English 中文(简体)
邮电局的类别名称
原标题:Get Category name from Post ID

鉴于邮政信息系统,能否获得一个类别的类别的名称,以下代码是为了获取第一类,但我如何获得名称?

<?php $post_categories = wp_get_post_categories( 4 ); echo $post_categories[0]?>

感谢!

最佳回答

页: 1

$category_detail=get_the_category( 4 ); // $post->ID
foreach($category_detail as $cd){
    echo $cd->cat_name;
}

get_the_journal/a>

问题回答
echo  <p> . get_the_category( $id )[0]->name . </p> ;

这是你可能想到的。

页: 1

<?php get_the_category( $id ) ?>

只是,在 lo里吗?

外部:

global $post;
$categories = get_the_category($post->ID);
var_dump($categories);
function wp_get_post_categories( $post_id = 0, $args = array() )
{
   $post_id = (int) $post_id;
   $defaults = array( fields  =>  ids );
   $args = wp_parse_args( $args, $defaults );
   $cats = wp_get_object_terms($post_id,  category , $args);

   return $cats;
}

Here is the second argument of function wp_get_post_categories() which you can pass the attributes of receiving data.

$category_detail = get_the_category(  4 ,array(  fields  =>  names  ) ); //$post->ID
foreach( $category_detail as $cd )
{
   echo $cd->name;
}

您可以通过简单地通过职位识别表来重复职类的名称:

echo wp_get_post_terms(get_the_ID(),  category )[0]->name;

Use get_the_category() function.

$post_categories = wp_get_post_categories( 4 );
$categories = get_the_category($post_categories[0]);
var_dump($categories);
     <?php  
     // in woocommerce.php
     $cat = get_queried_object();
     $cat->term_id;
     $cat->name;
     ?>

    <?php
    // get product cat image
        if ( is_product_category() ){
            $cat = get_queried_object();
            $thumbnail_id = get_woocommerce_term_meta( $cat->term_id,  thumbnail_id , true );
            $image = wp_get_attachment_url( $thumbnail_id );
            if ( $image ) {
                echo  <img src="  . $image .  " alt="" /> ;
            }       
}
?>

First Category name by post id

$first_category = wp_get_post_terms( get_the_ID(),  category  )[0]->name;




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签