How to show "category" name?

时间:2014-11-11 作者:mfab67

我是个新手,我正在尝试编辑我的主题。我需要在文本“中列出的:”后显示类别:

//echo $todaydate;
if(is_array($rec_dates) && strtolower(trim($is_recurring)) == strtolower(trim(\'Recurring event\')) && in_array($todaydate,$rec_dates)){ /* if recurring event */
$c = $counter++;
$recurrence_days = get_post_meta($post->ID,\'recurrence_days\',true); //on which day
//  print_r($rec_dates);
$end_date1 = strtotime(date("Y-m-d", strtotime($todaydate)) . " +$recurrence_days day");
$end_date = get_formated_date(date(\'Y-m-d\', $end_date1));
$start_date1 = strtotime(date("Y-m-d", strtotime($todaydate)) . " +$recurrence_days day");
$start_date = get_formated_date(date(\'Y-m-d\', $start_date1));
    $post_info .=\' 
    <a class="event_title" href="\'.get_permalink($post->ID).\'">\'.$post->post_title.\'</a><small>\'.
    __(\'<b>Listed in: </b>\').***which code here to show the category?***.\'<br>\'.
    __(\'<b>Location: </b>\').get_post_meta($post->ID,\'address\',true) .\'<br>\'.
    __(\'<b>Start Date: </b>\').get_formated_date(get_post_meta($post->ID,\'st_date\',true)).\' \'.get_formated_time(get_post_meta($post->ID,\'st_time\',true)) .\'<br />\'. 
    __(\'<b>End Date: </b>\').get_formated_date(get_post_meta($post->ID,\'end_date\',true)).\' \'.get_formated_time(get_post_meta($post->ID,\'end_time\',true)) .\'</small>\';
}else if(strtolower($is_recurring) == strtolower(\'Regular event\')){ /* if regular event */
        $post_info .=\' 
    <a class="event_title" href="\'.get_permalink($post->ID).\'">\'.$post->post_title.\'</a><small>\'.
    __(\'<b>Listed in: </b>\').***which code here to show the category?***.\'<br>\'.
    __(\'<b>Location: </b>\').get_post_meta($post->ID,\'address\',true) .\'<br>\'.
    __(\'<b>Start Date: </b>\').get_formated_date(get_post_meta($post->ID,\'st_date\',true)).\' \'.get_formated_time(get_post_meta($post->ID,\'st_time\',true)) .\'<br />\'. 
    __(\'<b>End Date: </b>\').get_formated_date(get_post_meta($post->ID,\'end_date\',true)).\' \'.get_formated_time(get_post_meta($post->ID,\'end_time\',true)) .\'</small>\';                            
}
endwhile;
$post_info .=\'</span>\';
}

1 个回复
SO网友:ManuA

这可能会帮助您获得特定帖子的类别

$catList =get_the_category($post->ID);
foreach($catList as $single){
echo $single->cat_name;
}
您也可以从以下链接进行检查

结束

相关推荐

Show Pages in Categories

通过将此代码添加到函数中,我创建了category函数。php:function page_category() { register_taxonomy_for_object_type(\'category\', \'page\'); } // Add to the admin_init hook of your theme functions.php file add_action( \'init\', \'page_category\' ); 但问