scriptygoddess

06 Sep, 2003

Using php to selectively show or hide content based on MT category

Posted by: Jennifer In: Script snippet

All of you people that actually know PHP may want to skip this entry as what I'm about to say will probably make you cringe. You could probably do this in some frightfully easy way, but I've barely cracked my PHP book open, so this has to work for me for now.

I discovered the following PHP snippet when I implemented the ScriptyGoddess show/hide script and I use it a lot throughout my site.

<?
if ( xxx == xxx ) {
?>
…stuff…
<? } ?>

My latest bit of witchery allows me to have only certain information show up on a page. For example, the blog that publishes the static pages of my site (about, contact etc) and the writing in the writing section is set to individually archive entries.

The problem is that I only want a feedback form and the creative commons license info to show up for those entries tagged with the 'writing' category. So, the above php snippet to the rescue.

I added the MT category code to the Individual Archive template, but commented it out because I don't want it to show. Then I surrounded the feedback form and cc info with the following:

<?
if (<$MTCategoryLabel$> == "writing") {
?>
…feedback form…
…cc info…
<? } ?>

So when the page gets published, the entry category is checked, and if it matches 'writing', the form and creative commons license info shows up.

By repeating the php snippet and changing the category type to be matched, you could have information show up for several different categories, I would imagine. Though I haven't tried this out yet.

See for yourself:
entry not tagged as 'writing'
entry tagged as 'writing' with feedback form and cc info

3 Responses to "Using php to selectively show or hide content based on MT category"

1 | Ivette01

September 9th, 2003 at 2:43 pm

Avatar

thanks for sharing Patricia and Jennifer :) Ill try to understand and play with it!

2 | Crys

September 9th, 2003 at 8:28 pm

Avatar

I do do a fair amout of php coding and that's almost exactly how I do it :) I *am* more likely to use the other format for an if statment in this case but it's purely an estetic matter the funtion is identical:

<? if ( xxx == xxx ): ?>
HTML code
<? endif; ?>

and just in case some one needs the code here's how to add an else clause (as in show this if it's one catergory otherwise show this

<? if ( xxx == xxx ): ?>
HTML code
<? else: ?>
HTML code
<? endif; ?>

OR

<? if ( xxx == xxx ) { ?>
HTML code
<? } else { ?>
HTML code
<? } ?>

And to display somthing if the category (or whatever) is /not/ the value you give:

if ( xxx != xxx )

OR

if (!( xxx == xxx ))

3 | Mama Write's Sideblog

May 22nd, 2004 at 5:08 pm

Avatar

http://www.mamawrite.com/sideblog/002843.html
Using php to selectively show or hide content based on MT category…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements