You could use the wp_get_archives() function to output a list of monthly archives. Otherwise, I think you’re looking at writing a custom page navigation function.
To be honest, I’m kind of surprised. Wouldn’t this type of functionality be desirable/default?
Does anyone know of a plug-in that can do this?
Hi.
I did something like this for a blog on the home page.
This is not the best solution but could work.
The problem is the number of pages on the site.
I’m working on this issue but if somebody can help.
🙂
This is the code that goes on index.php (on template directory) before the content id
<?php
if (is_home()) {
$temp_query = $wp_query;
$actPage = $_GET["paged"];
if ($actPage == "" || $actPage == "1") $actPage = 1;
$current_month = date('m');
$current_year = date('Y');
$toShow = $current_month - ($actPage - 1);
if (!$toShow) {
$toShow = 12;
$current_year--;
}
$strQuery = "&year=$current_year&monthnum=$toShow&posts_per_page=-1";
$strQuery = "&year=$current_year&monthnum=$toShow";
query_posts($strQuery);
}
?>
and after the endwhile:
<?php $wp_query = $temp_query; ?>
The problem is the number of pages.
After some pages this could start to show pages not found.
Thanks for help.
Byron H.
Hi Byron,
Thanks for the advice – I tried it out. I inserted the first code bit before:
<h1 id="post-<?php the_ID(); ?>">
and pasted the second bit after the endwhile, as instructed.
This is on my archive.php page, as it’s for the archive postings that I want this functionality.
However, this results in an emptied sidebar, with the following error in it:
Fatal error: Call to a member function on a non-object in /wp-includes/query.php on line 10
Please note the sidebar code is not in archive.php at all, so I’m not sure what’s happening here. Any help is appreciated.