Support » Fixing WordPress » Archive Page template by category but excluding some. WP 2.5

  • Resolved pshero


    Hey Gang,
    I’m hoping to get some coding help here. I’m not bad at manipulating PHP, but I’m crap at writing it, so I’m hoping someone with a little extra time and a generous spirit can help me out.

    I’ve got an Archive template which calls each category in alphabetical order followed by it’s associated posts. My code looks like this:

    <?php $cats = get_categories("hierarchical=0"); ?>
    <?php if($cats != NULL) { ?>
    		<?php foreach ($cats as $cat) { ?>
    			<?php if($cat != NULL) {
    				$base_url = get_bloginfo('home') . "/category/" . $cat->slug; ?>
    				<h3><a href="<?php echo $base_url?>"><?php echo $cat->cat_name?></a></h3>
    			<?php } ?>
    			<?php // Show category description
    				if ($cat->category_description != NULL) ?>
    					<p><?php echo $cat->category_description ?></p>
    				<?php $myposts = get_posts("category=$cat->cat_ID"); ?>
    				<?php foreach($myposts as $post) : ?>
    					<li><?php the_time('M d') ?>. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    				<?php endforeach; ?>
    	<?php } ?>
    <?php } ?>

    But now I’ve created categories which I want to exclude from this list but have absolutely no idea where to begin.

    Thanks a million (in advance) for any help you can provide. Like I said, I’m no good at writing php syntax, so if you could give a code example that would be infinitely helpful.


Viewing 1 replies (of 1 total)
  • For those of you who want to know how to do this too, I’ve spent hours pouring over the wp codex to finally come up with a solution.

    Using the code above, switch out this line
    <?php $cats = get_categories("hierarchical=0"); ?>

    With this:
    <?php $cats = get_categories('orderby=name&exclude=13'); ?>

    And if you want to exclude more than one category simply separate them with a comma. (ie ‘orderby=name&exclude=13,6,29’)

    I hope this helps someone else!

Viewing 1 replies (of 1 total)
  • The topic ‘Archive Page template by category but excluding some. WP 2.5’ is closed to new replies.