Skip to content

Instantly share code, notes, and snippets.

@uamv
Last active September 4, 2015 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uamv/f726e3741e9c9a12357c to your computer and use it in GitHub Desktop.
Save uamv/f726e3741e9c9a12357c to your computer and use it in GitHub Desktop.
Append Series List to WordPress Posts
<?php
add_filter( 'the_content', 'uamv_series_list', 2 );
function uamv_series_list( $content ) {
// associative array with seriesName => array of post IDs
$series = array(
'#MissionText' => array( 5671, 5691, 5741, 5814 ),
'Prayer' => array( 171, 220, 235, 237, 239, 241, 3890 ),
);
foreach ( $series as $list => $ids ) {
// we'll display the series list only on single posts
if ( is_single( $ids ) ) {
$content .= '<p style="font-size:75%;text-align:right;"><strong>Other posts in this <em>' . esc_html( $list ) . '</em> series:</strong><br />';
// insert link to each post in the series
foreach ( $ids as $key => $id ) {
// prepend a separator to each post - after the first
$content .= $key > 0 ? ' • ' : '';
$content .= '<a href="' . get_permalink( $id ) . '">' . get_the_title( $id ) . '</a>';
}
$content .= '</p>';
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment