문제

i am creating a theme which consists of two pages, blog and portfolio. therefore i have categories which related to the portfolio posts (ie. web design, graphic design) and categories relating to the blog posts (ie. tutorials, todos)

i have two pages (/blog and /portfolio), in each, i would like to show the list of categories related on to the specific types

(i may not be clear) so this is an example:

all categories: cat1, cat2, cat3, cat4, cat5,cat6

for portfolio: 
<ul>
<li><a>cat1</a></li>
<li><a>cat2</a></li>
<li><a>cat3</a></li>
</ul>

for blog:
<ul>
<li><a>cat4</a></li>
<li><a>cat5</a></li>
<li><a>cat6</a></li>
</ul> 

so is there a way to split them like that

thanks

도움이 되었습니까?

해결책

You can use wp_list_categories() method in your template, this method takes an "exclude" or "exclude_tree" parameter, which allows you to exclude blog categories in the first list, and portfolio in the second.

http://codex.wordpress.org/Template_Tags/wp_list_categories

다른 팁

Here is the method I use to control which category of posts shows on which pages of a WordPress blog. I insert this line of code into the page.php file, just before the loop is called:

<?php
$catID = 0;
if (is_page('videos')) {
 $catID=3;
} elseif (is_page('music')) {
 $catID=4;
}
 elseif (is_page('poetry')) {
 $catID=5;
}

if ($catID) {
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 query_posts("cat=$catID&amp;paged=$paged");
} ?>

Note: The names in parentheses after "is_page=" are the page slugs, not the page titles.

Using this line of code, you can tell which page to display which category of posts.

You can read more info about this at my blog if you need it: WordPress: How to control which category of posts displays on particular pages

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top