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

    (@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.

    Thread Starter Jay

    (@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.

    Moderator keesiemeijer

    (@keesiemeijer)

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

    Thread Starter Jay

    (@fectio1)

    Moderator keesiemeijer

    (@keesiemeijer)

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

    Thread Starter Jay

    (@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. πŸ™‚

    Moderator keesiemeijer

    (@keesiemeijer)

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

    Moderator keesiemeijer

    (@keesiemeijer)

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

    Thread Starter Jay

    (@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..

    Moderator keesiemeijer

    (@keesiemeijer)

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

    Thread Starter Jay

    (@fectio1)

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

    Thread Starter Jay

    (@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

    Moderator keesiemeijer

    (@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.

    Thread Starter Jay

    (@fectio1)

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

    Moderator keesiemeijer

    (@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 ‘Limit number of post on archive page’ is closed to new replies.