Support » Plugin: WordPress Popular Posts » Trouble with template tags for wpp_get_mostpopular()

  • 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?

Viewing 15 replies - 1 through 15 (of 16 total)
  • 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"")

    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); ?>
    Plugin Author Hector Cabrera


    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.

    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?

    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.


    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; ?>


    I’m currently using a similar code for my website:
    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

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

    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

    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.


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


    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

    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 🙂

    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.

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

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Trouble with template tags for wpp_get_mostpopular()’ is closed to new replies.