mfwpt/archive.php

122 lines
2.7 KiB
PHP
Raw Permalink Normal View History

<?php
// MFWPT - archive.php
// function arl_kottke_archives GPL2.0, attribution below
?>
<?php
get_header();
if ( have_posts() ) while ( have_posts() ) : the_post();
?>
<secion class="archives">
<?php
// if it is the month or category link
if (is_month() || is_category()) {
?>
<h1 class="archive-search-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?></a></h1>
<div class="archive-excerpt"><?php the_excerpt(); ?></div>
<?php
// else it should be the original text
} else {
?>
<h1 class="archive-post-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?></a></h1>
<div class="archive-content"><?php the_content(); ?></div>
<?php
} // if month or category
endwhile;
?>
<h2>Browse by date:</h2>
<?php arl_kottke_archives(); ?>
<h2>Browse by subject:</h2>
<ul class="archive-taxonomy"><?php wp_list_categories('title_li=');?></ul>
<h2>If all else fails, try searching for it&mdash;</h2>
<?php get_search_form(); ?>
</secion><!--archives-->
<?php
// endwhile; // end of the loop.
get_footer();
?>
<?php
/*
This function was originally a plugin, GPL2, information below:
Plugin Name: Kottke Style Archive
Version: 0.3
Plugin URI: http://www.lattimore.id.au/projects/wordpress/plugins/kottke-style-archives/
Author: Alistair Lattimore
Author URI: http://www.lattimore.id.au
Description: Displays an archive of posts in the same style to http://www.kottke.org/everfresh.
*/
function arl_kottke_archives($month_separator = ' ', $month_format = 'M')
{
global $wpdb;
$output = "";
$year = "";
$sql = "SELECT DATE_FORMAT(post_date, '%Y') AS Year, ";
$sql .= "DATE_FORMAT(post_date, '%m') AS Month ";
$sql .= "FROM $wpdb->posts ";
$sql .= "WHERE DATE_FORMAT(post_date, '%Y') <> '0000'";
$sql .= " AND post_status = 'publish'";
$sql .= " AND post_type = 'post' ";
$sql .= "GROUP BY DATE_FORMAT(post_date, '%Y'), DATE_FORMAT(post_date, '%m') ";
$sql .= "ORDER BY DATE_FORMAT(post_date, '%Y') DESC, DATE_FORMAT(post_date, '%m') ASC;";
$months = $wpdb->get_results($sql);
if (!empty($months))
{
foreach ($months as $month)
{
// Add in the year heading
if (($year == "") || ($year != $month->Year))
{
if (strlen($output))
{
$output .= "<br />\n<strong>" . $month->Year . ":</strong>&nbsp;";
}
else
{
$output .= "\n<strong>" . $month->Year . ":</strong>&nbsp;";
}
}
// Add in the monthly archive links
if ($year == $month->Year)
$output .= $month_separator;
$output .= '<a href="' . get_month_link($month->Year, $month->Month) . '">' . date($month_format, mktime(0, 0, 0, $month->Month, 1, $month->Year)) . '</a>';
$year = $month->Year;
}
}
else
{
$output = "<p>None available</p>\n";
}
print $output;
}
?>