简体   繁体   中英

How to add php string that get category title in wordpress

I just wanted to know how to apply php string when you want to get the title: ex.

 <h1 class="page-title"><?php single_cat_title(__('category:','themename')); ?></h1>

so if the title is "Video's", the button in the content will change to "Watch now" instead of "Read more" which is the default.

something like

if title is = "video's" {
echo "<button>Watch now</button>"
}<button>Readmore</button>

Simple PHP if/else

Here's the code which will work for you

if (single_cat_title("",false) == "video's") {
 echo "<button>Watch now</button>"
} else {
 echo "<button>Readmore</button>"
}

I am just assuming that title is actually titled video

Here is basic approach you can check video post by it's category id even with the category name. here is the example code.

$category_id = get_cat_ID('Category Name');
if( $category_id == 'your cat id'){
echo 'watch video';
{
else{
echo 'readmore';
}

Hope it helps. cheers!

You need false as second parameter to just return the value (not print). And then just compare it.

if (single_cat_title("", false) == "video's") {
    echo "Watch now";
} else {
    echo "Read more";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM