Support » Themes and Templates » Distinguish posts by category and max amount of posts

  • Resolved Sophiamolino


    I have a problem with distinguish posts by category on the frontpage.
    Want I want:
    – 3 different categories (columns, hotspots & trends)
    – 2 posts for every category
    What I get now:
    – Category ‘columns’&’hotspots’ are distinguish, but posts in category trends get in all categories.
    – There is no max on the amount of posts

    My code for the category ‘columns’ on the frontpage:

    			if (have_posts()) : while (have_posts()) : the_post(); 
    <?php if( !(in_category('hotspots')) || !is_home() )  { ;?>
    <?php /* This is our two columns loop */ ?>
    <div id="cms-column" style="width:460px;">
    		<div style="float:left; width:220px;" class="post<?php if(!has_post_thumbnail()) echo " no-featured"; ?>">
    			<?php if(has_post_thumbnail()): ?>
    			<div class="featured">
    				<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(700,9999)); ?></a>
    				<div class="credit"></div>
    			<?php endif; ?>
    		<div style="float:left">
    			<div class="detail" style="width:220px;">
    					<div style="width:220px; float:left; margin-left:2px;">
    			<?php _e(''); ?>  <div style"float:right; margin-top:-20px;"><?php echo get_the_date(); ?></p></div></div>
    					<div class="blog-titles2"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    			<div style="clear:both;"></div>
    				<div class="excerpt">
    					<?php the_excerpt(); ?>
    					$args = array(
    						'post_type' => 'attachment',
    						'numberposts' => 2,
    						'post_status' => null,
    						'post_parent' => $post->ID
    					$attachments = get_posts($args);
    					if(count($attachments) > 1):
    					<div class="bottom"></div>
    				<?php endif; ?>
     <?php if ( in_category('4') ) { ?>
               <div class="post-cat-four">
    <?php } ?>
    			<div style="clear:both;"></div>
    <?php /* closing div for the two columns */ ?>
    		<?php } endwhile;?>
    // Reset Query

    I think there is a fault in <?php if( !(in_category(‘hotspots’)) || !is_home() ) { ;?> . Is it right that the “if” is causing the exclusion of posts of category ‘hotspots’. Okay, that is almost what I want, because in the section ‘columns’, I don’t want to have posts of ‘hotspots’.
    However, how can I just say to get only posts of ‘columns’? I have read the whole explanation of the query posts in wordpress and I tried some things, but it didn’t work out. That’s why I think there are more fualts in the total code. Like the `<?php if ( in_category(‘4’) ) { ?>
    <div class=”post-cat-four”>`. I can not exclude this code from the total code, because than my page is not working anymore. However, I don’t understand the meaning of this code, because I don’t even think ‘columns’ belongs to cat=4. And I got exactly the same code (with the cat=4) in the other category ‘hotspots’. So that is really weird.

    Also the numberposts => 2 doesn’t work. I got all the posts and not just two of them.

    I hope someone understands my problem and would help me.

    By the way, don’t get confused with the clear:both and columns shit in the code. This is to get two post side by side and the tumbnail & text side by side. Sooo this ‘columns’ is something else then my category ‘columns’.

    I am a beginner in wordpress, but I am eager to learn and Iam also experienced in mathematic programs like matlab.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Distinguish posts by category and max amount of posts’ is closed to new replies.