• Resolved mkjar

    (@mkjar)


    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">
    </select>
    <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;
    
        });
    </script>

    Any insights would be appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mkjar

    (@mkjar)

    I figured how to use buttons:

    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        var str = $(this).text();
    	window.location.href = "<?php echo site_url(); ?>/<?php echo $archivetax ?>/<?php echo $archivetype ?>/?a="+str;
    	$(this).addClass("highlight");
      });
    });
    </script>
    <style type="text/css">
    button{background-color:#eee;border-width:0;}
    button:hover{background-color:#ccc;}
    button.highlight{font-weight:bold;}
    </style>
    View per page:
    <button >20</button>
    <button >50</button>
    <button >all</button>
    <?php
    $args = array(
    	'cat' =>  $catid,
    	'posts_per_page' => $amtper
    );
    query_posts( $args );
    ?>

    Thread Starter mkjar

    (@mkjar)

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Select archive post per page amt with dropdown 10 | 20 | view all’ is closed to new replies.