WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to call older posts using Global $post.?? (4 posts)

  1. hikzik
    Member
    Posted 2 years ago #

    Hey there.
    I'm new to wordpress, but have been trying to learn quickly to implement my own theme design to work with it.
    Have hit a little snag...and was hoping to get it done quickly.
    I am using a two column theme and have used the following query to get the code and then distribute the posts between the two columns and it works beautifully.
    The Code:
    global $post; $myposts = get_posts('numberposts=10');

    But the thing is with this code it only calls the first 10 posts and when I click on Older posts I get the same Page.

    any suggestions how to get by this.??

  2. davidsword
    Member
    Posted 2 years ago #

    the next pages query needs an offset of 10

    first page:

    $myposts = get_posts('numberposts=10');

    older posts page:

    $my_older_posts = get_posts('offset=10');

    and you're saying you 'get the same page' does the URL change (ie: ../page/2/) or is the URL staying the same?

  3. hikzik
    Member
    Posted 2 years ago #

    sorry my bad...
    I am getting the changed url (ie: ../page/2/) as you mentioned, but my code displays the same posts.

    $my_older_posts = get_posts('offset=10');

    How should i be coding this such that WordPress understands its older pages.?
    i.e How to differentiate between First page and older pages.?
    am still a noob when it comes to wordpress.
    Thanks a lot in advance and really appreciate your help.

  4. hikzik
    Member
    Posted 2 years ago #

    @davidsword -- Thanx a lot...But i found it out.
    This code worked great for me.!

    <?php
        $ppp = get_option('posts_per_page');
    	if (!is_paged()) {
    		$custom_offset = 0;
    	} else
            {
    	    $custom_offset = $ppp*($paged-1);
    	}
    	$args = array(
    	'numberposts' => $ppp,
    	'offset' => $custom_offset,
    	);
        global $post; $myposts = get_posts($args);
    ?>

    For the full explanantion its down here at this link:http://blog.ashfame.com/2011/04/pagination-approach-get-posts-wordpress/

Topic Closed

This topic has been closed to new replies.

About this Topic