首页 wordpress在文章页面获取所属分类的id两种可用的方法

wordpress在文章页面获取所属分类的id两种可用的方法

沐辰客栈 2022-03-19 02:42:54 1 1112

方法一、二


//wordpress 根据文章ID获取分类ID

$category=get_the_category( $post_ID );

$catid=$category[0]->term_id;

//wordpress 根据文章ID获取标签ID

$tags=wp_get_post_tags( $post_ID );

$tagid=$tags[0]->term_id;
方法三:



foreach((get_the_category()) as $category) {
    echo $category->cat_ID . ' ';            //当前文章的分类的ID
    echo $category->cat_name . ' ';            //当前文章的分类的名称
}

发表评论

评论列表:

66
2022-03-30 11:51
是<?php
$page_num = $paged;
if ($pagenum="") $pagenum =1;
query_posts('showposts='._read('rp-index-piece').'&paged='.$page_num); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>