Featuring few posts on each category page

Discussion in 'WordPress' started by Matt18, Jan 15, 2011.

  1. #1
    Hi

    I need some help :eek:

    I have a list of posts on my wordpress category page and I would like to set first few to have a different background, only on the category page. That way when visitor would click on the category and see 10 posts, the first two for example would have a different styling.

    It would be really cool if I could somehow set this to happen in only few categories.

    Is there a plugin or function to do that?

    Thank you very much for your help in advance.
     
    Matt18, Jan 15, 2011 IP
  2. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Depending on the theme you are using, this functionality should be built into it already. When you mark a post as a "sticky" it should float to the top of the page. Review your source code to see what you will need to style with CSS, if needed.
     
    Dodger, Jan 15, 2011 IP
  3. Matt18

    Matt18 Guest

    Messages:
    591
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nothing happens. I'm talking about the category pages. Not the front page, if that makes a difference.

    Or is there any way to just change the look of the post? I could bring it up by changing the date...
     
    Matt18, Jan 15, 2011 IP
  4. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Look at the coding for the front page, then modify your categories.php file to do the same thing.

    Styling to make them look different is easy too, but would again depend upon the theme. You need to look at your source code to see what class they identify sticky post with (usually this is just "sticky"). With that information you will be able to apply styling in your theme stylesheet.
     
    Dodger, Jan 15, 2011 IP
  5. Matt18

    Matt18 Guest

    Messages:
    591
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you very much for trying to help me out Dodger. I just can't manage to get any style to the posts in the category. This is what I use in the category page to call posts:

    after that is the post definiton. How could I get wp to add some styling in case post is a sticky?

    thanks alot again!
     
    Matt18, Jan 15, 2011 IP
  6. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You left out the most important part, all of the stuff that displays the post. Post the whole categories.php file. And it would be helpful if you posted it within the bbCode "code" tags to make it easier to read and maintain the formatting.
     
    Dodger, Jan 15, 2011 IP
  7. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
  8. Matt18

    Matt18 Guest

    Messages:
    591
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    no, I'm using benzo theme

    I am adding the full category page below. I managed to partly solve the problem though.

    I added this as a class of a post holder on the category page:

    <?php
    if (is_sticky()) echo 'class="sticky"';
    else echo 'class="normal"';
    ?>
    Code (markup):
    So that part is solved. Now I just have to find a way to bring all the sticky posts from a certain category to the top of the category page. Any help will be greatly appriciated.

    Thank you very much Dodger!

    Category page:
    <?php global $options; foreach ($options as $value) {if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}?>
    <?php get_header(); ?>
    
    
    
    <div class="cat_container">
    
    	<div class="cat_left">
    	<?php while (have_posts()) : the_post(); ?>
    			 <?php if ($images = get_children(array(
    				'post_parent' => $post->ID,
    				'numberposts' => '1',
    				'post_type' => 'attachment',
    				'post_mime_type' => 'image',
    				'order' => 'ASC',
    				'orderby' => 'menu_order')))  
    			 foreach($images as $image) {  
    				$exehill_image = $image->guid; 
    				$exehill_thumb = wp_get_attachment_thumb_url( $image->ID);			
    				} else {
    				$exehill_thumb = site_url('/wp-content/themes/benzo1.1/images/noimage_cat.png');
    				} ?>
    
    
    <div class="blog_container">
    
    
    
    	<div class="blog_top" style="background: url(<?php echo $exehill_thumb; ?>) no-repeat; "> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"></a>
    	
    	</div>
    	
    	<div class="blog_content">
    	
    		<div class="blog_headline">
    		
    			<span class="blog_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></span> 
    			
    			
    			
    		</div>
    		
    		<div class="blog_excerpt"><?php the_excerpt(); ?><span><a href="<?php the_permalink() ?>">Learn more &rarr;</a></span>
    		</div>
    	
    	</div>
    	
    	<div class="clear">
    	</div>
    
    
    	
    </div>
    		
    	<?php endwhile; ?>
    <div class="pagnav">
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    </div>
    </div>
    	
    <div class="cat_right"><?php get_sidebar(); ?>
    </div>
    	
    	<div class="clear">
    	</div>
    	
    </div>
    
    
    
    <?php get_footer(); ?>
    
    Code (markup):
     
    Matt18, Jan 15, 2011 IP
  9. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Technically, you will need two WP_Query Loops that take advantage of Sticky Post Parameters. First loop will display 'x' amount of sticky posts, then the second will display 'x' amount of non-sticky posts.

    Currently you have one loop that displays all posts in the category without separation. Separating into two Loops, of which, both will look almost identical line for line except the parameters for whether they are sticky or not. This is not just a simple cut and paste also, you need to have two WP_Query objects created (the first is already there via the global $post which has the have_posts() and the_post() methods in play).

    Since there will be repetitive code, consolidating all of the code that outputs 'blog_container' DIV block into a callable function would be prudent also.

    That is the theory anyway. Between the two links I gave you above, you should be able to muddle through this.

    As an aside, for a premium theme, I am not too impressed with the coding I have seen (that Google code link I asked about uses parts of your theme, or is a pre-cursor to it )
     
    Dodger, Jan 15, 2011 IP
  10. Matt18

    Matt18 Guest

    Messages:
    591
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks alot Dodger! :)

    I will read it all through the moment I have a little more time. Otherwise I'll just use dates to get them up on the top :)

    thank you again for your help
     
    Matt18, Jan 16, 2011 IP