wordpress怎么获取当前分类名称或别名
获取当前页面的别名
判断是否为单个页面
并获取页面的别名
if( is_page() ) { $content = $content . get_option('display_copyright_text'); $post_data = get_post($post->ID, ARRAY_A); echo $slug = $post_data['post_name']; }
$slug 就是当前页面的别名,其实不见限于page页面
wordpress怎么获取文章所属分类的名称
WordPress本身自带一个函数可以调出分类别名和链接:
但在实际的应用中,我们可能需要单独调出 wordpress 的分类,并不需要添加链接,那该如何只调出文章分类的名称呢?
如果是在分类页面进行调用:
如果是在文章页面进行所属分类名称的调用:
cat_name;}>
如何调出分类别名呢?
if(is_category()) {$cat = get_query_var('cat');$yourcat = get_category($cat);echo "该分类别名为" . $yourcat->slug;}
wordpress如何获得当前自定义分类的id
当前页是分类页 系统默认有个变量$cat,就是当前分类的ID 当前页是单页 第一种方法 $cat= single_cat_title('', false);echo get_cat_ID($cat); 第二种方法 if (!is_page() && !is_home()){ $catsy = get_the_category(); $myCat = $catsy[0]->cat_ID; $currentcategory = '¤t_category='.$myCat;}wp_list_categories('hierarchical=1&use_desc_for_title=0&exclude=12&depth=1&orderby=id&title_li='.$currentcategory); 第三种方法 foreach((get_the_category()) as $category) { echo $category->cat_ID . ''; //当前文章的分类的ID echo $category->cat_name . ''; //当前文章的分类的名称}。
WordPress别名判断分类怎么连接到一个指定的页面
在主题下的category.php(如果没有,复制index.php或者archive.php并重命名下);在category.php中写: function getmycatid($slug){ $icat=get_category_by_slug($slug); $icat_links=get_category_link($icat->term_id); $icat_name=$icat->name; $cat_id=$icat->term_id; return $cat_id;}这个函数的作用是根据分类的slug返回分类ID;$mycatid=getmycatid('你的分类的slug');define('MYCATID',$mycatid);上面两句的意思是获取你指定slug的分类的ID,并将其定义为常量;打开category.php,在最开头一个<?php之后添加:>?php之后添加:>
wordpress怎么显示当前分类的子分类
wordpress获取当前分类下的子分类1.将此函数放在你模版的函数中 (wordpress3.8.1是functions.php这个文件)functionget_category_root_id($cat){$this_category = get_category($cat); // 取得当前分类while($this_category->category_parent) // 若当前分类有上级分类时,循环{$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬)}return$this_category->term_id; // 返回根分类的id号}2.页面调用 在模板下sidebar.php里修改<?phpwp_list_categories("child_of=".get_category_root_id(the_category_id(false)). "&depth="0&hide_empty=0&title_li=");?">。
wordpress怎么显示当前分类的子分类
wordpress获取当前分类下的子分类
1.将此函数放在你模版的函数中 (wordpress3.8.1是functions.php这个文件)
functionget_category_root_id($cat)
{
$this_category = get_category($cat); // 取得当前分类
while($this_category->category_parent) // 若当前分类有上级分类时,循环
{
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬)
}
return$this_category->term_id; // 返回根分类的id号
}
2.页面调用 在模板下sidebar.php里修改
?>
wordpress 获取父分类下所有子分类名称和链接
获取父分类下,所有tag !
这句的表述存在问题,分类和标签,是平级的,都是用以区分产品的一种术语。
它们两者之间能够联系的就是产品。
所以,根据这个思路,要想获取当前分类下的所有tag,需要先获取当前分类下所有产品的信息。
可参考这几个函数实现:
get_queried_object_id(),在分类页,直接获取当前分类的ID
get_posts(); 用此函数可获取当前分类下的所有产品的ID。进而获取产品对应的所有tag!
另外,可参考wp_tag_cloud()函数直接输出标签云试试。
转载请注明出处51数据库 » wordpress获取当前分类别名
?phpwp_list_categories("child_of=".get_category_root_id(the_category_id(false)).>