lundi 5 octobre 2015

PHP WordPress Plugin - How to display a div on the static homepage only?

This is my first time building a plugin for WordPress. I got the basics down but now I am trying to display a div on the bottom right corner, more like a small pop-up on the bottom right side of the front page only. The PHP code that I've uploaded did not work, it kept crashing my website.

Where is my mistake?

Please explain your answers. Thank you!

Code:

<?php
/*
Plugin Name: My First Plugin
Plugin URL: http://ift.tt/1VC3cMl
Description: An awesome facebook popup plugin that will amaze you!
Author: Martin
Version: 1.0
Author URL: http://ift.tt/1VC3cMl
*/
add_action('admin_menu', 'myfirstplugin_admin_actions');
function myfirstplugin_admin_actions() {
    add_options_page('MyFirstPlugin', 'MyFirstPlugin', 'manage_options', __FILE__, 'myfirstplugin_admin');
}

function myfirstplugin_admin()
{
?>
<style>
    .wrap { 
        width:100%;
        height:auto;
        }

    .popup {
        position:fixed;
        bottom:0;
        right:0;
        width:325px;
        height:200px;
        background-color:#09f;
    }
</style>


    <div class="wrap">

    <h1>Hello World!</h1><br>
    <h4>Hope you like my awesome popup!</h4>

    </div>



<?php if(is_front_page()) {
        <div class="popup">Testing Div Tag On The Bottom Right Corner...</div>
    }
?>
<?php
}
?>



via Chebli Mohamed

How do I change the name of this sub-directory?

Long time listener, first time caller. Thank you all for your consideration. If you check out my dev site here: http://ift.tt/1GsZ36m

You'll see i'm using a wordpress theme that is built for lawyers/attorneys and not accountants like I am trying to pull off. How can I switch the "attorney" part in the URL path to something more general like "team" or "accountant"?

I'm okay if the back-end part (i.e. the Wordpress Dashboard functions) are labelled "attorney" (as they do now), as long as the user-side doesn't show "attorney".

Any help? I'm not a trained back-end developer, as you may be able to tell. Thanks!



via Chebli Mohamed

How to make a custom page in Wordpress

Hi I'd like to create a totally custom page in wordpress where I'd add a lot of php code so I would prefer not to create it as a wordpress 'Page', but as a file 'filename.php' in my theme directory. Of course in that page I need to include wp functions and stuff and I plan to do it with require_once("../../../../wp-load.php");.

My problem is, how do I set the header info for a custom page like that (title, meta description etc..) and how do I add a rewrite rule to make it reachable like "website.dom/pagename". Thanks in advance for any answer, and even if you tell me that the best way is to use wordpress default "Add New Page", I'd prefer not to use any script to insert php code in the page, thanks.



via Chebli Mohamed

How to include authors (users) in the results for the native WordPress search?

Does anyone knows a way to include authors as part of the search results in the native wordpress theme without plugins?

Thanks



via Chebli Mohamed

Exclude page from a wordpress sitemap

I came across a tutorial on the internet for creating a sitemap in WordPress. It does what I want - it lists all pages and posts on the website however I was wondering if it was possible to exclude a page from the sitemap. In this case I want to exclude the sitemap link. Is it possible to do this? I have included the code for the sitemap below.

<?php
/*
Template Name: Sitemap
*/

get_header(); ?>


<?php if ( have_posts() ) : while( have_posts() ) : the_post();
        the_content();
endwhile; endif; ?>

<h2>Pages</h2>
<ul>
<?php
// Add pages seprated with comma[,] that you'd like to hide to display on sitemap
wp_list_pages(
  array(
    'exclude' => '',
    'title_li' => '',
  )
);
?>
</ul>

<h2>Posts</h2>
<?php
// Add categories seprated with comma (,) you'd like to hide to display on sitemap
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
  echo "<ul>";
  query_posts('posts_per_page=-1&cat='.$cat->cat_ID);
  while(have_posts()) {
    the_post();
    $category = get_the_category();
    // Only display a post link once, even if it's in multiple categories
    if ($category[0]->cat_ID == $cat->cat_ID) {
      echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
    }
  }
  echo "</ul>";
}
?>

<?php get_footer(); ?>

I am aware that the comments within the code give me some idea as to where to list the pages I want to hide however I am unsure as to how to do this. If anyone can help me it would be much appreciated.

Many Thanks.



via Chebli Mohamed

Embeded Youtube 360 video doesn't work in iOS Safari

Is there a way to embed a youtube video in a wordpress post that lets the 360 video work?

I made this test video, and it works everywhere I've tested so far except when I view it in iOS Safari.

The video plays, but the 360 environment doesn't function at all.

Thanks for any leads in figuring this out.



via Chebli Mohamed

WooCommerce: issue setting attributes with wp_set_object_terms

I need to set product's attributes via PHP code. According to other threads on StackOverflow, there's the method wp_set_object_terms. Unfortunately it is not working as it is supposed to do in my case:

For example, there is an attribute named "Hersteller", slug "hersteller". And there is a product, ID 593, with no "hersteller" attribute set.

I tried the following code to fill the attribute:

wp_set_object_terms(593, 'Alpina', 'pa_hersteller' , false);

When I'm attempting to display the attribute on the product page, there is no output, so it seems that the wp_set_object_terms process hasn't been successful. Following code produces an empty output:

$product->get_attribute('hersteller');

Furthermore, the attribute "hersteller" isn't even listed in the attribute list in the admin backend menue.

To debug the problem I've also tried the following code:

$attributes = get_post_meta( 593,  '_product_attributes' ); 
print_r($attributes);

resulting in the following output:

Array ( [0] => Array ( [pa_marken] => Array ( [name] => pa_marken [value] => [position] => 0 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) [pa_kategorien] => Array ( [name] => pa_kategorien [value] => [position] => 1 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) [pa_referenznummer] => Array ( [name] => pa_referenznummer [value] => [position] => 2 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) [pa_herstellergarantie] => Array ( [name] => pa_herstellergarantie [value] => [position] => 3 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) [pa_schlagwoerter] => Array ( [name] => pa_schlagwoerter [value] => [position] => 4 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) [pa_lieferzeit] => Array ( [name] => pa_lieferzeit [value] => [position] => 5 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) ) )

Am I using the wp_set_object_terms method essentially wrong? I don't know what to do anymore now. May anyone here can help me? Thanks!



via Chebli Mohamed