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