HELP with wordpress.. Featured Post

Discussion in 'Programming' started by HomeBlogger, Nov 4, 2009.

  1. #1
    Hello,

    I'm building a wordpress blog. I've installed a theme that has the featured post feature.

    The problem is whenever I post a new post it gets featured automatically, and I don't like that.. I want to take control of it, I mean I want to set up a post to be featured even if I post other posts later it will still be featured.

    featuredpost.php file
    			<div id="block_featuredblog" class="block">
    				<img src="<?php bloginfo('template_directory'); ?>/images/ribbon_featuredblog.png" class="ribbon" alt="Featured Project"/><!-- CUSTOM FIELDS! -->
                	<div class="block_inside">
                    
                    	<?php
                    		$featured = new WP_Query();
    						$featured->query('showposts=1&cat=-'.BLOG); // Category 1 is the Blog Posts, so we remove that
    						while($featured->have_posts()) : $featured->the_post();
    						
    							$wp_query->in_the_loop = true; // This line is added so that the_tags('') will work outside the regular loop.
    							$featured_ID = $post->ID; // We'll store this here so that we know to skip this post in the main loop
                    	?>
                    
                    		<?php if (get_post_meta($post->ID, 'large_preview', true)) { ?>
                    			<div class="image_block">
                        			<img src="<?php echo get_post_meta($post->ID, 'large_preview', true); ?>" alt="Featured Post" />
                        		</div>
                            <?php } ?>
                        	<div class="text_block">
                            
                    			<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                            	<small>in <?php the_category(', '); ?> tagged <?php the_tags(''); ?></small>
                    			<?php the_content('Read More'); ?>
                    		
                    		</div>
                            
                        <?php endwhile; ?>
                    </div>
                </div>
                
                
    PHP:
    Regards,
     
    HomeBlogger, Nov 4, 2009 IP
  2. LeetPCUser

    LeetPCUser Peon

    Messages:
    711
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
     $featured->query('showposts=1&cat=-'.BLOG);
    
    Code (markup):
    If you change that to:

    
     $featured->query('showposts=1&cat=X');
    
    Code (markup):
    Change x to whatever the category number is for the category you want displayed there. That should work.
     
    LeetPCUser, Nov 4, 2009 IP
  3. HomeBlogger

    HomeBlogger Well-Known Member

    Messages:
    1,071
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    160
    Articles:
    1
    #3
    Already tried it before, but still the problem whenever I post a new post in that category it gets featured, instead I want the previous post (in the same catergory for example) to be featured.
     
    HomeBlogger, Nov 4, 2009 IP
  4. Nystul

    Nystul Well-Known Member

    Messages:
    3,077
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    175
    #4
    Try with query_posts('showposts=1&cat=X'); instead
     
    Nystul, Nov 4, 2009 IP
  5. HomeBlogger

    HomeBlogger Well-Known Member

    Messages:
    1,071
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    160
    Articles:
    1
    #5
    It's the same as LeetPCUser provided!
     
    HomeBlogger, Nov 4, 2009 IP
  6. SCLocal

    SCLocal Notable Member

    Messages:
    1,270
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    235
    #6
    The easiest way to accomplish this is to create a 'Featured Posts' category, then just reference that category. It will maintain and display the last post (in the featured post category) until you add a new one.
     
    SCLocal, Nov 4, 2009 IP