WordPress Popular Posts
Trouble with template tags for wpp_get_mostpopular() (17 posts)

  1. Ollie Ford
    Posted 3 years ago #

    Hi, I'm hoping someone can help me out, I have the following, but it doesn't return anything. Nothing at all.

    <?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular('range=weekly&limit=4&post_html=<div id="pop-link"><div id="pop-thumb">{thumb}</div><div id="pop-title"><a href="{url}">{text_title}</a></div></div>'); ?>

    What's wrong with that?

    If I remove the post_html=... It displays the posts (albeit poorly formatted). So why does my HTML break it?


  2. Ollie Ford
    Posted 3 years ago #

    Oh it's the spaces. Oh perhaps not.

    I'm not sure I understand the documentation for it - the FAQ contradicts itself, should the values of post_html= and range= be inside "" or not?

    I have:

    $html = "<div id='pop-link'><div id='pop-thumb'>{thumb}</div><div id='pop-title'><a href='{url}'>{text_title}</a></div></div>"
    wpp_get_mostpopular("range="weekly"&limit=4&wpp_start="<div id='pop-posts'>"&wpp_end="</div>"&post_html="$html"")
  3. Ollie Ford
    Posted 3 years ago #

    Okay, now using an array, except that post_html is just reverting to it's default for some reason?

    A bullet pointed list with # comments. As you can see, my HTML contains neither an ordered list nor any mention of comments:

    <div id="pop-posts">
    <?php $wppparams = array(
    'header_start' => '',
    'header' => '',
    'header_end' => '',
    'range' => 'weekly',
    'limit' => 4,
    'wpp_start' => '',
    'post_html' => '<div id="pop-link"><div id="pop-thumb">{thumb}</div><div id="pop-title"><a href="{url}">{text_title}</a></div></div>',
    'wpp_end' => '');
    if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular($wppparams); ?>
  4. Hector Cabrera
    Plugin Author

    Posted 3 years ago #

    Hi Ollie,

    Try this instead:

    	if (function_exists('wpp_get_mostpopular'))
    		wpp_get_mostpopular("range='monthly'&limit=4&post_html='<div id=\"pop-link\"><div id=\"pop-thumb\">{thumb}</div><div id=\"pop-title\"><a href=\"{url}\">{text_title}</a></div></div>'");

    String values should always be in quotes, specially when using the post_html paramater. Also, it's necessary to escape quotes so PHP can parse the values without issues.

    Since this can be a bit complicated for the average user, I'm already working on another way to customize the HTML output.

  5. Ollie Ford
    Posted 3 years ago #

    Thanks for getting back to me.

    I could've escaped them, as above I went for an array for readability. But that's just letting the post_HTML value default - surely escaping them inline won't make a difference to that?

  6. Ollie Ford
    Posted 3 years ago #

    If I may, I think the best solution would be to provide a 'popular_loop()'.

    So that users can use content.php or otherwise the_title() etc as normal.

    I currently use a custom function with wp_query in this manner, but I'm trying to switch to your plugin for the range=weekly ability.


  7. Ollie Ford
    Posted 3 years ago #

    Bah. Not really a solution - I edited your defaults array. Fixed it.

    I still think the ideal for user friendliness, ease of use, and template integration would be to provide a set of popular posts, so you could implement something like the following:

    <?php if(wpp_have_posts($range, $limit)): while(wpp_have_posts($range, $limit)): ?>
        <?php get_template_part('popular-content',get_post_format()); ?>
    <?php endwhile; endif; ?>
  8. stoffb
    Posted 3 years ago #


    I'm currently using a similar code for my website: http://www.hautstyle.co.uk
    The php code I use is:
    <?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=daily&stats_comments=0&limit=10&pages='0'&order_by='views'&thumbnail_selection='usergenerated'&thumbnail_width='250'&thumbnail_height='80'"); ?>

    I don't know if I'm doing anything wrong anywhere but alt text for the thumbnails aren't showing although everything else seems to be working perfectly...
    I've been looking around for hours now and can't find a solution to show the alt text.

    If you could enlighten me that would be great.

    Many thanks

  9. Ollie Ford
    Posted 3 years ago #

    Have you used add_image_size() in functions.php to create the new thumbnail size?

  10. stoffb
    Posted 3 years ago #

    Hi Ollie,

    I have used it yes, is it coming from there? Do I have to specify something in the code?
    That's what I have a t the minute: add_image_size( 'featured', 250, 80,true );

    Everything works perfectly fine apart from the thumbnail alt text not showing...

    Many thanks

  11. Ollie Ford
    Posted 3 years ago #

    Oh alt text, sorry, I misunderstood.

    You'll have to use the post_html= attribute for that, there's no other way to get alt="your words" into just the thumbnail element without making the whole thing custom.

    If you're only using wpp once though, you may find it's easier to edit the default option in plugins > editor > wpp.

  12. stoffb
    Posted 3 years ago #


    Sorry it was confusing... Just to clarify, I do not want alt="my words" but alt="thumbnail_title".... Would that change anything?


  13. stoffb
    Posted 3 years ago #

    Hi again,

    I've had a look at the post_html solution you suggested but I can't actually access the img tag as it's dynamically generated by {thumb} so I can't add the alt tag to it....

    Any ideas?
    Many thanks

  14. stoffb
    Posted 3 years ago #

    In the code I identified where I need to add the alt tag but I don't know what to add:
    return "<img src=\"". $new_img ."\" alt=\"\" width=\"{$dim[0]}\" height=\"{$dim[1]}\" class=\"wpp_cached_thumb wpp_{$source}\" />";

    So I should replace alt=\"\" with something like alt=\"{title}\" but this doesn't work however if I use alt=\"'test'\" then all the images used in wpp have an alt tag of "test"...

    Getting there, but not quite yet :)

  15. Ollie Ford
    Posted 3 years ago #

    Ah yeah I see.

    This is why I suggested to H├ęctor (plugins author) that WPP open a loop, then you would have been able to simply use the_post_thumbnail().

    It seems WPP doesn't use thumbnail from functions.php, it generates itself - and it doesn't provide access to the id through post_html either.

    I'm not sure what you can do in your case without delving deeper into the plugins code.

  16. stoffb
    Posted 3 years ago #

    Thanks for all your help Ollie, I'll keep looking

  17. stoffb
    Posted 3 years ago #


    I've been digging around and still haven't found a solution...
    Would anyone be able to point me in the right direction?

    Many thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WordPress Popular Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic