Forums

Syntax for multiple variables in query_posts( 'posts_per_page=-1') (5 posts)

  1. alsoran
    Member
    Posted 2 months ago #

    Hi there,

    I'm currently working on a wordpress theme based on iTunes that uses a list view for archives such as categories, tags and search results. In order to override the "Blog pages show at most" value for the archives I use the following handy code at the start of my archive.php which I found here:

    <?php get_header(); query_posts( 'posts_per_page=-1&cat=' . $cat ) ?>

    Unfortunately however, this only works for categories, with tags links etc displaying every possible post as if the code were:

    <?php get_header(); query_posts( 'posts_per_page=-1' ) ?>

    To get around this, I've created duplicates of the archive page for tag.php, search.php and so on, customising the code for each page, so for example tag.php begins:

    <?php get_header(); query_posts( 'posts_per_page=-1&tag=' . $tag ) ?>

    While this works, it's not the best solution as I have a lot of duplicate content should I wish to modify the archive layout.

    Can someone give me help please as to what the syntax would be to have only one line of code that would modify the posts_per_page value for $cat, $tag, $s, $year etc, which I can place in my archive.php only?

    I've tried variations like that below but to no avail:

    <?php get_header(); query_posts( 'posts_per_page=-1&cat&tag=' . $cat . $tag ) ?>

    Thanks in advance for any help,

    Jonathan

  2. MichaelH
    moderator
    Posted 2 months ago #

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args=array(
       'showposts' => 5,
       'category__in' => array(1,2,3),
       'paged'=>$paged
       'caller_get_posts'=> 1
       );
    query_posts($args);
  3. alsoran
    Member
    Posted 2 months ago #

    Thanks for the code, but I don't understand what to do with this.

    Can I have some instruction as to what it does and where to put it?

    Cheers,

    J

  4. MichaelH
    moderator
    Posted 2 months ago #

    Replace the query_posts statement in the template where you got the code in your original question.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    Category Templates

  5. alsoran
    Member
    Posted 2 months ago #

    Adding this in with the get_header request returns the following error:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')'

Reply

You must log in to post.

About this Topic