Join 3,561 readers in helping fund MetaFilter (Hide)


Showing all posts from a given day, in list form.
December 1, 2010 11:59 AM   Subscribe

PHP/AJAX gurus: Please help me figure something out. Want to display all Wordpress posts from a single day, but want it to be as sexy and intuitive as possible.

So I've got a feature I want to add to one of my Wordpress blogs, and I'm not sure if it's simple, or if it's going to require hiring a coder.

I want visitors to be able to select a month/day/year (from three separate drop-downs), hit "select," and the area below that will show a list of all the posts published that day. Not the posts themselves, just a list of them. I'm guessing AJAX would be the way to make that sexy, but I would also be OK with having the site load a new page with the results.

How would I go about doing this? I'm going this route as an alternative to the clickable sidebar calendar, which is just hideous and takes a long time to load if there are a lot of posts.
posted by jbickers to Computers & Internet (3 answers total)
 
Before I invest time in writing some code: why would visitors be curious about posts from a certain day? What would trigger them to order the content of said blog chronologically?

On my boeklog I have tried to present the archives in as many ways as possible, since reviews don't age. However, no-one of its visitors uses the date of original publication to find anything.
posted by ijsbrand at 12:27 PM on December 1, 2010


We use blog posts to let listeners to our public radio station know when songs were played - each blog post is the name of an artist/song, posted by the DJ at the moment the song is started. So, someone who wants to know what that song was they heard yesterday morning in the car at a certain time would go to the site and go to that day. (It would also be helpful, from a reporting standpoint, to be able to easily print out an entire day's posts.)
posted by jbickers at 12:40 PM on December 1, 2010


Viewing a list of posts for a certain date is easy. You'd make a copy of your theme's archive.php template that you'll use specifically for day views. Call it date.php (this is a special template name so that Wordpress knows to use it for date-based archives; it will know to use it based on the format of the URL of the page you're calling.

Near the top of the template, you'll probably see a chunk that looks like this: <?php /* If this is a category archive */ if (is_category()) { ?>
<h1>Archive for the <?php single_cat_title(); ?> Category</h1>
<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<h1>Posts Tagged <?php single_tag_title(); ?></h1>
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h1>Archive for <?php the_time('F jS, Y'); ?></h1>
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<h1>Archive for <?php the_time('F, Y'); ?></h1>
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<h1>Archive for <?php the_time('Y'); ?></h1>
<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<h1>Author Archive</h1>
<?php /* If this is a paged archive */ }


You can go ahead and delete the bits about category, tag, and author archives.

Then you'll want to set a flag on the "is this a daily archive", so you'll replace the relevant two lines above with the following three:
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h1>Archive for <?php the_time('F jS, Y'); ?></h1>
<?php $isdaily = true; ?>


Then scan down in your template to <?php the_content() ?>
And replace that with <?php if(!$isdaily){the_content()} ?>
This checks whether $isdaily is true, and only emits the full content of the post if false. It's possible your template shows excerpts instead of full content—same idea.

Setting up the menu for navigating to a certain day will take a little more work, and AJAX is outside my expertise, but it can be done. Doing it right, so that (for example) you only show 28 days for February, except in leap years, will take a little more doing. I'm pretty sure there are jquery date navigators out there that would do the job for you; you might need to modify it a little to get it to return a value with the date formatted in your URL format with your URL prepended to it.
posted by adamrice at 1:13 PM on December 1, 2010


« Older Gift ideas for my manly man hu...   |  Do you have a whirlpool/jacuzz... Newer »
This thread is closed to new comments.