从档案标题中删除“浏览类别:”

时间:2016-04-26 作者:Céline

我有一个成型的博客主题,我试图从我的档案标题中删除“浏览类别”。

我查看了代码,在“template tags.php”中找到了以下代码:

`//////////////////////////////////////////////////////////////////////////////////////////////////////////////////归档标题//////////////////////////////////////////////////////////////////

if ( ! function_exists( \'shaped_blog_archive_title\' ) ) :

function shaped_blog_archive_title( $before = \'\', $after = \'\' ) {
    if ( is_category() ) {
        $title = sprintf( __( \'Browse Category: %s\', \'shaped-blog\' ), single_cat_title( \'\', false ) );
    } elseif ( is_tag() ) {
        $title = sprintf( __( \'Browse Tag: %s\', \'shaped-blog\' ), single_tag_title( \'\', false ) );
    } elseif ( is_author() ) {
        $title = sprintf( __( \'Browse Author: %s\', \'shaped-blog\' ), \'<span class="vcard">\' . get_the_author() . \'</span>\' );
    } elseif ( is_year() ) {
        $title = sprintf( __( \'Browse Year: %s\', \'shaped-blog\' ), get_the_date( _x( \'Y\', \'yearly archives date format\', \'shaped-blog\' ) ) );
    } elseif ( is_month() ) {
        $title = sprintf( __( \'Browse Month: %s\', \'shaped-blog\' ), get_the_date( _x( \'F Y\', \'monthly archives date format\', \'shaped-blog\' ) ) );
    } elseif ( is_day() ) {
        $title = sprintf( __( \'Browse Day: %s\', \'shaped-blog\' ), get_the_date( _x( \'F j, Y\', \'daily archives date format\', \'shaped-blog\' ) ) );
    } elseif ( is_tax( \'post_format\' ) ) {
        if ( is_tax( \'post_format\', \'post-format-aside\' ) ) {
            $title = _x( \'Asides\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-gallery\' ) ) {
            $title = _x( \'Galleries\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-image\' ) ) {
            $title = _x( \'Images\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-video\' ) ) {
            $title = _x( \'Videos\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-quote\' ) ) {
            $title = _x( \'Quotes\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-link\' ) ) {
            $title = _x( \'Links\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-status\' ) ) {
            $title = _x( \'Statuses\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-audio\' ) ) {
            $title = _x( \'Audio\', \'post format archive title\', \'shaped-blog\' );
        } elseif ( is_tax( \'post_format\', \'post-format-chat\' ) ) {
            $title = _x( \'Chats\', \'post format archive title\', \'shaped-blog\' );
        }
    } elseif ( is_post_type_archive() ) {
        $title = sprintf( __( \'Browse Archives: %s\', \'shaped-blog\' ), post_type_archive_title( \'\', false ) );
    } elseif ( is_tax() ) {
        $tax = get_taxonomy( get_queried_object()->taxonomy );
        /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
        $title = sprintf( __( \'%1$s: %2$s\', \'shaped-blog\' ), $tax->labels->singular_name, single_term_title( \'\', false ) );
    } else {
        $title = __( \'Archives\', \'shaped-blog\' );
    }

    /**
     * Filter the archive title.
     *
     * @param string $title Archive title to be displayed.
     */
    $title = apply_filters( \'get_the_archive_title\', $title );

    if ( ! empty( $title ) ) {
        echo $before . $title . $after;
    }
}
endif;
`

尽管最后解释得很少,但我不明白如何删除它。

感谢您的帮助:)

1 个回复
SO网友:bravokeyl

如果您正在使用child theme. 在中添加筛选器functions.php 像这样的儿童主题。

add_filter(\'get_the_archive_title\',\'wpse_224884_filter_archive_title\',10,1);
function wpse_224884_filter_archive_title($title){
   if ( is_category() ) {
      $title = sprintf( __( \'%s\', \'shaped-blog\' ), single_cat_title( \'\', false ) );
   } 
   return $title;
}

将整个函数复制到函数中。php

function shaped_blog_archive_title( $before = \'\', $after = \'\' ) {
    if ( is_category() ) {
    $title = sprintf( __( \'%s\', \'shaped-blog\' ), single_cat_title( \'\', false ) );
  }else if ....//remaining code
}
if ( ! function_exists( \'shaped_blog_archive_title\' ) ) :

您需要做的唯一更改是删除Browse Category: 第4行中

相关推荐

Updating modified templates

我想调整一些。php模板文件在我的WordPress主题中,我知道正确的过程是将相关文件复制到子主题文件夹中并在那里编辑文件,这样我的修改就不会在将来的主题更新中丢失。但这是否意味着我将无法从主题更新中获益,因为我将文件放在了我的子主题文件夹中?这可能不是一件好事,因为主题更新可能添加了一些有用的特性,甚至修复了我最初需要对代码进行调整的问题!这方面的常见解决方案是什么?有人推荐了一款Diff应用程序——这是人们常用的吗?