php - How to display different content on different title page in WordPress -
i have wordpress template , trying display different content on different categories pages:
single_cat_title('');
how use in php template? when have category (e.g. category-1
) need display different content category (e.g. category-2
).
if single_cat_title(''); category-1 display content-1 else display content-1
i can think of 2 solutions.
you make use of category templates. idea behind them create separate php file each category. can use names
category-1.php
,category-2.php
etc. category ids orcategory-name.php
,category-other-name.php
etc. category names. avoid writing same pieces of code in each of files, should put shared code in file or multiple files (e.g. shared.php or, better, header.php, footer.php , on). can wrap shared code in functions more control. include shared file(s) in category templates , call functions:include('shared.php'); // including shared code show_header(); // our function displaying header /* * category-specific stuff */ show_footer(); // our function displaying footer
you can use single category template (
category.php
default), check current category , perform different actions different categories. there special function checking category, called is_category(). this://(...) header code here if(is_category('some_category')) { // perform specific actions } else if(is_category('other_category')) { // perform specific actions } else { // unknown category. perform specific actions } // (...) footer code here
Comments
Post a Comment