WordPress.org

Ready to get started?Download WordPress

Forums

archive dropdown for each year (4 posts)

  1. onebitrocket
    Member
    Posted 1 year ago #

    Hi,

    I want to modify the archives widget.

    By default it's one dropdown containing all the months.

    I'd like to have one dropdown for each year.

    I'm really not sure how i go about this and which files to modify.

    Thanks

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    This can be done easier and without a plugin - just use the Links widget...First create a new Link category, then create the links in form: yoursite.com/year/
    An example at my site is in footer at "SOME SITES I BUILT AND HOST" (of using Links and it's widget)
    ...or just use a text widget and hard code the HTML.

    Update with new link each year.

  3. onebitrocket
    Member
    Posted 1 year ago #

    Thanks for your help, but it wasn't the solution I was looking for.
    I did find a fix though which I'm still working on.

    Eventually I want a function that will recognise if the checkbox in the archive widget has been checked and then replace the standard widget select area width the code below.

    <ul>
    <?php
    /**/
    $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date)
    FROM $wpdb->posts WHERE post_status = 'publish'
    AND post_type = 'post' ORDER BY post_date DESC");
    foreach($years as $year) :
    ?>
    
    <li>
    <label><?php echo $year; ?></label>
    
    	 <select  name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
    
            <?php $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
            FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
            AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
            foreach($months as $month) :
            ?>
    
    	<option value="<?php echo get_month_link($year, $month); ?>">
    
                <?php echo date( 'F', mktime(0, 0, 0, $month) );?>
    
                </option>
    
            <?php endforeach;?>
    	    </select>
    
    </li>
    <?php endforeach; ?>
    
    </ul>
  4. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    It may have helped if your end result was stated in the OP. What I suggested does and would work well for most without coding.

Topic Closed

This topic has been closed to new replies.

About this Topic