显示Wordpress博客文章类别

时间:2020-02-01 17:02:40

标签: php html wordpress wordpress-theming custom-wordpress-pages

我正在使用Wordpress主题桥,这里是reference

我在网站首页上使用砌体博客简码。它目前仅显示博客标题,摘录,元数据和评论,而我想显示博客的类别。

下面显示了显示标题,博客摘录,元数据和评论的代码,因此希望能对显示博客类别提供任何帮助。

$html .= '<div class="q_masonry_blog_post_text">';
$html .= '<'.$title_tag.' itemprop="name" class="q_masonry_blog_title
entry_title"><a itemprop="url" href="' . get_permalink() . '">' .
get_the_title() . '</a></'.$title_tag.'>';
$excerpt = ($text_length > 0) ? substr(get_the_excerpt(), 0,
intval($text_length)) : get_the_excerpt();
$html .= '<p itemprop="description" 
class="q_masonry_blog_excerpt">'.$excerpt.'...</p>';
$html .= '<div class="q_masonry_blog_post_info">';
if ($display_time != "0") {
$html .= '<span itemprop="dateCreated" class="time entry_date updated">'.
get_the_time('d F, Y') .'<meta itemprop="interactionCount" 
content="UserComments: <?php echo get_comments_number(qode_get_page_id()); 
?>"/>.</span>';
}

2 个答案:

答案 0 :(得分:1)

您可以使用get_the_category

在这里找到link

$categories = get_the_category();
if ( ! empty( $categories ) ) {
$html .= '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>'
 }
$html .= '</div>'; //closing class q_masonry_blog_post_info

答案 1 :(得分:0)

可以使用此代码获取帖子中的类别。

<?php 
    foreach((get_the_category()) as $category){
        echo $category->name;
        }
    ?>