繁体   English   中英

显示 Wordpress 博客文章类别

[英]Display Wordpress blog article category

我正在使用 Wordpress 主题 Bridge,这是参考.

我在我的网站主页上使用砌体博客短代码。 它目前只显示博客标题、摘录、元数据和评论,我想显示博客类别/类别。

下面显示了显示标题、博客摘录、元数据和评论的代码,因此对于显示博客类别的任何帮助将不胜感激。

$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>';
}

您可以使用get_the_category

在这里你可以找到它的链接

$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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM