显示标题旁边的图标或文字-WordPress

发布于 2025-02-10 07:19:19 字数 128 浏览 1 评论 0原文

如果帖子包含特定类别 /标签,我想做这件事,那么我想显示标题旁边显示的图标或文本。我该怎么做?这就是我所需要的,我找不到任何插件,因此我可能必须将自己的代码添加到自定义功能插件或其他地方。我对功能描述或与PHP相关的任何内容的了解很少。请帮忙

I want to make that if a post will contains a specific category / tag, then i want show icon or text displayed next to the title. How can I do this? That's all I need, and I can't find any plugins, so I'd probably have to add my own code to the Custom Functions plugin or somewhere else. My knowledge of a function description or anything related to PHP is very little. Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も星光 2025-02-17 07:19:19

这是一个非常简单的想法,您在数组中定义了类别。该值是类别和图像的同名。

如果类别名称在字段中,则加载图像(.jpg)并返回HTML字符串

PHP函数

<?php 

function imageToCat(){
    // get the category variable from WordPress
    $categories = get_the_category();

    // definite array image
    $category =[
        'Allgemein','Cat B'
    ];

    if(in_array($categories[0]->cat_name,$category)){
        // If the cat_name is in array
        return '<img src="'.get_stylesheet_directory_uri().'/image_path/'.$categories[0]->cat_name.'.jpg" alt="" >';

    } // else { echo 'not in Array!';}
}
?>

,您可以在HTML文件中调用该函数作为一个示例

<header>
    <h1><?php echo imageToCat();?>  Your Title</h1>
</header>

This is a very simple idea, you define the category in the array. The value is the same name of the category and the image.

If the category name is in the field, then load the image (.jpg) and return the html string

PHP Function

<?php 

function imageToCat(){
    // get the category variable from WordPress
    $categories = get_the_category();

    // definite array image
    $category =[
        'Allgemein','Cat B'
    ];

    if(in_array($categories[0]->cat_name,$category)){
        // If the cat_name is in array
        return '<img src="'.get_stylesheet_directory_uri().'/image_path/'.$categories[0]->cat_name.'.jpg" alt="" >';

    } // else { echo 'not in Array!';}
}
?>

You can call the function in your HTML file with as an an example

<header>
    <h1><?php echo imageToCat();?>  Your Title</h1>
</header>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文