如何从category.php页面上的 URL 回显一个或多个分类?

PHP 如何仅从上一页单击的链接中回显两个类别?我想在我的 category.php 页面上列出一个或多个类别。

如果我使用链接:/category/one/(1 个分类),我可以使用<?php single_cat_title(''); ?>它来回显第一个类别,但有时我需要回显 2 个或更多类别,以下方法就可以更好的获取:

<h1>
<?php
global $wp_query;
foreach ( $wp_query->tax_query->queries as $query ) {

$category_slug = $query['terms'][0];
$category = get_category_by_path( $category_slug );
echo esc_html( $category->name )." ";
/*echo count( $wp_query->tax_query->queries); //counts number of catogries*/
if ( count( $wp_query->tax_query->queries ) >= 2) {
echo " + ";
};
/* something to trim off the last + mark ltrim($str, '+');*/
}
echo " (". $wp_query->found_posts . ") ";
?>
</h1>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
开发教程

如何关闭媒体上传的评论

2022-10-21 11:31:12

开发教程

如何从媒体库中获取图像并按 Alt 标签排序

2022-10-21 12:03:32

8 条回复 A文章作者 M管理员
  1. Hi my family member! I want to say that this post is awesome, nice written and come with approximately all significant infos. I would like to peer extra posts like this.

  2. I have read some excellent stuff here. Definitely value bookmarking for revisiting. I wonder how much effort you put to make the sort of excellent informative website.

  3. I do agree with all the ideas you have introduced on your post. They are very convincing and will definitely work. Still, the posts are very short for newbies. May just you please prolong them a little from subsequent time? Thank you for the post.

  4. Somebody essentially lend a hand to make significantly articles I’d state. That is the very first time I frequented your website page and up to now? I surprised with the research you made to make this actual submit amazing. Wonderful task!

  5. Fantastic site. A lot of helpful info here. I’m sending it to some buddies ans additionally sharing in delicious. And naturally, thanks on your sweat!

  6. Wonderful beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog web site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear idea

  7. hi!,I like your writing so much! share we be in contact more approximately your article on AOL? I need a specialist in this area to resolve my problem. Maybe that is you! Looking ahead to see you.

  8. My brother recommended I might like this web site. He was totally right. This post actually made my day. You cann’t imagine just how much time I had spent for this information! Thanks!

个人中心
今日签到
有新私信 私信列表
搜索
赣ICP备2021010644号-1