Single.php Active Category Class

As vancoder notes, a post can have multiple categories and the following code highlights each category, as well as the current month for the post. Add to your theme’s functions.php. // Generate active class for categories when viewing single posts // Props to Sam Nabi http://samnabi.com/blog/highlight-the-current-category-for-single-posts-in-wordpress function singlePostActiveCat ($CatText) { global $post; if (is_singular()) { … Read more

Create single.php for specific category by category id

You can use this function to add category specific single template pages on your website. This goes in functions.php You can define as many single templates as you want. function wpse_category_single_template( $single_template ) { global $post; $all_cats = get_the_category(); if ( $all_cats[0]->cat_ID == ‘1’ ) { if ( file_exists(get_template_directory() . “/single-cat1.php”) ) return get_template_directory() . … Read more

How to have different content in the loop and single

you can add additional information to your posts through using post meta: http://wp.tutsplus.com/tutorials/plugins/how-to-create-custom-wordpress-writemeta-boxes/ If you want to check if WordPress is going to display just a single post/single page or more, you could use something like this before your loop: $single_page = false; if(is_single() || is_page()) $single_page = true; And then in your loop you … Read more

Using previous_post_link and next_post_link to wrap around post sequence

Add following custom functions in functions.php file and instead of calling previous_post_link and next_post_link functions call custom_next_post_link and custom_previous_post_link custom functions respectively. function custom_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories=””, $previous = true ) { if ( $previous && is_attachment() ) $post = get_post( get_post()->post_parent ); else $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous ); if … Read more

Create sub single pages

First, you need to register the custom post type so that it has hierarchy, i.e. a post can have a parent post. After that, you need to make sure your permalink structure is set to example.com/%postname%/. Once you have that, you only need to create a child custom post named sub-single-slug and set single-slug as … Read more

Proper way to load a single post via Ajax?

Here is my view: Load it inside your single.php why use ajax at all? Google wont be able to see this (using most crawlers). In any case – here is the right way to return the data… please note that you can use get_post or wp_query. up tp you. JS Part: jQuery(document).ready(function($) { $.post(ajax_object.ajaxurl, { … Read more

How to show a post single post in page template

The »Template Hierarchy« doesn’t allow this per default. Inside your single.php template, you can call load_template(). This will allow you to simply include the template you need, based on the in_category() conditional tag. // inside single.php if ( in_category( ‘foo’ ) ) { load_template( get_stylesheet_directory().’foo_template.php’ ); } elseif ( in_category( ‘bar’ ) ) { load_template( … Read more