admin管理员组文章数量:1122832
In tag pages, I want to display specific text if the title containing a specific word.
As example:
I have a Tag and tag archive page: Yellow Banana
And I want to display “cool fruits” in all tag pages that have in title word “Banana”.
Can you tell me the code?
In tag pages, I want to display specific text if the title containing a specific word.
As example:
I have a Tag and tag archive page: Yellow Banana
And I want to display “cool fruits” in all tag pages that have in title word “Banana”.
Can you tell me the code?
Share Improve this question asked Apr 13, 2020 at 14:30 SeryozhaSeryozha 191 silver badge2 bronze badges1 Answer
Reset to default 0You may use string comparison. I could illustrate a simple example code.
It is assumed that the user with the following knowledge/experience
- PHP - understand what is variables, static value
- WordPress templates and how to modify them
There are many ways to test string such as
- php string comparison strpos() (simple)
- php regular expression preg_match() (required more test and knowledge)
This example shows the simple way to check the title.
Assumed you are talking about templates so the following code will be put in tag archive template. eg. tag.php
<?php
// assumed you are doing it in a loop
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$str_search = strpos( $post->title, 'Banna' ); // assumed when your $post-title contains 'Banna'
if( $str_search !== false && $str_search >= 0 ) {
echo 'cool fruits';
}
endwhile;
endif;
?>
- A friendly reminder: make sure you read, research and test rather than just copy and paste and hope this answer resolve all the questions and troubles instantly without spending further effort.
本文标签: tagsDisplay text if title in archive has specific word
版权声明:本文标题:tags - Display text if title in archive has specific word 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292606a1928970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论