TwentyTen: Overloading template.php files vs. get_template_part

TwentyTen was designed to help understand the WordPress theming system and that is why it has more lines of comments then actual code. So looking at TwentyTen you need to understand that they tried to include every file in the Template Hierarchy (eg: attachment.php, single.php, page.php) and every template tag there is (including: get_template_part() which … Read more

Creating a custom category page with pagination

You have a few issues here The following piece of code is wrong and unnecessary $category = get_post(); $category = $category->post_title; The current page object is saved in get_queried_object(), so you can use this function to get your post title. Also, post_title is not the correct property to use here. You want to look at … Read more

A shared custom taxonomy between two custom post types

You use get_query_var(‘post_type’) to set the post type in your args array $args[‘post_type’] = get_query_var(‘post_type’); and also include the right loop part based on that for example: if (get_query_var(‘post_type’) == “event”){ get_template_part( ‘loop’, ‘event’ ); }else{ get_template_part( ‘loop’, ‘other’ ); }

wordpress – load a template based on the URI

I assume that your custom post type windows would map onto /windows/ etc? You can customise the template for individual custom post types via single-posttype.php in your theme, e.g. single-windows.php single-doors.php and single-garages.php WordPress will automatically pick these up You could also use custom page templates, e.g. page-windows.php or custom templates with the right template … Read more

How to assign a class to a page with a custom template?

Using is_page(8) will make your code a bit static. Let’s make it dynamic as you’re after with is_page_template(): <?php function prefix_conditional_body_class( $classes ) { if( is_page_template(‘mytemplate.php’) ) $classes[] = ‘mytemplate’; return $classes; } add_filter( ‘body_class’, ‘prefix_conditional_body_class’ ); Worked for me in a child theme with the template file in the root of the child theme, … Read more

Correct process for a new Page Template?

A page template defines the full rendered content displayed: header, footer, content – everything. So, at the very least, you’ll need to call get_header() and get_footer(), or manually add the header and footer code to the template. Also, I would recommend using a callback to enqueue your custom stylesheet. You can use the is_page_template() conditional … Read more