0

I'm currently working on an intranet site for a big company and based on the project description, there will be a lot of articles posted everyday so this website will need various archive pages with different queries for users to quickly find articles based on their chosen criteria. I sorted out all of them (thanks to StackExchange!!) but I can't figure out how to create something like below:

enter image description here

I want a set number of lines (10 on each sides) each containing the date where posts were published ordered by date. I know how to query posts by date, but to use that it will mean that I will need to update this list everyday manually which is impractical.

Is there a way to dynamically create this list (relative to "today's" date)?

Thank you in advance for your time on this!

0

Please note that I have now resolved this issue. For whomever is interested, please find my code below (I've included everything to a shortcode to facilitate adding it anywhere I want):

function archiveday() {
$x=1;
    do {

$result = date('l jS F Y',strtotime("-$x days")); 
$year= date('Y',strtotime("-$x days"));
$month= date('n',strtotime("-$x days"));
$day= date('j',strtotime("-$x days"));
$my_query2 = get_posts("post_status=publish&post_type=post&year=$year&monthnum=$month&day=$day");

        if ($my_query2){
            echo '<a href="http://EXAMPLE.COM/'.$year.'/'.$month.'/'.$day.'/">'.$result.'</a> ('. count($my_query2).') <br>'; }
        else {
            echo $result .' ('. count($my_query2).') <br>';}
    $x++;}
    while ($x<=10);

        wp_reset_postdata();
}
add_shortcode('archive', 'archiveday');

This now outputs the below:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.