WordPress,如何更改帖子标题以显示帖子类别?

在我们使用的主题Mesmerize-Pro中, 所有帖子均在两个位置显示帖子标题:

  1. (英雄标题)标题和
  2. 实际的帖子标题。

示例:(链接已删除)

我想更改最热门的英雄标题, 以显示帖子类别。

我可以通过functions.php将帖子标题更改为该类别, 但这没什么意义。

感谢你的任何帮助。

-e

细节:

.inner-header-description h1.hero-title (Top Title, want to be the Category)

.post-item .post-content-single body #page h1 (Post Title, as is)

#1


从主题来看, 确定英雄头衔的方式似乎有点过于复杂。如果主题中没有替代选项(我没有安装要检查的选项), 则确实会出现一个可以插入的mesmerize_header_title过滤器, 这显然是它们如何原生更改主题中WooCommerce页面上的标题。

需要注意的一件事是, 帖子上可以有很多类别, 因此通常你只希望显示第一个类别。我们可以使用get_the_category()返回WP_Term对象的数组, 并将第一个应用于标题过滤器:

add_filter('mesmerize_header_title', function($title){
    if( is_single() ){
        $categories = get_the_category();
        $title      = $categories[0]->name;
    }

    return $title;
});

你应该能够将其放在functions.php文件中, 并且一切顺利。

我将此代码基于/inc/woocommerce/woocommerce.php文件, 该文件包含以下内容:

add_filter('mesmerize_header_title', function ($title) {

    if (mesmerize_is_page_template()) {
        if (is_archive() && mesmerize_get_current_template() === "woocommerce.php") {
            $title = woocommerce_page_title(false);
        }
    }

    return $title;
});

来源:

https://www.srcmini02.com/66158.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37137.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?