Output HTML only on individual post view

If you want to load your js only on page/post view you can do it like this: function myplugin_enqueue_scripts() { global $wp_query; if ( $wp_query->is_single ) { wp_enqueue_script( ‘my_js’, … ); } } add_action( ‘wp_enqueue_scripts’, ‘myplugin_enqueue_scripts’ );

How can I display widget in a Page or Post?

There’s no easy way to do this. Many plugins that provide a widget also provide a shortcode (text in brackets that you can put in your post like this: [quora]). I have no idea whether either of your widgets also come with shortcodes. Though I’ve never used them, there are some plugins that claim to … Read more

Custom Blog Post Page

When you set a page to be the page for posts it no longer operates like a vanilla page, the template hierarchy dictates a different set of templates for that page. Your selected template doesn’t appear to work, because it’s not being loaded. See the template hierarchy for more info. You should name your template … Read more

how to find user ids of all commenters in a post

The get_comments() answer by Poulomi Nag is correct. This will be somewhat more efficient. global $wpdb, $post; $query = sprintf(“SELECT user_id FROM {$wpdb->comments} JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID WHERE comment_post_ID = %d AND comment_approved = ‘1’”, $post->ID); $authors = $wpdb->get_col($query); $authors = array_unique($authors); $authors = array_diff($authors,array(‘0’)); // Remove those where users are not registered … Read more

Alternating post layout

minimal necessary correction – move the_post(); to before the if(($i%2 == 0) : for instance: <?php if (have_posts()) : while(have_posts()) : the_post(); $i++; if(($i % 2) == 0) : ?>

Add code just after Post content

There are some global variables available (or not) to detect the current page number: if ( empty ( $GLOBALS[‘multipage’] ) or $GLOBALS[‘numpages’] === $GLOBALS[‘page’] ) echo ‘<a id=”lastPageLink” href=”#comment”>comment</a>’; The best way to understand what they do is a look at the internals of wp_link_pages(). (bool) $GLOBALS[‘multipage’] is TRUE if there is more than one … Read more