用户登录
用户注册

分享至

wordpressgetcatid

  • 作者: 啊一一长城
  • 来源: 51数据库
  • 2020-04-21

1.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 = '&current_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 . ''; //当前文章的分类的名称

}

2.wordpress如何根据分类ID获取分类标题

用法:<?php get_cat_id(="" $cat_name="" )="" ?="">参数:$cat_name 分类名称 默认值为"General"。

类型为字符型可选返回的值:出错时返回0,成功则返回分类ID号,类型为整数示例:<?php $category_id="get_cat_id('Category" name');="" query_posts('cat='.$category_id); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; ?>。

3.wordpress取得子分类id

$categories_shop = get_categories("echo=0&show_count=1&child_of=".$hot_shop_id."&title_li=&orderby=count&order=DESC&hide_empty=0&number=14");

foreach($categories_shop as $category) {

//ID $category->cat_ID

//名称 $category->cat_name

}

4.wordpress取得子分类id

<?php$term_id = 10; //父类ID$taxonomy_name = ' products';="" 分类名,可用于自定义的,也可以是category(默认分类)、post_tag、post_format、nav_menu$termchildren="get_term_children(" $term_id,="" $taxonomy_name="" );echo="" '';foreach="" (="" $termchildren="" as="" $child="" )="" {="" $term="get_term_by(" 'id',="" $child,="" $taxonomy_name="" );="" echo="" 'name,="" $taxonomy_name="" )="" .="" '"="">' . $term->name . '';}echo '';?>楼上的回复本可以满足你的需求了。

我列举的其实是官方的一个示例,应用范围更广,推荐你了解。

5.wordpress如何根据分类ID获取分类标题

用法:

参数:$cat_name 分类名称 默认值为"General"。类型为字符型可选

返回的值:出错时返回0,成功则返回分类ID号,类型为整数

示例:

query_posts('cat='.$category_id);

if (have_posts()) : while (have_posts()) : the_post();

the_content();

endwhile; endif;

?>

6.wordpress如何获取当前文章的id,要求写一个函数在function里面调用

$args = array(

'cat' =>61 //这是分类ID,也可以用array给一组ID

);

// The Result

$naruco= new WP_Query( $args );

if ( $naruco-> have_posts() ) {

// The Loop

while ( $naruco-> have_posts() ) : $naruco->the_post();

echo '

转载请注明出处51数据库 » wordpressgetcatid

软件
前端设计
程序设计
Java相关