How to override Category rendering mechanism

if you can use template_redirect hook and a simple function to set the template to use add_action( ‘template_redirect’, ‘category_set_redirect’ ); function category_set_redirect(){ //create the sets of categories $first_set= array(“1″,”2″,”3″,”4″,”5″,”6”); $second_set= array(“7″,”8″,”9″,”10″,”11″,”12”); if (is_category()){ if (in_array(get_query_var(‘cat’),$first_set)){ include(TEMPLATEPATH . “/first_category.php”); // include the corresponding template die(); } if (in_array(get_query_var(‘cat’),$second_set)){ include(TEMPLATEPATH . “/second_category.php”); // include the corresponding template … Read more

What code do you use to generate the text to go into the HTML title tag?

Mine is: function getDocumentTitle($separator = ” « “){ $title = get_bloginfo(‘name’); $desc = get_bloginfo(‘description’); if(is_front_page() && is_home() && !empty($desc)){ $title .= $separator.$desc; }elseif(is_home() || is_singular()){ $id = $GLOBALS[‘wp_query’]->get_queried_object_id(); if($meta = get_post_meta($id, ‘title’, true)) $title .= $separator.$meta; $title .= (empty($meta) && is_front_page() && !empty($desc)) ? $separator.$desc : $separator.get_post_field(‘post_title’, $id); }elseif(is_archive()){ if(is_category() || is_tag() || is_tax()){ $term … Read more

How to move style from template file to section?

What about putting styles before the function get_header(); <style type=”text/css”>#header { display: none; }</style> <?php get_header();?> <div class=”main-container-of-my-template”></div> <?php get_footer(); ?> However this is not recommended as it loads the styles even before the <html> not within the <head> section of your website, but as per your requirement this could be the only way to … Read more

wordpress 3.4 template files in subdirectories

The solution shared in this answer on StackOverflow works for me: https://stackoverflow.com/questions/4647604/wp-use-file-in-plugin-directory-as-custom-page-template#answer-8255556 function get_book_post_type_template($single_template) { global $post; if ($post->post_type == ‘books’) { $single_template = dirname( __FILE__ ) . ‘/themefiles/single-books.php’; } return $single_template; } add_filter( “single_template”, “get_book_post_type_template” ) ;

Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page

I found an answer by searching in similar posts and links. I added a line to fit my needs (I wanted to prevent my blog page to get highlited when on a custom post).See this line: unset($classes[array_search(‘current_page_parent’,$classes)]); Solution function add_parent_url_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = current_url(); … Read more

Set template based on query in URL

There are a number of template filters available to override template selection. For a single post you can use the single_template filter: function wpa_single_template( $template ) { if( isset( $_GET[‘template’] ) ) { $template = locate_template( $_GET[‘template’] . ‘.php’, false ); } return $template; } add_filter( ‘single_template’, ‘wpa_single_template’ );

How to display error on specific template?

@PieterGoosen gave some good advice. Focus on that, But if you really wan it, then you can set debug ON temporarily on your website this way. In your wp-config.php use this instead. if ( isset( $_GET[‘debug’] ) && ‘debug’ == $_GET[‘debug’] ) { define( ‘WP_DEBUG’, true ); } Then access your website homepage/any page and … Read more