WordPress.org

Ready to get started?Download WordPress

Forums

DIsplaying 2 featured posts then 3 excerpts with pagination (4 posts)

  1. thinkluke
    Member
    Posted 3 years ago #

    Hi,

    I am new to wordpress, if anyone could help me it would be hugely appreciated. Here is my problem:

    I have query posts on a Page. What it currently does it get 2 post and displays there content it then gets 3 post offset by 2 and displays the excerpt. When I go to the older posts Page 2 the page displays the same layout as the Page 1. What I would like to happen is that any older posts only display the excerpts, so when you are on page 2 -> 5 posts are displayed using the excerpt only. Similar to this website: http://www.thinkfa.com/exposure/ .

    Here is my code:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Using this function:

    <?php
    function my_post_limit($limit) {
    	global $paged, $myOffset;
    	if (empty($paged)) {
    			$paged = 1;
    	}
    	$postperpage = 3;
    	$pgstrt = ((intval($paged) -1) * $postperpage)+$myOffset . ', ';
    	$limit = 'LIMIT '.$pgstrt.$postperpage;
    	return $limit;
    } //end function post_limit
    ?>

    Any help would be awesome.

  2. vtxyzzy
    Member
    Posted 3 years ago #

    Try changing your code for the first loop to this:

    <?php global $more;?>
    <?php add_filter('post_limits', 'my_post_limit'); ?>
    
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if ($paged < 2) : ?>
    
    <?php
    	$featured = new WP_Query();
    	$featured->query('posts_per_page=2');
    	while($featured->have_posts()) : $featured->the_post();
    ?>
    ======== Leave the rest of your while loop here =========
    <?php endwhile; ?>
    <?php endif; ?>
  3. thinkluke
    Member
    Posted 3 years ago #

    Hi vtxyzzy, thanks for your response, I have tried what you said above but i couldn't get it to work. I think the code i was using is no good. I have new code which is easier for me to understand I just cant find a place to put the 'if' statement see below for new code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I am thinking something like this: like if not page 1 do this, if page 1 do something else, but also calculate posts for paging... it seems so simple! I wish i was better at this.

  4. thinkluke
    Member
    Posted 3 years ago #

    <?php
    // Amount of posts in the first query
    $qry[1] = 2;
    // Amount of posts in the second query
    $qry[2] = 3;
    // Total posts per page (sum of the 3 above values)
    $qry['total'] = array_sum($qry);
    // If paged is set then set the paged variable to that value, else it's 1 (the first page)
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $onum = ($qry['total'] * ($paged - 1)); // $paged is a mutliplier
    // If paged is more then 1 then set to the total of posts to show this page, else it's page one, so no offset
    $offset = ($paged > 1) ? ($onum) : 0;
    query_posts("posts_per_page=$qry[total]&paged=$paged&showposts=$qry[1]&offset=$offset");
    if (have_posts()) :
    	while (have_posts()) : the_post();?>
    
    <div class="post">
    <div class="date">
    <span class="day"><?php the_time('j') ?></span>
    <span class="month"><?php the_time('M') ?></span>
    <span class="year"><?php the_time('Y') ?></span>
    </div>
    <h2 class="blog-title"><a href="<?php the_permalink(); ?>"title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <div class="clear"></div>
    
    <?php $more = 0;the_content(''); ?>
    
    <div class="post-btm">
    <a href="<?php the_permalink(); ?>"title="<?php the_title(); ?>" class="blog-more">Read more</a>
    <div class="post-cat"><span>Category:</span> <?php the_category(', '); ?></div>
    </div>
    <div class="clear"></div>
    </div>
    
    	<?php endwhile; endif;
    // Reuse the offset variable (rather then creating a new one), setting to a new value (plus any additional offset)
    // Total in first query, plus any offset, if there is one
    $offset = $qry[1] + (($paged > 1) ? $onum : 0);
    query_posts("posts_per_page=$qry[total]&offset=$offset&showposts=$qry[2]");
    if (have_posts()) :
    	while (have_posts()) : the_post(); ?>
    
            <div class="post">
    
    <div class="date">
    <span class="day"><?php the_time('j') ?></span>
    <span class="month"><?php the_time('M') ?></span>
    <span class="year"><?php the_time('Y') ?></span>
    </div>
    <h2 class="blog-title"><a href="<?php the_permalink(); ?>"title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <div class="clear"></div>
    
    <?php the_excerpt(); ?>
    
    <div class="post-btm">
    <a href="<?php the_permalink(); ?>"title="<?php the_title(); ?>" class="blog-more">Read more</a>
    <div class="post-cat"><span>Category:</span> <?php the_category(', '); ?></div>
    </div>
    <div class="clear"></div>
    </div>
    	<?php endwhile; ?>
    
        <div id="navigation">
    <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    </div><!-- End navigation -->
    
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic