Series Posting in Wordpress

In my functions.php file, I have some code which implements series posting. This relies on the thematic framework

function childtheme_article_footer($footer) {
	// This variable is the stuff I put before the regular 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();

	// Check for a 'series' as a custom field - if there is one, grab the value contained
	if($series) :
		$args = array(
			'numberposts' => -1,
			'meta_key' => 'Series',
			'meta_value' => $series,
		);

		// This bit grabs the series posts, and stores the HTML linking to them in $extra_stuff variable
		$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>';
				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><a href="' . get_permalink($serial->ID) . '" class="postID_' . $serial->ID . '" title="' . str_replace('"', '"', $serial->post_title) . '">' . str_replace('"', '"', $serial->post_title) . '</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;

       // This is irrelevant to series list, but it does add twitter links and the like
	$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>';

	// This slams it all together at the end of the post
	$footer = $extra_stuff . $footer . $extra_stuff_post;
	return $footer;
}

// This replaces thematics stuff with mine
add_action('thematic_postfooter','childtheme_article_footer');

It’s been a while since I did this, and my aim of tidying the output is now further away than it was. What I want is for the code to ONLY output the first post in a series, the previous post, the current post (with no link), the next post and the last post. If any of these posts are one and the same, they would only be output once.

I’m really drawing a bit of a blank on how to do this – though I sense I’m missing a trick. If anyone has any bright ideas, I’d be glad to hear them.

Series Information

"Series Posting in Wordpress" is 3rd in a larger sequence of 4 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.

3 Comments

  1. Artela
    Posted February 6, 2010 at 11:20 am | Permalink

    Is there any way of stopping these PHP coding posts from hitting the RSS feed? Sorry – they break my reader due to the line lengths :-(

  2. Posted February 6, 2010 at 11:36 am | Permalink

    That’s odd – they shouldn’t do that. It looks like the sourcecode plugin which makes ‘em pretty for the web is using a pre-formatted text block for the RSS (as otherwise the code gets interpreted and this changes the meaning). This is a sensible thing to preserve meaning, but….

    I could fix it in CSS, but readers don’t respect CSS, it could be fixed, I think, with local CSS at your end – but that’s not optimal by any stretch of the imagination.

    One solution would be to change the feed to only show excerpts, but that isn’t ideal if you want full feeds. I think I could do that by putting things in the ‘read more’ box – but that relies on my remembering every time. Not ideal – I’ll try and remember to do that, apologies if I forget.

    I’ll try and work out how to get the RSS to wrap automagically (but I can’t promise success)

    Oh, I’ve worked out how to do what I needed – I’ve managed to identify first, last, next, previous and used CSS to hide everything else. At some point everything else won’t appear in the HTML either, but that’s less critical as display:none is pretty well respected. I’m not yet ready to post the code – it ain’t pretty.

  3. Posted February 6, 2010 at 11:38 am | Permalink

    I’ll also try and avoid longer lines in the first place – that isn’t pretty either (since posting the above, those long lines have been divided up – which makes it much more readable)

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