WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Archive Page template by category but excluding some. WP 2.5 (2 posts)

  1. pshero
    Member
    Posted 6 years ago #

    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) { ?>
    		<ul>
    		<?php foreach ($cats as $cat) { ?>
    			<li>
    
    			<?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"); ?>
    				<ul>
    				<?php foreach($myposts as $post) : ?>
    					<li><?php the_time('M d') ?>. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    				<?php endforeach; ?>
    				</ul>
    			</li>
    	<?php } ?>
    		</ul>
    <?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.

    Thanks!

  2. pshero
    Member
    Posted 6 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.