WordPress.org

Ready to get started?Download WordPress

Forums

Easy Popular Posts
show=false does not work (5 posts)

  1. Bart McLeod
    Member
    Posted 3 years ago #

    <?php
    	if (function_exists('popularPosts')) {
    		$populars = popularPosts('show=false');
    		if (is_array($populars)) {
    			foreach ($populars as $popular) {
    				var_dump($popular);
    			}
    		}
    	}
    ?>

    I tried the above, following your FAQ from the plugin repository. But show=false does not return the links, it just spits them out as if false was not in the parameters. Am I doing something wrong? I will look into the code later.

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

  2. Bart McLeod
    Member
    Posted 3 years ago #

    Well, I looked into the code and found why it does not work.

    if ( $ns_options['show'] ) {
    		echo $popular;
    	} else {
    		return $popular;
    	}

    The above bit of code should obviously be:

    if ( $ns_options['show'] !== 'false') {
    		echo $popular;
    	} else {
    		return $popular;
    	}

    Since all the options are extracted as strings, string 'false' converts to boolean true if you just check if it is set. Instead, you should do a check for the exact string 'false'.

    And then, after changing the code in this way, my snippet will still not work, because the result is not an array. This is not wrong by the way.

    Why would I like to change the behavior? [maybe it already exists, I have to dig in further]. Well, I would like the first of the popular posts to show the excerpt and the title only for the rest of them.

  3. Bart McLeod
    Member
    Posted 3 years ago #

    The same applies to:

    if ( $ns_options['credit'] !== 'false' ) {
    		$popular .= "<li style='opacity:0.4;filter:alpha(opacity=40);'><a href='http://thisismyurl.com/downloads/wordpress/plugins/easy-popular-posts/?source=" . urlencode(get_bloginfo('url')) . "' style='opacity:0.4;filter:alpha(opacity=40);' target='_blank'>Easy Popular Posts by Christopher Ross</a></li>";
    	}
  4. Bart McLeod
    Member
    Posted 3 years ago #

    I have refactored your plugin code to allow for separate retrieval of the popular posts as an array and fixed the two bugs mentioned above.

    Do you have an repository or e-mail where I can post the altered plugin so that you can use it if you like?

  5. christopherross
    Member
    Plugin Author

    Posted 3 years ago #

    Hi Bart, thanks for addressing that. I try my best to keep the plugins updated and tested, it's surprising to me that this was not working as I've used it myself for many years without issue.

    If you could send the plugin to me (info@thisismyurl.com) I'll review it and update the version here on WordPress.org as soon as possible.

    Chris

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic