Updated Code for Series Posts

I just posted about a problem with series posts. Almost immediately I solved it.

I’m not really ready for this to go public – as all it does is tag the posts (I really want to only show the HTML of those posts), but I wanted to check that my manual remedy for ensuring that posting code doesn’t do funny things to my friend’s RSS reader works (see comment on previous). I’ve tried to prevent this by using a ‘read more’ tag as that should stop the RSS at that point.

Ultimately, I’d want to have the software automatically trim down the lines so I don’t have to rely on doing this manually.

This code tags the first/last/prev and next posts, and then uses CSS to clean it up.

This code goes in functions.php – relying on the thematic framework

function childtheme_article_footer($footer) {
	$extra_stuff='';

	global $id, $post;
	$series = get_post_meta($post->ID, 'Series', true);
	$pstlink = get_permalink();
	$psttitle = get_the_title();
	$pstbody = get_the_excerpt();
	if($series) :
		$args = array(
			'numberposts' => -1,
			'meta_key' => 'Series',
			'meta_value' => $series,
		);
		$series_posts = get_posts($args);
		if($series_posts) :
			$class = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", $series);
			$class = strtolower(str_replace(array(' ', ' '), '-', $class));
			if (is_single()) {
				$extra_stuff = '<div class="series series-' . $class . '"><h4 class="series-title">' . __('Articles in this series') . '</h4><ul>';

				// This bit finds first, last, previous, next and current posts.

				$lowest=99999999999;
				$prevpost=99999999999;
				$nextpost=0;
				$highest=0;
				$lastwascurrent=0;
				$currenthaspassed=0;
				foreach($series_posts as $serial) :
					if ($lastwascurrent == 1) {
						$lastwascurrent = 0;
						$prevpost=$serial->ID;
					}
					if ($serial->ID < $lowest) {
						$lowest = $serial->ID;
					}
					if ($serial->ID == $post->ID) {
						$current=$serial->ID;
						$lastwascurrent=1;
						$currenthaspassed=1;
					}
					if ($currenthaspassed == 0) {
						$nextpost=$serial->ID;
					}
					if ($serial->ID > $highest) {
						$highest=$serial->ID;
					}
				endforeach;

				foreach($series_posts as $serial) :
					if($serial->ID == $post->ID)
                			        $extra_stuff = $extra_stuff . '<li class="current-post">' . $serial->post_title . '</li>';
               				else {
						$extra_stuff = $extra_stuff .  '<li';

						// Custom CSS for first, last, previous, next and current posts
						if ($serial->ID == $highest) {$extra_stuff = $extra_stuff .  ' class="highestseriespost">Newest in Series: ';} else {
							if ($serial->ID == $lowest) {$extra_stuff = $extra_stuff .  ' class="lowestseriespost">First in Series: ';} else {
								if ($serial->ID == $prevpost) {$extra_stuff = $extra_stuff . ' class="previnseries">Previous in Series: ';} else {
									if ($serial->ID == $nextpost) {$extra_stuff = $extra_stuff . ' class="nextinseries">Next in Series: ';} else {
										$extra_stuff = $extra_stuff . ' class="regularseriespost">';
									}
								}
							}
						}
						$extra_stuff = $extra_stuff .  '<a href="' . get_permalink($serial->ID);
						$extra_stuff = $extra_stuff .  '" class="postID_' . $serial->ID;
						$extra_stuff = $extra_stuff .  '" title="';
						$extra_stuff = $extra_stuff .  str_replace('"', '"', $serial->post_title) . '">';
						$extra_stuff = $extra_stuff .  str_replace('"', '"', $serial->post_title);
						$extra_stuff = $extra_stuff .  '</a></li>';
               				}
				endforeach;
				$extra_stuff = $extra_stuff .  '</ul></div>';

			} else { 

                                $extra_stuff = $extra_stuff .  '<div class="series series-' . $class . '">';
                                $extra_stuff = $extra_stuff .  '<h4 class="series-title"><a href="' . $pstlink . '">' . $psttitle . '</a>';
                                $extra_stuff = $extra_stuff .  ' is part of a series' . '</h4></div>';
                        }
		endif;
	endif;

	$pageurl = get_bloginfo('siteurl');
        $pageurl = $pageurl . "?p=" . $post->ID;
	$extra_stuff_post = '<div class="socialnetwork"><ul>';
	$extra_stuff_post = $extra_stuff_post . '<li>Send to: <a class="twitterlink" href="http://twitter.com/home?status=Currently reading ' . $pageurl . '" title="Click to send ' . $psttitle . ' to Twitter!" target="_blank">Twitter</a></li>';
	$extra_stuff_post = $extra_stuff_post . '<li><a class="deliciouslink" href="http://del.icio.us/post?url=' . $pstlink . '&title=' . $psttitle . '" title="Click to bookmark ' . $psttitle . ' on del.icio.us!" target="_blank">del.icio.us</a></li>';
	$extra_stuff_post = $extra_stuff_post . '<li><a class="digglink" href="http://digg.com/submit?phase=2&url=' . $pstlink . '&title='. $psttitle . '&bodytext=' . $pstbody . '" title="Click to bookmark ' . $psttitle . ' on Digg!" target="_blank">Digg</a></li>';
	$rss_url = get_bloginfo('rss2_url');
	$extra_stuff_post = $extra_stuff_post . '<li>Use the: <a class="rsslink" href="' . $rss_url . '" title="Click to Subscribe to the Feed"  rel="alternate" type="application/rss+xml" target="_blank">RSS Feed</a></li>';
	$extra_stuff_post = $extra_stuff_post . '</ul></div>';
	$footer = $extra_stuff . $footer . $extra_stuff_post;
	return $footer;
}

add_action('thematic_postfooter','childtheme_article_footer');

In style.css, I add this:

div.series .regularseriespost {display: none;}
div.series .current-post {display: none;}

Series Information

"Updated Code for Series Posts" is the last in a sequence of 4 posts

  • Thematic - A problem with php
  • Thematic Child Theme - Post Footer Modification
  • Series Posting in Wordpress
  • This post: Updated Code for Series Posts
    • Add to Delicious
    • Digg This Post
    • Stumble This Post
    • RSS Feed
    This entry was posted in Wordpress and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

    2 Comments

    1. Artela
      Posted February 6, 2010 at 11:32 pm | Permalink

      And you are a star – my page is no longer broken!
      I may not comment often, but there are some things you post that I do like to read :-)

    2. Posted February 7, 2010 at 8:49 am | Permalink

      Apologies if I forget to put in the ‘break’ link in future.

    Post a Comment

    Your email is never published nor shared.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Subscribe without commenting

    • Categories

    • Archives

    • Recent Comments