newbee
newbee

Reputation: 11

How to display text in my wordpress post except if it's in a certain category?

I want to display certain text in all my posts except if it's in this one category. How do I do that? Oh yea I almost forgot I want to include the title of the post in the text. So I think I need to use echo, cat='-5', and or something?? I don't know how to form it though. Thanks!

Upvotes: 1

Views: 1292

Answers (2)

Philip Jones
Philip Jones

Reputation: 376

Do you require the text to be completely locked away, or just hidden from view? If you only need it hidden from view (but accessible to anyone who chooses to pry) then you may be able to do it very quickly using css.

If you have coded your theme - or are using someone else's - that adds helpful styles into the header, you may have a lot to work with already. For example, this is a body declaration generated by the Thematic theme:

<body class="wordpress y2011 m01 d31 h12 archive category category-orthopaedics">

Say you have a chunk of content to hide:

<div class="text_to_hide">This is what gets hidden.</div>

Then you declare the CSS as:

.category-orthopaedics .text_to_hide { display: none; }

Upvotes: 0

probabilityzero
probabilityzero

Reputation: 1012

You could use the Wordpress function in_category(). When you use it inside the loop, it returns true if the current post is a member of the category you passed it.

<?php 
if ( in_category('my-category'))
{
    // don't output text
} else {
    // do output text
}
?>

Upvotes: 2

Related Questions