Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.