Отображение подкатегорий на странице категории

Дек 5th, 2009 | От Aleksey Davlad | Категория: CMS WORDPRESS, ХАКИ

Задача в в общем решалась по разному. И всегда в кодах, которые приводились, были определенные неадекватности: то на страницах подкатегорий не показывались категории, то наоборот не отсеивались другие подкатегории. Вариант предложенный http://www.wpbeginner.com лишен данных недостатков.

Код вывода следующий:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
if (is_category()) {
$this_category = get_category($cat);
}
?>
<?php
if($this_category->category_parent)
$this_category = wp_list_categories(’orderby=id&show_count=0
&title_li=&use_desc_for_title=1&child_of=.$this_category->category_parent.
"&echo=0"); else
$this_category = wp_list_categories(’orderby=id&depth=1&show_count=0
&title_li=&use_desc_for_title=1&child_of=.$this_category->cat_ID.
"&echo=0");
if ($this_category) { ?>

И варианты интеграции в сайдбары:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!--code for children categories ---->
 
<?php
if (is_category()) {
$this_category = get_category($cat);
}
?>
<?php
if($this_category->category_parent)
$this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent."&echo=0"); else
$this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if ($this_category) { ?>
 
<ul>
<?php echo $this_category; ?>
 
</ul>
 
<?php } ?> 
 
<!---end of code--->
 
 
 
 
 
<!--code for subpages ---->
 
 
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&exclude=10");
if ($children) { ?>
 
<ul>
<?php echo $children; ?>
 
</ul>
 
<?php } ?> 
 
 
<!---end of code--->
Теги: ,

Комментарии статьи