MovableBlog: Exclude a Single Category

Nuance 2.0

May 13, 2002

I worked on this for about a half-hour and it actually worked.

Might noticeably slow down your site, because there's PHP for each entry.

Note: there are still some bugs to work out. Like how the date header doesn't show up if the excluded category is the latest post.

<MTEntries>
<?php

$category_array = array();
<MTEntryCategories>
$category_array[] = "<$MTCategoryLabel$>";
$count++;

</MTEntryCategories>
$flagged = FALSE;
for ($i = 0; $i < $count; $i++)
{
if ($category_array[$i] == "CATEGORY_NAME")
{ $flagged = TRUE;
}
}

if (!$flagged)
{
?>

[insert MT code and HTML here; this will only get shown on your site if CATEGORY_NAME is not one of the categories for the individual entry]

<?php
}

reset($category_array);

?>

</MTEntries>

Posted by Richard at 1:05

Comments

Perhaps I don't understand what you're trying to instruct here, but why couldn't you use far simpler code to exclude a certain category from the page:

<MTEntries>
<?php
$cat = "<$MTEntryCategory$>";
if (!$cat == "Name Of Excluded Category") {

?>

PLACE NORMAL MTENTRIES TAGS HERE - MTEntryBody, MTEntryTitle, etc, as you would a normal template

<?
}
?>
</MTEntries>

This is for when posts have multiple categories. If one of the categories is the excluded category, the post doesn't get published.

Ahhhhh. Gotcha.