create_post_series_box
part of GWP tutorial : https://generatewp.com/group-post-series-custom-taxonomy
/*
* create_post_series_box
* Create post series box html markup
* @param int $current_id current post ID.
* @param array $posts_in_series array of post IDs.
* @param WP_Term $series Post Series taxonomy term.
* @return string HTML markup of post series box
*/
function create_post_series_box( $current_id, $posts_in_series, $series ){
//box template (filterable)
$template = apply_filters( 'GWP_series_box_template', '
<div id="post-series">
<div class="series-title">Post Series: {series_title}</div>
{series_list}
</div>
');
//list tag (filterable)
$list_tag = apply_filters( 'GWP_series_list_tag', 'ul' );
//create an array of all posts in series as li tags
$items = array();
foreach ( $posts_in_series as $id ) {
$title = get_the_title( $id );
if ( $id == $current_id ){
//this is the current post so no link anchor tag is needed
$items[] = '<li class="current series-item">' . $title .'</li>';
}else{
$items[] = '<li class="series-item"><a title="'.esc_attr( $title ).'" href="' .get_permalink( $id ) .'">' . $title .'</a></li>';
}
}
//connect the items to a list
$list = '<' . $list_tag .'>' . implode( "n", $items ). '</'. $list_tag .'>';
//array of template tokens
$search = array(
'{series_id}',
'{series_slug}',
'{series_title}',
'{series_description}',
'{series_url}',
'{series_list}'
);
//array of token replacements
$replace = array(
$series->term_id,
$series->slug,
$series->name,
$series->description,
get_term_link( $series, $this->tax_name ),
$list
);
//replace tokens in template with actual data
$box = str_replace( $search, $replace, $template );
//return box html (filterable)
return apply_filters( 'GWP_series_box', $box, $current_id, $posts_in_series, $series );
}