• I’ve been searching around for ways to trick out the query and get_archives functions to manipulate post outputs and I have been having a hard time finding an elegant solution to do the following, generate links for each day of the most recent week. So I want links that say Monday / Tuesday / Wednesday / Thursday and have each sort all posts by the most recent post from that day of the week.

    Anyone come across a solution or know how I could best implement?

Viewing 1 replies (of 1 total)
  • Thread Starter benfranklin

    (@benfranklin)

    Okay, I coded a solution myself … never say I don’t contribute to the great WP community!

    Below is the result … it takes any day of the week you’re on and creates links that allow you look back at the previous posts for previous days that week!

    It also auto highlights the days you’re currently on.

    If you have something more elegant than this, let us all know.

    <style type="text/css" >
    .cday {
    	border: 1px solid black;
    }
    
    </style>
    
    <?php
    $day=Date("l");
    $year1=Date("Y");
    $month1=Date("m");
    if ($day=="Monday") { $day1=Date("d"); $day2=Date("d") - 6; $day3=Date("d") - 5; $day4=Date("d") - 4; $day5=Date("d") - 3; $day6=Date("d") - 2; $day7=Date("d") - 1;  }
    elseif ($day=="Tuesday") { $day1=Date("d") - 1; $day2=Date("d"); $day3=Date("d") - 6; $day4=Date("d") - 5; $day5=Date("d") - 4; $day6=Date("d") - 3; $day7=Date("d") - 2;  }
    elseif ($day=="Wednesday") { $day1=Date("d") - 2; $day2=Date("d") - 1; $day3=Date("d"); $day4=Date("d") - 6; $day5=Date("d") - 5; $day6=Date("d") - 4; $day7=Date("d") - 3;  }
    elseif ($day=="Thursday") { $day1=Date("d") - 3; $day2=Date("d") - 2; $day3=Date("d") - 1; $day4=Date("d"); $day5=Date("d") - 6; $day6=Date("d") - 5; $day7=Date("d") - 4;  }
    elseif ($day=="Friday") { $day1=Date("d") - 4; $day2=Date("d") - 3; $day3=Date("d") - 2; $day4=Date("d") - 1; $day5=Date("d"); $day6=Date("d") - 6; $day7=Date("d") - 5;  }
    elseif ($day=="Saturday") { $day1=Date("d") - 5; $day2=Date("d") - 4; $day3=Date("d") - 3; $day4=Date("d") - 2; $day5=Date("d") - 1; $day6=Date("d"); $day7=Date("d") - 6;  }
    elseif ($day=="Sunday") { $day1=Date("d") - 6; $day2=Date("d") - 5; $day3=Date("d") - 4; $day4=Date("d") - 3; $day5=Date("d") - 2; $day6=Date("d") - 1; $day7=Date("d");  }
    ?>
    
    <a <?php if ($day=="Monday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day1"; ?>">Monday</a>
    <a <?php if ($day=="Tuesday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day2"; ?>">Tuesday</a>
    <a <?php if ($day=="Wednesday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day3"; ?>">Wednesday</a>
    <a <?php if ($day=="Thursday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day4"; ?>">Thursday</a>
    <a <?php if ($day=="Friday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day5"; ?>">Friday</a>
    <a <?php if ($day=="Saturday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day6"; ?>">Saturday</a>
    <a <?php if ($day=="Sunday") { ?> class="cday" <? } ?> href="?m=<? echo "$year1" . "$month1" . "0$day7"; ?>">Sunday</a>
Viewing 1 replies (of 1 total)
  • The topic ‘Sort posts by day of week — link for Monday, Tuesday, Wednesday … etc.’ is closed to new replies.