• Resolved nivosh

    (@nivosh)


    Hi.

    I fetched the latest post from category and I want to also display 3 more latest posts from that category underneath the main one (news style) .

    I have duplicated the “<?php while (have_posts()) : the_post(); ?>”
    but it displays also the main post that I already fetched.

    I know there is a way to display main post from category and then a list of latest from that category but without the first one.

    here is the code I used (i am not a programmer, just used common sense, But I feel it’s not the best solution for this)

    <?php $display_categories = array(188,189,190,191); $i = 1; // החלף את מספרי הקטגוריות
    	foreach ($display_categories as $category) { ?>
    	<div class="headerone">
    		<?php query_posts("showposts=1&cat=$category")?>
    		<h4><span><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span></h4>
    		<a href="<?php echo get_category_link($category);?>"><?php echo category_description($category); ?></a>
    <?php while (have_posts()) : the_post(); ?>
    	<div class="clearfloat" style="margin-bottom:10px;">
          <a href="<?php the_permalink() ?>" rel="bookmark" title="קישור קבוע אל <?php the_title(); ?>">
    	<?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
    	<div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
    <div class="excerpt">
    <?php
      $excerpt = get_the_excerpt();
      echo string_limit_words($excerpt,10);
    ?>
    </div>
    </div>
        	</div>
          <?php endwhile; ?>
    
    <?php query_posts("showposts=3&cat=$category")?>
    	<?php while (have_posts()) : the_post(); ?>
    	<div class="clearfloat">
          <a href="<?php the_permalink() ?>" rel="bookmark" title="קישור קבוע אל <?php the_title(); ?>"></a>
    	<div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
    
    </div>
        	</div>
          <?php endwhile; ?>
    	</div>
    	<?php $i++; ?>
        	<?php } ?>
    	</div>
    	<?php } ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • change this line <?php query_posts("showposts=3&cat=$category")?>
    with <?php query_posts("showposts=3&cat=$category&offset=1")?>

    Thread Starter nivosh

    (@nivosh)

    nobody can help?

    you change the line?

    Thread Starter nivosh

    (@nivosh)

    Oh thank you, didn’t see your response.

    I read somewhere that it’s not advisable to use more then one ” <?php query_posts”> in the same page.

    Do you know if it’s true?

    yes. you can use more than one.

    Thread Starter nivosh

    (@nivosh)

    What about using this instead of query_post:

    <ul>
     <?php
     global $post;
     $myposts = get_posts('numberposts=5&offset=1&category=');
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>

    Isn’t it more efficient?

    yes, you can also use the above function. If you use 2 query_post() functions in one page thats not creating a problem.

    Thread Starter nivosh

    (@nivosh)

    thanks.
    RESOLVED

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Can I start from second post?’ is closed to new replies.