Why isn't my if statement working with get_the_category?

后端 未结 2 1972
小蘑菇
小蘑菇 2021-01-26 00:00

Im trying to make an if statement that would echo a word for each category that the post is in, it gets the category name from the post id, but the first category is All Stories

2条回答
  •  盖世英雄少女心
    2021-01-26 00:08

    The only issue I can see is that you need to use a comparison operator ("==") instead of setting the $category_detail variable with ("="). Make sure you're changing that in BOTH places.

    Also note that the wordpress coding standards say your comparison should have the variable on the right, that way if you ever mis-type it or something else goes wonky the operation fails and throws an error instead of ALWAYS returning true.

    Example:

    if( "Company News" == $category_detail ){
        echo "hello world";
    }
    

提交回复
热议问题