WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
Add spaces to post_start attribute (4 posts)

  1. dancasas
    Member
    Posted 3 years ago #

    Hello,

    I am trying to tune the plugin through the short code [wpp], but when I am using strings with spaces as a value of any of the attributes, everything crashes.

    For example, I would like to set the post_start parameter as follows

    [wpp post_start="<div class="popular_entry">" post_end="</div>"]

    and I believe it chrashes due to the space between div ans class, and maybe also due to the extra " I am using.

    I there any way to fix this? Thanks a lot!

  2. maorb
    Member
    Posted 3 years ago #

    Have you find a solution to this?
    In my case, I use the template function wpp_get_mostpopular with some args. All args are well working, except the post_start and post_end - it just ignores everything I try to write as post_start, I tried to put a string with no spaces, but didn't help - this attribute just won't expand and stays as
    li

    Any ideas?

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  3. dancasas
    Member
    Posted 3 years ago #

    I haven't found any solution so far... It looks to me that this is a common issue to anyone trying to play with this plugin, but no one seems to have solved the problem.

    More ideas anyone?

  4. maorb
    Member
    Posted 3 years ago #

    Well, I've just wrote couple lines of code to handle this.
    If you use the template tag and not the shortcode, you can use these:

    <?php if (function_exists('wpp_get_mostpopular')) {
    				ob_start();
            			$args = 'limit=5&range=weekly&order_by=views&pages=0&stats_comments=0';
    					wpp_get_mostpopular($args);
    				$popular = ob_get_clean();
    
    				$popular = explode('</li>', $popular);
    				$popular_counter=1;
    
    				foreach ($popular as &$p)	{
    					$p = str_replace('<li>','<li class="popular popular-'.$popular_counter.'">',$p);
    					$popular_counter++;
    				}			
    
    				$popular = implode('</li>', $popular);
    				$popular = str_replace('<ul>', '<ul class="popular-posts">', $popular);
    				echo $popular;
    
    			} ?>

    The $args line, define the args I want, except of the post_start.
    The line that starts with $p = str_replace ... will replace any li with li with class popular and also class popular-1/popular-2 etc.. so you can later style these.

    Hope it will help you and others.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic