Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/114962318dabb0e3700b2e83d8633c45 to your computer and use it in GitHub Desktop.
Save dwanjuki/114962318dabb0e3700b2e83d8633c45 to your computer and use it in GitHub Desktop.
Shortcode to display a series' list of articles with their available date. #pmpro_series #shortcode
<?php
/**
* This recipe creates a shortcode that shows the list of articles for a specific series.
* Use [pmpro_series id="n"] on any page/post to display a list of posts that belong to a series.
* The attribute "id" is the post ID of the series and is required, e.g [pmpro_series id="123"]
*
* This recipe assumes the site has the PMPro Series: Drip Feed Add On active.
* @link https://www.paidmembershipspro.com/add-ons/pmpro-series-for-drip-feed-content/
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_series_shortcode( $atts ) {
if ( ! function_exists( 'pmpros_the_content' ) ) {
return false;
}
global $post;
extract(
shortcode_atts(
array(
'id' => $post->ID,
),
$atts
)
);
//start output buffering
ob_start();
echo '<div class="pmpro"><div id="pmpro-series-' . $id . '" class="pmpro_card pmpro-series-post-list"><div class="pmpro_card_content">';
$series = new PMProSeries( $id );
$series->getPostList( true ); // true echoes post list
echo '</div></div></div>';
$temp_content = ob_get_contents();
ob_end_clean();
return $temp_content;
}
add_shortcode( 'pmpro_series', 'my_pmpro_series_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment