• Resolved redwiredesign

    (@redwiredesign)


    Hi,

    It would be great if you could make a public function that just fetches the post objects and doesn’t render the HTML so we can have total control over the look of the results.

    The main reason I want this is because there’s no way of checking the number of popular posts before rendering the content. My theme will show different content depending upon if there are popular posts or not.

    As it stands I will have to write my own function to check, before I render the function.

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @redwiredesign,

    There’s the WordPressPopularPosts\Query class. Use that to retrieve post objects and build your posts list however you want/need.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Or you can use the wpp_no_data filter hook to display alternative content when no popular posts were found.

    • This reply was modified 6 years, 7 months ago by Hector Cabrera. Reason: Fixed typo
    Thread Starter redwiredesign

    (@redwiredesign)

    Thank you I’ll try the class.

    Unfortunately the wpp_no_data filter isn’t useful in my case. The PHP still has no idea if there are any popular posts or not.

    It would be useful perhaps to add a param to return the string of HTML instead of echoing it from within the function. At least then we can determine if there are popular posts or not in the code.

    Thanks.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Unfortunately the wpp_no_data filter isn’t useful in my case. The PHP still has no idea if there are any popular posts or not.

    It would be useful perhaps to add a param to return the string of HTML instead of echoing it from within the function. At least then we can determine if there are popular posts or not in the code.

    No need, WPP does that check for you automatically and if no posts are found then that filter hook is called (see related code here).

    Thread Starter redwiredesign

    (@redwiredesign)

    I appreciate how the filter works, however the no data filter doesn’t affect the header. The function still prints out the header even if there are no posts.

    I’m sure you can imagine how embarrassing it is for a website to have a heading saying “Popular posts” and then there being none. It’s far better to show nothing until there is data.

    I shall use the class so I can achieve what I’m trying to do. Thanks.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Ah, that is true. Maybe I should improve that on future releases. Thanks for the reminder!

    Anyways, I’m marking this topic as resolved. If you need help with anything else don’t hesitate to ask.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Retrieve posts as an array not HTML’ is closed to new replies.