StudioPress Community Forums

StudioPress Community Forums (http://www.studiopress.com/support/index.php)
-   General Discussion (http://www.studiopress.com/support/forumdisplay.php?f=7)
-   -   Excluding Posts Except From Specific Category (http://www.studiopress.com/support/showthread.php?t=10098)

rishel 06-21-2009 10:08 AM

Excluding Posts Except From Specific Category
 
Guys, posting this in general, its a code based question. If anyone can throw a possible solution at it, that would be great.

I am trying to change this code to only display from category 5 (exclude categories 1,2,3,4) and only allow 10 posts from it. Just seeing if anyone can tell me what to edit, I tried a few things, that did not work.

Here is the code for anyone that may think they can get it to work. I am assuming the edits need to be done on line 14 or 16?

Code:

<?php get_header(); ?>

<?php
        if (is_home()) {
                include ('head_highlight.php');
                include ('products_highlight.php');
        }
        include ('sidebar_home.php');
?>

<div id="main-content">
        <div class="padd20">
       
                <?php if (have_posts()) : ?>
                                       
                        <?php while (have_posts()) : the_post(); ?>
                       
                                <div class="post-item clearfix">
                                                               
                                        <h2>"><?php the_title(); ?></h2>
                                        <?php
                                                if ( get_post_meta($post->ID,'thumb', true) ) {
                                                        $thumbwidth = get_option('fancytheme_thumb_width'); // thumbnail width
                                                        $thumbheight = get_option('fancytheme_thumb_height'); // thumbnail height
                                                        if ( $thumbwidth && $thumbheight ) {
                                        ?>
                                <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">[img]<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, [/img]&amp;h=<?php echo $thumbheight ?>&amp;w=<?php echo $thumbwidth ?>&amp;zc=1&amp;q=80" alt="<?php the_title(); ?>" /></a>
                                        <?php
                                                        }
                                                }
                                        ?>
                                        <h3>Posted on <?php the_time('l, F jS, Y') ?></h3>
                                        <?php the_excerpt(); ?>
                                        continue reading
                                       
                                </div>
                               
                        <?php endwhile; ?>
                       
                                <?php if (show_posts_nav()) : ?>
                                <div id="post-navigation" class="clearfix">
                                        <span class="previous"><?php next_posts_link('Older Entries') ?></span>
                                        <span class="next"><?php previous_posts_link('Newer Entries') ?></span>
                                </div>
                                <?php endif; ?>       
                       
                        <?php else : ?>
                       
                        <h2 class="center">Not Found</h2>
                        <p class="center">Sorry, but you are looking for something that isn't here.</p>
                       
                <?php endif; ?>                       
               
        </div>
</div>

<?php get_footer(); ?>


adew 06-21-2009 11:41 AM

Re: Excluding Posts Except From Specific Category
 
Hi,

Use query_posts to modify the database query (ie to modify the normal Loop).

Add this:
Code:

<?php query_posts("cat=5&showposts=10"); ?>
immediately above this line:
Code:

<?php if (have_posts()) : ?>
That should do it.

rishel 06-21-2009 11:59 AM

Re: Excluding Posts Except From Specific Category
 
Adew, worked like a champ, thank you very much.

adew 06-21-2009 12:33 PM

Re: Excluding Posts Except From Specific Category
 
Cool! :)


All times are GMT -5. The time now is 05:45 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.