WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Limit number of post on archive page

[Resolved] Limit number of post on archive page

Viewing 15 replies - 1 through 15 (of 19 total)
  • Jay
    Member

    @fectio1

    I just tried using this same query on another page and it seems to work fine. Not sure why it will not work on the archive.php file..

    here is the error unexpected $end on line 56

    Thanks in advance.

    Jay
    Member

    @fectio1

    Okay,

    I tried changing this

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("posts_per_page=1&paged=".$paged);
    
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    to this

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($paged . "&posts_per_page=1&paged=' .$paged);
    ?>

    but now I’m getting an T_endwhile error.

    keesiemeijer
    moderator

    @keesiemeijer

    is the code in the pastebin the full code of the template file?

    Jay
    Member

    @fectio1

    keesiemeijer
    moderator

    @keesiemeijer

    Try it with this: http://pastebin.com/1TS5Wt31

    Jay
    Member

    @fectio1

    That definitely fixed the error message. Thank you, but now I’m getting a 404 when I select the next link. It appears the pagination is not working properly.

    Its always something. 🙂

    keesiemeijer
    moderator

    @keesiemeijer

    Try it with this: http://pastebin.com/XpSc0JV6

    keesiemeijer
    moderator

    @keesiemeijer

    Sorry, that one contains an error. Try it with this one: http://pastebin.com/56UDXh4B

    Jay
    Member

    @fectio1

    Thanks again, but that took the page navigation away and showed all the post instead of the 1. I even removed the reset since the global was in there and still no luck..

    keesiemeijer
    moderator

    @keesiemeijer

    Use the last pastebin (one above your last post).

    Jay
    Member

    @fectio1

    Well that one brought back the page nav, but still getting the 404 error.

    Jay
    Member

    @fectio1

    Maybe it has something to do with the structure. So here it is.

    -> parent category

    –> children category

    All of the children are displayed on a certain page. You select the category which then displays all the post within that category. This is where I want to limit the number displayed. Hopefully that gives a better picture.

    url for page that displays childern

    localhost/?page_id=5

    url for category selected

    localhost/?cat=4

    url for next post link which I get the 404 error

    localhost/?cat=4&paged=2

    keesiemeijer
    moderator

    @keesiemeijer

    I have the same 404 error on my testsite. Pagination on archive pages is always difficult (don’t know why). I will test further.

    Jay
    Member

    @fectio1

    Thanks a lot for your help, I really appreciate it.

    keesiemeijer
    moderator

    @keesiemeijer

    Try it without a query on the loop with this: http://pastebin.com/M2jdLS1X

    and put this in your theme’s functions.php

    function my_archive_per_page( &$q ) {
      if ( !is_admin() && $q->is_archive ){
        if ( isset( $q->query_vars['category_name']) ) {
          $catslug = get_category_by_slug($q->query_vars['category_name']);
          // change 3 to the parent category of the child categories you only want 1 post per page
          if(cat_is_ancestor_of(3, $catslug->term_id)){
            $q->set( 'posts_per_page', 1 );
          }
        }
      }
      return $q;
    }

    Change “3” to the parent category ID of the child categories.

    I couldn’t get it to work with a normal post query.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Resolved] Limit number of post on archive page’ is closed to new replies.