开发者

Any idea why Wordpress's inCategorgy tag is not working?

So I am trying to add a "-none" to a class for a post if it is in a specific category in Wordpress. So like lets say if I am viewing a post that has a category id of 7, i want a certain class titled "example" change to "example-none".

Here's my code:

<div class="example<?= is_category('events')  ?'-none':'' ?><?= in_category('7')   ?'-none':'' ?>">

The weird thing with the code is, it works in a page when I am viewing all the posts in a specific category. But when I go to an interior post that is in a specific category, the code does not work.

I am using the in_category('7') tag to achieve this on a wordpress sidebar.

开发者_开发技巧

Any idea on what I am doing wrong?


I would remove the quotes around the id of the category:

in_category(7)

This should be a number, not a string.


Thanks. i got it working using this code:

    <div class="example<? wp_reset_query(); ?><?= in_category(7)   ?'-none':'' ?>">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜