How to use a post template to display in popular post list

[ad_1]

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="https://projectdmc.org/support/topic/how-to-use-a-post-template-to-display-in-popular-post-list/<?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 ... */
  • This topic was modified 4 hours, 4 minutes ago by Abid.
  • This topic was modified 4 hours, 3 minutes ago by Abid.

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer