• Resolved claudchan

    (@claudchan)


    Hi,
    Appreciate if someone can help me.
    I have posts need to wrap inside the ul li.
    But each li have to show 2 posts.
    How to show 2 posts in each li?

    Many thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter claudchan

    (@claudchan)

    Anyone?

    A bit more info would be relevant – i.e. theme, where are you trying to do this, code you are using, link to your site.

    Thread Starter claudchan

    (@claudchan)

    Here is my current code:

    <h2>Recent News</h2>
    <ul class="post-carousel">
    
    	<?php
    
    	$posts = get_posts("showposts=10");
    
    	if ($posts) {
    		foreach ( $posts as $post) : setup_postdata($post);
    	?>
    
    	<li>
    
    		<div class="entry">
    			<div class="entry-date">
    				<div class="entry-day"><?php the_time('d'); ?></div>
    				<div class="entry-month"><?php the_time('M'); ?></div>
    			</div>
    			<div class="entry-body">
    				<h4 class="entry-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
    				<div class="entry-content">
    					<div class="content">
    						<?php echo wp_trim_words(apply_filters('the_excerpt', $post->post_content), $num_words = 55); ?>
    					</div>
    					<p><a href="<?php the_permalink() ?>">Read More &rsaquo;</a></p>
    				</div>
    			</div>
    		</div>
    
    	</li>
    
    	<?php endforeach; } ?>
    
    </ul>

    I need to show 2 entries in each ‘li’

    Many thanks.

    This can be easily done by creating a counter, here is the updated code:

    <h2>Recent News</h2>
    <ul class="post-carousel">
      <?php
        $posts = get_posts("showposts=10");
        if ($posts) {
          $counter=0;
          foreach ( $posts as $post) : setup_postdata($post);
            echo ($counter % 2 ==0) ? '<li>':'';?>
            <div class="entry">
              <div class="entry-date">
                <div class="entry-day"><?php the_time('d'); ?></div>
                <div class="entry-month"><?php the_time('M'); ?></div>
              </div>
    
              <div class="entry-body">
                <h4 class="entry-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
                <div class="entry-content">
                  <div class="content">
                    <?php echo wp_trim_words(apply_filters('the_excerpt', $post->post_content), $num_words = 55); ?>
                  </div>
                  <p><a href="<?php the_permalink() ?>">Read More &rsaquo;</a></p>
                </div>
              </div>
            </div>
            <?php  echo ($counter % 2 == 1) ? '</li>': '';
            $counter++;
          endforeach;
        }
        echo ($counter % 2 == 1) ? '</li>': '';
      ?>
    </ul>
    Thread Starter claudchan

    (@claudchan)

    Great!
    Thank you so much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to show two posts in each item’ is closed to new replies.