我希望这个问题不会让我看起来太傻!
我正在使用一个名为“查询多个分类法”的插件——这是一个很棒的插件,写得非常好。http://wordpress.org/plugins/query-multiple-taxonomies/
除了一件小事,我需要它做的一切都是它做的。一段时间以来,我一直在想如何完成这最后一点,我决定是时候寻求一些帮助了。
您可以在此处查看我正在处理的部分:http://tunagaming.dyndns.org/?section=tutorials
向下钻取效果很好。以下是当前的设置方式:
第一页显示平台第二页显示流派,第三页显示子流派这就是我希望它的工作方式,除了每一种都是自定义分类法之外,我希望完全消除“子类型”,以支持分级“类型”分类法。
因此,最终,我希望深入了解如下:
第一页显示平台第二页仅显示分类法“流派”中的父术语,第三页显示所选父术语的子术语所有这些都被称为归档文件。php文件。以下是参考代码:
<?php if (is_multitax( array(\'section\', \'platforms\', \'genre\') ) ){
the_widget(\'Taxonomy_Drill_Down_Widget\', array(
\'title\' => \'\',
\'mode\' => \'lists\',
\'taxonomies\' => array(\'subgenre\')
));?>
<div id="postList">
<h2>Query Results</h2>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<ul><a title="<?php the_title();?>" href="<?php the_permalink();?>"><li>
<span class="image"><?php echo get_the_post_thumbnail($page->ID, \'thumbnail\'); ?></span>
<span class="content">
<h3><?php the_title();?></h3>
<?php the_excerpt(); ?>
</span>
</ul></li></a>
<?php endwhile; ?>
</div>
<?php
}
elseif (is_multitax( array(\'section\', \'platforms\') ) ) {
the_widget(\'Taxonomy_Drill_Down_Widget\', array(
\'title\' => \'\',
\'mode\' => \'lists\',
\'taxonomies\' => array(\'genre\')
));
?>
<div id="postList">
<h2>Query Results</h2>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<ul><a title="<?php the_title();?>" href="<?php the_permalink();?>"><li>
<span class="image"><?php echo get_the_post_thumbnail($page->ID, \'thumbnail\'); ?></span>
<span class="content">
<h3><?php the_title();?></h3>
<?php the_excerpt(); ?>
</span>
</ul></li></a>
<?php endwhile; ?>
</div>
<?php
}
else {
the_widget(\'Taxonomy_Drill_Down_Widget\', array(
\'title\' => \'\',
\'mode\' => \'lists\',
\'taxonomies\' => array(\'platforms\') // list of taxonomy names
));
?>
<div id="postList">
<h2>Latest Entries</h2>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<ul><a title="<?php the_title();?>" href="<?php the_permalink();?>"><li>
<span class="image"><?php echo get_the_post_thumbnail($page->ID, \'thumbnail\'); ?></span>
<span class="content">
<h3><?php the_title();?></h3>
<?php the_excerpt(); ?>
</span>
</ul></li></a>
<?php endwhile; ?>
</div>
<?php } ?>
我希望能得到一些帮助来解决这个问题,甚至是一些关于如何实现这个深入研究的新想法。我并没有要求任何人为我编写代码,但这只是有点让我不知所措。我对PHP很在行——不太好。因此,朝着正确的方向轻推也会非常有帮助!
提前谢谢。
编辑:
不管它值多少钱,我相信答案在于插件的助行器。php文件。我可能错了,但这是我今天早上一直在研究的代码:
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
if ( !$element )
return;
$id_field = $this->db_fields[\'id\'];
$id = $element->$id_field;
$child_output = \'\';
// descend only when the depth is right and there are childrens for this element
if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
foreach ( $children_elements[ $id ] as $child ) {
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $child_output );
}
unset( $children_elements[ $id ] );
}
$this->single_el( $output, $element, $depth, $child_output );
}
function single_el( &$output, $term, $depth, $child_output ) {
$data = $this->specific_data( $term, $depth );
$data = array_merge( $data, array(
\'term-name\' => $term->name,
\'is-selected\' => in_array( $term->slug, $this->selected_terms ) ? array(true) : false,
\'depth\' => $depth,
) );
if ( !empty( $child_output ) ) {
$data[\'children\'][\'child-list\'] = $child_output;
}
$full_data = new QMT_Data_Container( $this->taxonomy, $term, $data );
$output .= Taxonomy_Drill_Down_Widget::mustache_render( $this->walker_type . \'-item.html\', $full_data );
}
abstract function specific_data( $term, $depth );
}
SO网友:Vikas Bhardwaj
我为即将到来的主题做了一些工作,该主题显示了自定义分类法中的分类树(分类法向下钻取)。您可以在分类页面或类别页面上显示它。
if(! defined(\'TH_TAX_TYPE\')) define(\'TH_TAX_TYPE\',\'your-tax-type\');
function is_decendent($term_id,$main_parent) {
$terms= get_term_by(\'id\', $term_id,TH_TAX_TYPE);
$parent_term= get_term_by(\'id\', $terms->parent,TH_TAX_TYPE);
$grand_parent_term= get_term_by(\'id\',$parent_term->parent,TH_TAX_TYPE);
if($terms || $grand_parent_term){
if($grand_parent_term->term_id==$main_parent){
return TRUE;
}
}
return FALSE;
}
function category_tree() {
global $term;
$get_current_term_info= get_term_by(\'slug\', $term,TH_TAX_TYPE);
$all_category= get_terms(TH_TAX_TYPE);
$out_put=\'<ul class="category-tree">
<li><a href="\'.get_option(\'all_cat_link\').\'">\'.__(\'All Files\',\'themeshive\').\'</a></li>\';
foreach ($all_category as $main_cat) {
if($main_cat->parent==\'0\'){
$out_put.=\'<li><a href="\'.get_term_link($main_cat).\'">\'.$main_cat->name.\'</a>\';
$sub_cats=get_terms(TH_TAX_TYPE, array(\'parent\'=>$main_cat->term_id ));
if($sub_cats ){
if($main_cat->slug==$term || $main_cat->term_id ==$get_current_term_info->parent || is_decendent($get_current_term_info->term_id,$main_cat->term_id)){
$out_put.=\'<ul>\';
foreach ($sub_cats as $sub_cat) {
$out_put.=\'<li><a href="\'.get_term_link($sub_cat).\'">\'.$sub_cat->name.\'</a>
<small>(\'.$sub_cat->count.\')</small>\';
$sub_sub_cats= get_terms(TH_TAX_TYPE, array(\'parent\'=>$sub_cat->term_id));
if($sub_cat->slug==$term || $sub_cat->term_id ==$get_current_term_info->parent){
if($sub_sub_cats){
$out_put.=\'<ul>\';
foreach ($sub_sub_cats as $sub_sub_cat) {
$out_put.=\'<li>
<a href="\'.get_term_link($sub_sub_cat).\'">\'.$sub_sub_cat->name.\'</a>
<small>(\'.$sub_sub_cat->count.\')</small></li>\';
}
$out_put.=\'</ul>\';
}}
$out_put.=\'</li>\';
}
$out_put.=\'</ul>\';
}
}
$out_put.=\'</li>\';
}
}
$out_put.=\'</ul>\';
return $out_put;
}
类别树的CSS
ul.category-tree {
margin: 0 10px;
}
ul.category-tree li {
margin-bottom: 0px;
padding-left: 0px;
padding: 5px 0px;
}
ul.category-tree li a {
font-size: 13px;
color: #8a6741;
}
ul.category-tree li ul {
border-left: 1px solid #999;
list-style: none;
margin-bottom: 0px;
margin-left: 0px;
margin-top: 7px;
}
ul.category-tree li ul li {
line-height: 15px;
padding-left: 17px;
position: relative;
}
ul.category-tree li ul li:before {
background-color: #999;
content: "";
height: 1px;
left: 0;
position: absolute;
top: 12px;
width: 11px;
}
ul.category-tree li ul li a {
color: #555;
font-size: 13px;
}
ul.category-tree li ul li ul li a {
color: #555;
}
.category-tree.list {
overflow: hidden;
}
.category-tree.list li {
float: left;
width: 100%;
margin: 0px 15px;
}
.category-tree.list li li {
float: none;
width: auto;
margin: inherit;
}
.category-tree small {
font-size: 11px;
float: right;
}
现在,您可以在喜欢的地方回显category\\u tree(),也可以根据需要进行修改。
我是这样做的。
SO网友:Lynne
我就是这样处理的。
正如我在第一个问题中所说的,我不是一个优秀的PHP程序员,但我认为这是处理分类深入的一种非常可靠的方法。
它使用用户所在的当前URL提取平台和类型的变量。(即:它把每个人的鼻涕虫都变成了一个虚幻的东西)
我把代码放在函数中。php文件:
// I assign the variables a NULL value before the multiexplode function
// so that I can use them for if statements later.
$platforms = NULL;
$genre = NULL;
function multiexplode ($delimiters, $string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$requestURI = multiexplode(array("/", "?", "&"), $_SERVER[\'REQUEST_URI\']); //cuts the array into sections for genre= and platform=
$requestURI = array_splice($requestURI, -2, 2); //drops blanks for "/" and "?"
foreach ($requestURI as $value) {
$value = parse_str($value);
}
unset($value);
这是我的档案。处理流派输出的php文件;流派儿童。平台列表位于其他文件中。
<?php get_header(); ?>
<div class="center">
<div id="padding">
<?php
if ($genre != NULL && $platforms !=NULL) { // If ganre and platforms both have a value (meaning they were selected)
$args = array( \'taxonomy\' => \'genre\', \'parent\' => 0 );
$terms = get_terms(\'genre\', $args);
foreach ($terms as $term) {
$term_list .= \'<li><a href="?platforms=\'.$platforms.\'&genre=\'.$term->slug.\'">\'.$term->name.\'</a></li>\';
}
echo \'<ul>\';
echo $term_list;
echo \'</ul>\';
// then we display children of selected genre term
$getGenre = get_term_by(\'slug\', $genre, \'genre\'); // Get the term using the genre slug
$current_genre_id = $getGenre->term_id; // get the term ID
$current_genre_name = $getGenre->name; // get the term name
$term_id = $current_genre_id; // what tax parent to query children from. In this case, whatever genre they\'ve selected.
$taxonomy_name = \'genre\'; // name of taxonomy
$termchildren = get_term_children( $term_id, $taxonomy_name ); // get children
echo \'<h1>Sub-Categories in Category: <span style="color: green">\' . $current_genre_name . \'</span></h1>\';
echo \'<ul>\';
foreach ( $termchildren as $child ) {
$term = get_term_by( \'id\', $child, $taxonomy_name );
echo \'<li><a href="?platforms=\'.$platforms.\'&genre=\'.$genre.\'+\'.$term->slug.\'">\' . $term->name . \'</a></li>\';
}
echo \'</ul>\';
?>
<div id="postList">
<?php if ( have_posts() ) { while ( have_posts() ) : the_post();?>
<h2>Latest Entries</h2>
<ul><a title="<?php the_title();?>" href="<?php the_permalink();?>"><li>
<span class="image"><?php echo get_the_post_thumbnail($page->ID, \'thumbnail\'); ?></span>
<span class="content">
<h3><?php the_title();?></h3>
<?php the_excerpt(); ?>
</span>
</ul></li></a>
<?php endwhile; } else { echo \'No posts to display.\'; }?>
</div>
<?php
} else {
// They have only selected a platform
$args = array( \'taxonomy\' => \'genre\', \'parent\' => 0 );
$terms = get_terms(\'genre\', $args);
foreach ($terms as $term) {
$term_list .= \'<li><a href="?platforms=\'.$platforms.\'&genre=\'.$term->slug.\'">\'.$term->name.\'</a></li>\';
}
echo \'<ul>\';
echo $term_list;
echo \'</ul>\';
//wp_nav_menu( array(\'menu\' => \'genres\', \'container\' => false, \'menu_class\' => \'genres\', \'depth\' => 0));
?>
<div id="postList">
<h2>Latest Entries</h2>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<ul><a title="<?php the_title();?>" href="<?php the_permalink();?>"><li>
<span class="image"><?php echo get_the_post_thumbnail($page->ID, \'thumbnail\'); ?></span>
<span class="content">
<h3><?php the_title();?></h3>
<?php the_excerpt(); ?>
</span>
</ul></li></a>
<?php endwhile; ?>
</div>
</div>
</div>
<?php } ?>
<?php get_footer(); ?>
现在我只需要添加+符号的检查,因为一旦你深入到孩子们身上,它就不能正确处理这些符号,但这没什么大不了的。
我不知道该怎么办,因为我基本上已经回答了我自己的问题。我想我会让它一直开放到到期,如果有人能给我一个更好的答案,在一个更干净的包装中完成我所需要的一切,我会奖励他们。