wavematt
Forum Replies Created
-
Okay I resolved my own issue. Sorry, this theme I’m working on had a custom plugin that was conflicting with the Popular Posts plugin. Once I deactivated the conflicting plugin, my code started working. Thanks for your help Hector! Sorry for the confusion!
Hey Hector,
Yep that’s me haha.
PHP version is 7.0.31
Plugin version is 4.1.1
Sage Theme version is 9.0.0Below is a summary of the code I have implemented so far with popular posts.
Thank you for your help btw ??
Blade Template which calls wpp_get_mostpopular():
$category = get_the_category()[0]->cat_ID; {{ wpp_get_mostpopular([ 'range' => 'all', 'order_by' => 'views', 'cat' => $category->parent, 'limit' => 5 ]) }}
WPP Filter to create custom output:
// My filter just passes $popular_posts to my blade template // The issue in this filter is $popular_posts is a string, not an array add_filter('wpp_custom_html', function ($popular_posts, $instance) { $data = [ 'popular_posts' => $popular_posts ]; return sage('blade')->render('partials.popular-posts', $data); }, 10, 2);
Blade Template to render the custom html:
@foreach ($popular_posts as $popular_post) // render each post @endforeach
Even without the blade usage, I could still build this HTML string by looping through the posts, but again – that’s where I’m stuck because its a string and not an array.