• Resolved MrCarlLister

    (@mrcarllister)


    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.

    Cheers,

    Carl

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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?

    Thread Starter MrCarlLister

    (@mrcarllister)

    Thanks,

    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

    <ul>
    
    <?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 6 , 'show_post_count' => true ) ); ?>	
    
    <?php
    	$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;
    		else
    		continue;
    }
    echo "<div class='showhidelist'>";
    	$links=(array_splice($links, 6 ));
    foreach($links as $key => $value){
       	echo "<li >{$value}\n </li>";
    }
    	echo "</div>";
    ?>
    </ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Offset Archives / target all monts after’ is closed to new replies.