Viewing 9 replies - 1 through 9 (of 9 total)
  • What code are you using?

    Total guess without seeing it, but are you passing the paged argument to the query?

    Thread Starter jeniharding

    (@jeniharding)

    Thanks for answering!

    Here is the code:

    <?php
    /*
    Template Name: news
    MultiEdit: One centered column with no sidebar
    */

    get_header(); ?>

    <div id=”content”>
    <div class=”contentTop2 newspad”>

    <div id=”newsTitle”>/news/”>Latest News</div>

    <?php
    $args = array( ‘numberposts’ => 1, ‘post_status’=>”publish”,’post_type’=>”post”,’orderby’=>”post_date”);
    $postslist = get_posts( $args );

    foreach ($postslist as $post) : setup_postdata($post); ?>
    <div class=”postNews”>

    <?php if ( has_post_thumbnail() ) { /* loads the post’s featured thumbnail, requires WordPress 3.0+ */
    echo ‘<div class=”featured-thumbnail”>’; the_post_thumbnail(); echo ‘</div>’;
    } ?>

    <div class=”newsRightPost”>

    <div class=”newsTitle”>” title=”<?php the_title(); ?>”><?php the_title(); ?></div>
    <div class=”newsDate”>Posted <?php the_date(); ?></div>
    <div class=”newsExcerpt”><?php the_excerpt(); ?></div>

    <div class=”sharetext”>Share This:  </div>
    <div class=”tweetButton”>Tweet
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=”//platform.twitter.com/widgets.js”;fjs.parentNode.insertBefore(js,fjs);}}(document,”script”,”twitter-wjs”);</script></div>

    <div class=”fbButton”><iframe src=”//www.facebook.com/plugins/like.php?href=http%3A%2F%2Flemondropdrama.co.uk%2F&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=35&appId=159796134099543″ scrolling=”no” frameborder=”0″ style=”border:none; overflow:hidden; width:450px; height:35px;” allowTransparency=”true”></iframe></div>
    </div>

    </div>
    <?php endforeach; ?>

    <div class=”clearBoth”> </div>
    </div>

    <?php

    global $post;
    $myposts = get_posts(‘numberposts=10&offset=1&category=’);
    foreach($myposts as $post) :
    setup_postdata($post);

    ?>

    <div class=”postNews2″>
    <?php if ( has_post_thumbnail() ) { /* loads the post’s featured thumbnail, requires WordPress 3.0+ */
    echo ‘<div class=”featured-thumbnail”>’; the_post_thumbnail(); echo ‘</div>’;
    } ?>

    <div class=”newsRightPost”>

    <div class=”newsTitle”>” title=”<?php the_title(); ?>”><?php the_title(); ?></div>
    <div class=”newsDate”>Posted <?php the_date(); ?></div>
    <div class=”newsExcerpt”><?php the_excerpt(); ?></div>

    <div class=”sharetext”>Share This:  </div>
    <div class=”tweetButton”>Tweet
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=”//platform.twitter.com/widgets.js”;fjs.parentNode.insertBefore(js,fjs);}}(document,”script”,”twitter-wjs”);</script></div>

    <div class=”fbButton”><iframe src=”//www.facebook.com/plugins/like.php?href=http%3A%2F%2Flemondropdrama.co.uk%2F&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=35&appId=159796134099543″ scrolling=”no” frameborder=”0″ style=”border:none; overflow:hidden; width:450px; height:35px;” allowTransparency=”true”></iframe></div>
    </div>

    </div>

    <?php endforeach; ?>
    <?php query_posts( ‘posts_per_page=1’ ); ?>
    <div class=”oldernewer”>
    <p class=”older”><?php next_posts_link(‘« Older Entries’) ?></p>
    <p class=”newer”><?php previous_posts_link(‘Newer Entries »’) ?></p>
    </div><!–.oldernewer–>

    <?php // end of content bottom ?>
    <div class=”roundededge”> </div>
    <div class=”clearBoth”> </div>
    </div><!–#content–>

    <?php get_footer(); ?>

    $args = array( ‘numberposts’ => 1, ‘post_status’=>”publish”,’post_type’=>”post”,’posts_per_page’=>1,’orderby’=>”post_date”,’paged’ => get_query_var(‘paged’));

    Can you please (as per forum rules) put the code in to a Pastebin? It makes it difficult to read posts if you place big chucks of code in them.

    That said, you code looks a little off. For next_posts_link() and previous_posts_link() to work, you need to have run query_posts, not get_posts(). Basically, WP doesn’t know what posts to look at for next/previous, becuase there is nothing in the $wp_query global for it to check.

    Have a read of these and it should set you on the right path –

    And yes to adding 'paged' => get_query_var('paged');.

    I take it also that you only expect 1 more post to be displayed when you click on ‘Older’/’Newer’? Usueally this scenario is used for an Index page, where multiple Posts are listed.

    Thread Starter jeniharding

    (@jeniharding)

    Thanks both,
    Pasted in what you said nitin_8 but came up with Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/lemondropdrama/wp-content/themes/lemondropdrama/news.php on line 19

    Sorry duck_boy didn’t realise about the code rule.
    I was just changing the post number to see if the pagination worked as there is only 3 news items at the moment but there will be 4/5 per page.

    Here is the pastebin link https://pastebin.com/3H4rPACL

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this: https://pastebin.com/unHjw8uh

    This is untested so backup your file first.

    Thread Starter jeniharding

    (@jeniharding)

    Hi keesiemeijer,

    Thanks for that, the links have now gone though?

    https://spaceandtime.dyndns.org:2/lemondropdrama/news/

    Thread Starter jeniharding

    (@jeniharding)

    Oh sorry kees. I think it is fixed, I didn’t think to change the posts per page.

    Thanks so much!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Paginating News Posts, not paging correctly?’ is closed to new replies.