Kod dla konkretnej strony, dla konkretnej kategorii

zróżnicowanie kodu html w zależności od strony na jakiej jest wyświetlany, dla różnych podstron, kategorii oraz custom post:


<?php $post = $wp_query->post;
$current_post = get_post_type();
if (is_category(2) ) { ?>
  //your code
<?php } elseif (is_page(5)) { ?> 
  //your code
<?php } elseif (is_tax('custom-category')) { ?>
  //your code
<?php } elseif (is_tax('custom-category', 'single-custom-category')) { ?>
  //your code
<?php } elseif (is_singular('custom-post-name')) { ?>
  //your code
<?php } elseif (is_post_type_archive('edition')) { ?>
  //your code
<?php } elseif ( get_post_type() == 'post' ) { ?>
  //your code for all page with post like author page, category page, 
<?php } ?>

elseif (is_tax('custom-category', 'single-custom-category') || (is_single() && has_term('single-custom-category', 'custom-category')) ) { ?>
  //your code
<?php } ?>

ostatnia linia z użyciem is_single() && has_term() – pozwala na dodanie indywidualnego kodu dla single custom posta dla wybranej kategorii.

 

if( get_post_type() == 'post’ ) – dodaje kod dla każdej strony związanej z wpisami, single posta, category page, home page z wpisami, strony archive daty, strona autora

 

kod dla konkretnej kategorii, jej subkategorii:

// if the category is a Cykle and his subcategory,
if (cat_is_ancestor_of(14, $cat) or is_category(14)):
  include(TEMPLATEPATH . '/category-cycles.php');

// if the category is a Poradniki subcategory,
elseif (cat_is_ancestor_of(8, $cat)):
  include(TEMPLATEPATH . '/category-8.php');
else :
  include(TEMPLATEPATH . '/category-defaults.php');
endif;


więcej tagów warunkowych: Conditional tags WP