How to use a post template to display in popular post list
-
Hello,
first of all thanks for this great, fully customizable plugin.
We’re using a self developed theme in our site (based on Blankslate).
Instead of customizing WPP’s output via custom theme, I’d like to use an existing post template (‘entry-small.php’) for rendering the popular post list.
Therefore I hooked into the
wpp_custom_html
filter:function my_12345_wpp_posts_html($popular_posts, $instance) { // loop the array of popular posts objects $output = '<div>'; foreach( $popular_posts as $popular_post ) { setup_postdata( $popular_post->id ); ob_start(); get_template_part( 'entry-small' ); $post_html = ob_get_clean(); $output .= $post_html; } $output .= '</div>'; return $output; } add_filter('wpp_custom_html', 'my_12345_wpp_posts_html', 10, 2);
Unfortunately this doesn’t work. The only thing which is shown in the list of popular posts is the post’s author name (all other fields are displayed as an ellipsis ‘…’).
What am I missing? Is there a better way to achieve this?
Here’s the (shortened) content of entry-small.php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="article-item"> <div class="row g-0"> <div class="col-2"> <?php if ( ( has_post_thumbnail() ) ) : ?> <a class="dark-link" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <?php $img_class = 'img-left'; if (strlen(get_post_custom_values('Fokus')[0]) > 0) { $focus = get_post_custom_values('Fokus')[0]; $focus = strtolower($focus); if ($focus == 'links') { $img_class = $img_class . ' left'; } elseif ($focus == 'rechts') { $img_class = $img_class . ' right'; } } if (in_category('Kommentar')) { get_template_part( 'commentary-img', null, array('img_class' => $img_class)); } else { the_post_thumbnail('medium_large', array('class' => $img_class)); }?> </a> /* more content ... */
The page I need help with: [log in to see the link]
- The topic ‘How to use a post template to display in popular post list’ is closed to new replies.