wordpress 分类相关代码

分类关联标签

<?php

//分类关联标签
$currentterm = get_queried_object(); //获取当前分类
$keywords = get_term_meta($currentterm->term_id , 'guanlian',true); //_seo_keywords即配置数据中的id值


// 12,13是分类ID,多个用半角逗号隔开
$args = array( 'categories' =>$keywords );

// 调用上面定义的函数,来获取ID为12,13的分类的关联标签
$tags = get_category_tags($args);

// 输出我们获取到的关联标签,以列表形式打印
$content .= '<ul class="jishi">';

if(!empty($tags)) {
  foreach ($tags as $tag) {
    $content .= "<li  ><a  class=\"button big gray\" href=\"".get_tag_link($tag->term_id)."\"><span>".$tag->name."</a></li>";
  }
}

$content .= "</ul>";
echo $content;


?>

获取子分类

<?php
if(is_category())
{
if(get_category_children(get_category_root_id(the_category_ID(false)))!= "" )
{
echo '<dd>';
echo wp_list_categories("child_of=".get_category_root_id(the_category_ID(false)). "&depth=0&hide_empty=0&title_li=&orderby=id&order=ASC");
echo '</dd>';
}
}
?>

获取指定分类

 <?php
 //获取指定分类
$args=array(
  'orderby' => 'ID',
  'include'=> '1,3,2',
  'order' => 'ASC'
  );

$categories=get_categories($args);
  foreach($categories as $category) { 
    echo '<dd><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dd>';
    } 
?>

 

 

 

2

预见

发表评论

:?::razz::sad::evil::!::smile::oops::grin::eek::shock::???::cool::lol::mad::twisted::roll::wink::idea::arrow::neutral::cry::mrgreen: