Last active
September 4, 2015 15:44
-
-
Save uamv/f726e3741e9c9a12357c to your computer and use it in GitHub Desktop.
Append Series List to WordPress Posts
This file contains 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 | |
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