Created
October 21, 2013 00:31
-
-
Save dcsg/7077053 to your computer and use it in GitHub Desktop.
Add talks by year to my wordpress blog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The template for displaying Category Archive pages. | |
* | |
* @package WordPress | |
* @subpackage Twenty_Eleven | |
* @since Twenty Eleven 1.0 | |
*/ | |
get_header(); ?> | |
<style type="text/css"> | |
#recent-posts li { list-style: none; margin-left: 15px; } | |
#recent-posts li.year { list-style: none; margin-left: 0px; font-size:1.4em; } | |
</style> | |
<section id="primary"> | |
<div id="content" role="main"> | |
<?php if ( have_posts() ) : ?> | |
<header class="page-header"> | |
<h1 class="page-title"><?php | |
printf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . single_cat_title( '', false ) . '</span>' ); | |
?></h1> | |
<?php | |
$category_description = category_description(); | |
if ( ! empty( $category_description ) ) | |
echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_description . '</div>' ); | |
?> | |
</header> | |
<?php twentyeleven_content_nav( 'nav-above' ); ?> | |
<?php | |
if (is_category('talks')) | |
{ | |
echo "<ul id=\"recent-posts\">"; | |
favrik_recent_posts('group=1&limit=500'); | |
echo "</ul>"; | |
} elseif (is_category('palestras')) { | |
echo "<ul id=\"recent-posts\">"; | |
favrik_recent_posts('group=1&limit=500'); | |
echo "</ul>"; | |
} else { | |
while ( have_posts() ) { | |
the_post(); | |
get_template_part( 'content', get_post_format() ); | |
} | |
} | |
?> | |
<?php twentyeleven_content_nav( 'nav-below' ); ?> | |
<?php else : ?> | |
<article id="post-0" class="post no-results not-found"> | |
<header class="entry-header"> | |
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1> | |
</header><!-- .entry-header --> | |
<div class="entry-content"> | |
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p> | |
<?php get_search_form(); ?> | |
</div><!-- .entry-content --> | |
</article><!-- #post-0 --> | |
<?php endif; ?> | |
</div><!-- #content --> | |
</section><!-- #primary --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
/** | |
Most important configuration variable is $group: | |
0 - Just put the date at the left side. | |
1 - Group by year, month, and day. | |
*/ | |
function favrik_recent_posts($args = '') { | |
global $wp_locale, $wpdb; | |
// params fun | |
parse_str($args, $r); | |
$defaults = array('group' => '1', 'limit' => '10', 'before' => '<li>', 'after' => '</li>', 'show_post_count' => false, 'show_post_date' => true, 'date' => 'F jS, Y', 'order_by' => 'post_date DESC'); | |
$r = array_merge($defaults, $r); | |
extract($r); | |
// output | |
$output = ''; | |
$pre = ''; | |
$full_date = ''; | |
$year = ''; | |
$month = ''; | |
$day = ''; | |
// the query | |
$where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND tt.taxonomy = 'category' AND tt.term_id IN (82,85)"); | |
$join = apply_filters('getarchives_join', " INNER JOIN {$wpdb->term_relationships} tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)"); | |
$qry = "SELECT ID, post_date, post_title, post_name | |
FROM $wpdb->posts $join | |
$where ORDER BY $order_by LIMIT $limit"; | |
$arcresults = $wpdb->get_results($qry); | |
if ($arcresults) { | |
foreach ($arcresults as $arcresult) { | |
if ($arcresult->post_date != '0000-00-00 00:00:00') { | |
$url = get_permalink($arcresult); | |
if ($group == 0) { // dates at the side of the post link | |
$arc_date = date($date, strtotime($arcresult->post_date)); | |
$full_date = '<em class="date">' . $arc_date . '</em> '; | |
} | |
if ($group == 1) { // grouping by year then month-day | |
$y = date('Y', strtotime($arcresult->post_date)); | |
if ($year != $y) { | |
$year = $y; | |
$pre = '<li class="year">' . $year . '</li>'; | |
} | |
} | |
$full_date = date('d/m', strtotime($arcresult->post_date)).' '; | |
$text = strip_tags(apply_filters('the_title', $arcresult->post_title)); | |
$output .= get_archives_link($url, $text, $format, | |
$pre . $before . $full_date, | |
$after); | |
$pre = ''; $full_date = ''; | |
} | |
} | |
} | |
echo $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment