[resolved] Offset Archives / target all monts after (3 posts)

  1. MrCarlLister
    Posted 3 years ago #

    I'm using wp_get_archives to display the last 6 months ('limit' => 6). I've been tasked to update this code to allow for a jquery 'reveal' of the rest of the months beneath.

    Initially I figured I'd have 2x wp_get_archives 1 as above, and then one showing all months with an offset of 6 months.

    I have since realised this isn't possible, at least not from the outset/what I can see.

    Is there anyway to do this? Preferably without plugins although I'm open to that as a last resort.



  2. x500.net
    Posted 3 years ago #

    Maybe you don't need to set the limit for the query and just hide part of the list with jQuery?
    Alternatively, you can keep what you have there and run second query for archives, remove elements from the array with array_splice and append the result to <ul> element using jQuery?

  3. MrCarlLister
    Posted 3 years ago #


    That helped! I managed to get there in the end after I realised that wp_get_archives doesn't return a format-less array.

    Here's the final code for those who may need it in the future!

    Thanks again x500.net

    <?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 6 , 'show_post_count' => true ) ); ?>	
    	$archi = wp_get_archives( 'echo=0' );
    	$archi = explode( '</li>' , $archi );
    	$links = array();
    foreach( $archi as $link ) {
    	$link = str_replace( array( '<li>' , "\n" , "\t" , "\s" ), '' , $link );
    		if( '' != $link )
    			$links[] = $link;
    echo "<div class='showhidelist'>";
    	$links=(array_splice($links, 6 ));
    foreach($links as $key => $value){
       	echo "<li >{$value}\n </li>";
    	echo "</div>";

Topic Closed

This topic has been closed to new replies.

About this Topic