WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] max two posts and organize posts by category (1 post)

  1. Sophiamolino
    Member
    Posted 1 year ago #

    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:

    <?php 
    
    			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>
    				<div class="credit"></div>
    			<?php endif; ?>
    		</div>
    
    		<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(); ?>
    
    				</div>
    				<?php
    					$args = array(
    						'post_type' => 'attachment',
    						'numberposts' => 2,
    						'post_status' => null,
    						'post_parent' => $post->ID
    						);
    					$attachments = get_posts($args);
    					if(count($attachments) > 1):
    				?>
    
    					</div>
    					<div class="bottom"></div>
    
    				<?php endif; ?>
    		</div>
    
    			</div>
    			<div style="clear:both;"></div>
    <?php /* closing div for the two columns */ ?>
    </div>
    		<?php } endwhile;?>
    <?php
    // Reset Query
    wp_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.

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic