PapaScott I like big blogs and I cannot lie! 🐘

How To Cook Quick Links, Bork Bork Bork!

Danger, danger, this post contains PHP code! Also note I've changed my mind a bit and put the quick links below any main posts for the day, rather than above.

Note that the qlinks are saved in a separate blog. I'm not sure if that's the best idea or not... I could have defined a category for quick links. But it's difficult to define different entry formats for categories using MT tags. I find using a separate blog easier, then including the files with quick links in the index of the main blog, so the main blog always has the newest quick links without rebuilding. However, using a separate blog makes finding the links for each day somewhat complicated.

Each day can be found in /YYYY/MM/DD/ I could just include this file in the MTDateFooter for each main post... EXCEPT that I would then miss the quick links for the days where I had no main post. So in the MTDateHeader, I need to check all the dates between the current and the previous post.

At the top of the index template (before the MTEntries tag at any rate) we need to define some variables to make it easier to calculate dates:


Since NOW is defined in seconds, we have count back DAYs in seconds as well. The $offset keeps track of which days we've already checked.

The meat of the script is in the MTDateHeader, where we check each day before the date of the current entry for quicklinks, before we output anything for the current day. For each day, we print a header and include the quick links only if a quick links file exists for that day.

  $mt_date='<$MTEntryDate format="%d %B %Y"$>';
  $ql_date=date('d F Y',NOW-$offset*DAY);
  while ($ql_date<>$mt_date) {
    if (is_readable($inc_file)) {
      echo '<h2>',$ql_date,'</h2>';
    $ql_date=date('d F Y',NOW-$offset*DAY);
<h2><$MTEntryDate format="%d %B %Y"$></h2>

Then we do all our normal entry stuff. After that, we need an MTDateFooter for the current day's quick links.

@include('<$MTEntryDate format="./%Y/%m/%d/"$>');

The @ before 'include' means there will be no warning message if the file does not exist.

I'm not particularly happy that I have up to 15 separate includes on my index page. A cleaner solution would be to put all the quick links into an RSS file, and loop through that. I'll do that in version 0.02.

Or I may even put the quick links back on the sidebar. Nothing in life is permanent.

comments powered by Disqus