[resolved] Select archive post per page amt with dropdown 10 | 20 | view all (3 posts)

  1. mkjar
    Posted 4 years ago #

    I am interested in being able to let the reader of my blog change the amount of posts on an archive page.

    For example: above the list of archived posts there would be this menu:
    10 per page | 50 per page | view all

    I have been playing around with it today - and have made it work for my categories archives (I am eventually going to add in the other archive options - but I wanted to work it out first) :

    Here is the code: At pastebin
    (the template tag for archive.php is commented out at the bottom)

    I have two questions - Is this a smart way to do this? Is there an easier way?

    And also how would I make the options look like links (not a drop down?) I have been playing with changing them to form buttons but I think the jquery input values are a bit above my current skills.

    My latest attempt :

    <form  id="amt-per" action="">
    <input type="submit" value="20">
    <input type="submit" value="50" >
    <input type="submit" value="all">
    <script type="text/javascript">
        $("button").click(function () {
          var str = $(this).text();
    	  window.location.href = "<?php echo site_url(); ?>/<?php echo $taxy ?>/<?php echo $archivetype ?>/?a="+str;

    Any insights would be appreciated!

  2. mkjar
    Posted 4 years ago #

    I figured how to use buttons:

    <script type="text/javascript">
        var str = $(this).text();
    	window.location.href = "<?php echo site_url(); ?>/<?php echo $archivetax ?>/<?php echo $archivetype ?>/?a="+str;
    <style type="text/css">
    View per page:
    <button >20</button>
    <button >50</button>
    <button >all</button>
    $args = array(
    	'cat' =>  $catid,
    	'posts_per_page' => $amtper
    query_posts( $args );
  3. mkjar
    Posted 4 years ago #

    Just in case anyone is searching for an answer to this - I have gotten most of it to work here:at pastebin

    I realized in my original tries I was trying to reset the whole url using values of the query - when I only needed to add to the url (silly on my part)- now the function is far simpler to read.

    Also the code I have in the pastebin allows you change posts_per_page and orderby without resetting the earlier variable value. meaning you can sortby date and then view 'all posts', and then sort by 'modified date' and the posts will still be view all amount (not reset back to the default 10). My next move is add order direction.

    AND hopefully get the highlight class to work. it applies the class - but then the class gets removed when the query is refreshed.

Topic Closed

This topic has been closed to new replies.

About this Topic