Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:40:24+00:00 2026-06-17T06:40:24+00:00

WordPress, you infuriate me sometimes! What I’ve been trying to do for the past

  • 0

WordPress, you infuriate me sometimes!

What I’ve been trying to do for the past few hours is trying to have a way that I can display the Archive’s down the sidebar with a custom date format (without changing the global options in settings), a terribly convoluted task that should really be as simple as using the_date();. I just want to make January 2013 for example, Jan 13 instead while also having one year down one column and the other in the other.

I’ve managed to do the custom date formatting alright by adapting this code: http://www.wpbeginner.com/wp-themes/how-to-customize-the-display-of-wordpress-archives-in-your-sidebar/ to this:

function sidebar_archive_list($arclistno = "24") {

    global $wpdb;

        $limit = 0;

        $year_prev = null;

        $months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");

    foreach($months as $month) :
        $year_current = $month->year;

        if ($year_current != $year_prev){
             if ($year_prev != null){ }
        }
    ?>

    <a href="<?php bloginfo('url') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>" title="<?php echo date("F Y", mktime(0, 0, 0, $month->month, 1, $month->year)); ?>"><?php echo date("M y", mktime(0,0,0,$month->month,1,$month->year)); ?></a>

<?php 

    $year_prev = $year_current;

    if(++$limit >= $arclistno) { break; }

    endforeach; 

}

That’s worked no problems.

The trouble has now come when I’ve tried to split the returned content from this function into the two separate column divs. I believe I need to make the function into an array like you can get from wp_get_archives(‘echo=0’); (and some extra code) but my PHP skills aren’t superb and I can’t quite figure out how to go about recreating the same kind of thing. I think it should look something like:

array(3) { [0]=> string(86) "January 2013"
           [1]=> string(90) "September 2012"
           [2]=> string(82) "March 2012"
}

When var_dumped. Also it’s worth bearing in mind for whatever reason the anchor links also surround the dates, but echo, rather than print out.

The code I’m using for the content split is:

<?php

    $links = print(sidebar_archive_list());
    $archive_n = count($links);
        for ($i=0;$i<$archive_n;$i++):
            if ($i<$archive_n/2):
                $archive_left = $archive_left.'<li>'.$links[$i].'</li>';
            elseif ($i>=$archive_n/2):
                $archive_right = $archive_right.'<li>'.$links[$i].'</li>';
    endif;
        endfor;

?>                  

<div class="group">
    <ul class="sb_double_column_list alignleft">
        <?php echo $archive_left;?>
 </ul>

 <ul class="sb_double_column_list alignright">
        <?php echo $archive_right;?>
 </ul>
</div>

Any help or advice would be wholeheartedly appreciated. I’m in a real rut with this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:40:26+00:00Added an answer on June 17, 2026 at 6:40 am

    Okay after messing around a bit I managed to modify wp_get_archives into my own custom function which allowed me to pass it through the column creating code in a similar manner to how I did when trying to use wp_get_archives on its own.

    The code is as follows.

    function sidebar_archive_list($args = '') { 
    
    global $wpdb, $wp_locale; 
    
    $defaults = array(
        'limit' => '24',
        'format' => 'html', 'before' => '',
        'after' => '', 'show_post_count' => false,
        'echo' => 0, 'order' => 'DESC',
    ); 
    
    $r = wp_parse_args( $args, $defaults ); 
    extract( $r, EXTR_SKIP );
    
    
    if ( '' != $limit ) {
        $limit = absint($limit);
        $limit = ' LIMIT '.$limit;
    }
    
    $order = strtoupper( $order );
    if ( $order !== 'ASC' ) 
        $order = 'DESC'; 
    
    
    //filters
    $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); 
    
    $join = apply_filters( 'getarchives_join', '', $r );
    
    $output = '';
    
        $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
    
        $key = md5($query);
    
        $cache = wp_cache_get( 'wp_get_archives' , 'general');
    
        if ( !isset( $cache[ $key ] ) ) { 
            $arcresults = $wpdb->get_results($query); 
            $cache[ $key ] = $arcresults;
            wp_cache_set( 'wp_get_archives', $cache, 'general' );
        } else {
            $arcresults = $cache[ $key ];
        }
    
    
        if ( $arcresults ) { 
            $afterafter = $after; 
    
            foreach ( (array) $arcresults as $arcresult ) { 
    
                $url = get_month_link( $arcresult->year, $arcresult->month ); 
    
                $year = date("y", strtotime($arcresult->year));
    
                $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month_abbrev($wp_locale->get_month($arcresult->month)), $year); 
    
                if ( $show_post_count ) 
                    $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
                $output .= get_archives_link($url, $text, $format, $before, $after);
            }
        }
    
    if ( $echo ) // If "echo" has been defined as having a value (e.g: 1) then echo $output, if it has no value (0) then return the value.
        echo $output;
    else
        return $output;
    }
    

    Just drop it into the functions.php and then use the sidebar_archive_list(). Please note that the function only supports the monthly display and I’ve altered the defaults slightly from wp_get_archives. So it will return the array rather than echoing it and the default limit is 24 (12 months down one column and vice versa).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WordPress has been installed as a blog into osCommerce. I'm trying to get the
Wordpress has a filter that automatically add paragraphs to posts. I can remove this
Wordpress 3.0 just came out and it was cited that one can make a
Wordpress / PHP related question. I have a Wordpress plugin that uses dirname(__File__) to
In wordpress I have developed a website. In that I have two sidebars. In
Has Wordpress a function or something like that?I need a way to check if
My wordpress 3.4.2 site have 25 activated plugin, so Which is safest way to
WordPress RSS feed not work when custom filed have '&'. i think that may
WordPress has this thing that examines whether it has been set up (installed) on
My wordpress site has been hacked. Through this program: http://sitecheck.sucuri.net/ (...) i found that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.