WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. MrCarlLister
    Member
    Posted 1 year 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.

    Cheers,

    Carl

  2. x500.net
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic