从the_archive_title中删除“类别:”,“标签:”,“作者:”
9 个回答
- 投票数
-
- 2015-02-27
您可以扩展
get_the_archive_title
过滤器在此答案中提到add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { $title = '<span class="vcard">' . get_the_author() . '</span>' ; } elseif ( is_tax() ) { //for custom post types $title = sprintf( __( '%1$s' ), single_term_title( '', false ) ); } elseif (is_post_type_archive()) { $title = post_type_archive_title( '', false ); } return $title; });
You can extend the
get_the_archive_title
filter which I've mentioned in this answeradd_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { $title = '<span class="vcard">' . get_the_author() . '</span>' ; } elseif ( is_tax() ) { //for custom post types $title = sprintf( __( '%1$s' ), single_term_title( '', false ) ); } elseif (is_post_type_archive()) { $title = post_type_archive_title( '', false ); } return $title; });
-
这样可行!谢谢,彼得!如果不那么精通技术的用户正在寻找相同的解决方案:将Pieters代码添加到functions.php文件中就可以了!That works! Thanks, Pieter! In case less tech-savy users are looking for the same solution: You add Pieter's code to your functions.php file and that's it!
- 2
- 2015-02-27
- Nick
-
在子主题中执行此操作,以使您的更改不会在主题更新时丢失.Do this in a child theme so your changes won't get lost upon a theme update.
- 0
- 2016-08-19
- Jürgen Paul
-
这很好用,但是缺少档案和自定义分类法的情况.This works pretty well, but it's missing cases for archives and custom taxonomies.
- 1
- 2016-11-23
- JacobTheDev
-
请参阅Ben Gillbanks的[解决方案](https://www.binarymoon.co.uk/2017/02/hide-archive-title-prefix-wordpress/)中的所有帖子类型档案和分类法.See Ben Gillbanks' [solution](https://www.binarymoon.co.uk/2017/02/hide-archive-title-prefix-wordpress/) to all post type archives and taxonomies.
- 0
- 2018-01-27
- Dan Knauss
-
刚刚添加了对CPT存档的支持:)Just added support for CPT archives :)
- 0
- 2020-03-09
- Maxwell s.c
-
不涵盖年份doens't cover year
- 0
- 2020-07-16
- Corey
-
-
您可以在WP中以多种方式执行操作,但是我总是选择最简单的解决方案.谢谢蒂莫.You can do things many ways in WP, but I always opted for the simplest solutions. Thanks Timo.
- 1
- 2018-01-11
- f055
-
嗯,这对并非所有术语的档案都无效.因此,我认为这不是一个很好的解决方案.Well that just doesn't work for all archives that aren't terms. So in my opinion not a very good solution.
- 1
- 2019-04-05
- GDY
-
您能告诉@GDY,档案中应显示哪些非术语?@GDY could you tell, which non-terms should show in archives?
- 0
- 2019-12-17
- Iggy
-
-
- 2017-08-10
对于CPT标题,无字:"存档":
如果您要为CPT构建自定义存档模板,并且只想输出CPT的标题而没有多余的单词(例如" Archive"),请改用以下功能:
post_type_archive_title();
For CPT title Without word: ‘Archive’:
If you are building custom archive template for a CPT, and want to output just the title of the CPT with no extra word like “Archive” use following function instead:
post_type_archive_title();
-
很好-此功能正是我所需要的.注意,第一个参数已经默认为空字符串,第二个参数默认为true,这将回显结果而不是返回结果……因此您可以使用`post_type_archive_title()`获得与`echopost_type_archive_title'完全相同的结果('',false)`Nice - this function is just what I needed. Note that the first parameter already defaults to and empty string and the second defaults to true which would echo out the result instead of returning it... so you could just use `post_type_archive_title()` to get the exact same result as `echo post_type_archive_title( '', false )`
- 0
- 2019-12-08
- squarecandy
-
-
对于非英语网站来说,这是行不通的.this wouldn't work for an non-english website.
- 2
- 2018-11-09
- Maxwell s.c
-
-
- 2016-08-13
echo '<h1 class="page-title">' . single_cat_title( '', false ) . '</h1>';
在主题公开之外的taxonomy-category.php中.echo '<h1 class="page-title">' . single_cat_title( '', false ) . '</h1>';
in taxonomy-category.php outside public of theme. -
- 2018-05-14
我将使用过滤器并将其放入文件functions.php中
add_filter( 'get_the_archive_title', 'replaceCategoryName'); function replaceCategoryName ($title) { $title = single_cat_title( '', false ); return $title; }
I would use a filter and put it in a file functions.php
add_filter( 'get_the_archive_title', 'replaceCategoryName'); function replaceCategoryName ($title) { $title = single_cat_title( '', false ); return $title; }
-
这是一个不错的解决方案,但实际上您应该在将$title更新为single_cat_title之前检查is_category(),如果不是is_category(),则只需返回$title不变即可.This is a nice solution, but really you should check is_category() before updating $title to single_cat_title, & if not is_category(), then just return the $title unchanged..
- 0
- 2020-08-20
- Paul 501
-
-
虽然是正确的,但之前在其他答案中已经建议过这一点.While true, this has been suggested before in other answers.
- 2
- 2018-02-27
- Nicolai
-
-
- 2019-10-06
假设格式始终为:
Prefix: Archive Name
,我们可以使用get_the_archive_title()与PHP的 substr()和 strpos()函数.<?php // Only show the portion of the string following the first ": " echo substr(get_the_archive_title(), strpos(get_the_archive_title(), ': ') + 2); ?>
Assuming the format is always:
Prefix: Archive Name
, we can just find the first colon followed by a space, and only show the content after this, using get_the_archive_title() with PHP's substr() and strpos() functions.<?php // Only show the portion of the string following the first ": " echo substr(get_the_archive_title(), strpos(get_the_archive_title(), ': ') + 2); ?>
-
- 2016-09-06
目录:
wp-includes
文件:
general-template.php
查找函数:
get_the_archive_title()
更改:if ( is_category() ) { $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) ); } elseif ( is_tag() ) { $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) ); } elseif ( is_author() ) { $title = sprintf( __( 'Autor: %s' ), '<span class="vcard">' . get_the_author() . '</span>' ); }
收件人:
if ( is_category() ) { $title = sprintf( __( '%s' ), single_cat_title( '', false ) ); } elseif ( is_tag() ) { $title = sprintf( __( '%s' ), single_tag_title( '', false ) ); } elseif ( is_author() ) { $title = sprintf( __( '%s' ), '<span class="vcard">' . get_the_author() . '</span>' ); }//if you want to remove or just change text if you need to
directory:
wp-includes
file:
general-template.php
find function:
get_the_archive_title()
change:if ( is_category() ) { $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) ); } elseif ( is_tag() ) { $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) ); } elseif ( is_author() ) { $title = sprintf( __( 'Autor: %s' ), '<span class="vcard">' . get_the_author() . '</span>' ); }
to:
if ( is_category() ) { $title = sprintf( __( '%s' ), single_cat_title( '', false ) ); } elseif ( is_tag() ) { $title = sprintf( __( '%s' ), single_tag_title( '', false ) ); } elseif ( is_author() ) { $title = sprintf( __( '%s' ), '<span class="vcard">' . get_the_author() . '</span>' ); }//if you want to remove or just change text if you need to
-
错误,您是否真的建议在这里破解内核?Err, are you really suggesting hacking the core here?
- 3
- 2016-09-06
- cjbj
-
这是一个非常非常糟糕的主意.如果不创建单独的分支,则无法立即更新.This is a very, very bad idea. You cannot update now without creating a separate branch.
- 4
- 2016-09-06
- fuxia
-
很抱歉,如果我中断工作,我会对此说一句话,但这只是另一种解决方案,没有恶意.所以,您说我入侵了自己的网站,还是无法共享核心文件中的代码?Sory if I break roles I give a word for that, but this is just another solution nothing malicious. So, you said that I hack my own site or I cant share code from core files?
- 0
- 2016-09-06
- Dragan Nikolic
-
好吧,这是您的网站,您可以编辑任何内容-甚至是核心文件.但是,如果您更新Wordpress,网络将中断.Well, it's your website and you may edit whatever you want - even the core files. However, the web will break if you update your Wordpress...
- 0
- 2016-09-22
- Raccoon
我的主题的archive.php中包含以下代码:
这给了我诸如"类别:俄罗斯","标签:美国","作者:约翰"之类的标题.
我想删除"类别:","标签:"和"作者:"部分,仅显示类别,标签和作者姓名.
有人知道如何做到这一点吗?
谢谢.