Support » Plugin: WordPress Popular Posts » [Plugin: WordPress Popular Posts] Get permalink from the function loop

  • Resolved Shahin


    <?php if (function_exists("get_mostpopular")) get_mostpopular("range=all&order_by=views&limit=3&stats_comments=0&thumbnail_selection=usergenerated&thumbnail_width=100&thumbnail_height=100&excerpt_length=80&do_pattern=1&pattern_form='{image} {title {summary}'&post_start='<li onclick=location.href=\"". get_permalink() ."\">'&post_end='</li>'"); ?>

    As you can tell the get_permalink() is not the right way to do it since it only points to last(?) post.

    Anyone know how to get the correct permalink?

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



    The post_start and post_end parameters are meant to define the opening and closing tags containing the post content, respectively. The permalink is included already within the post content.

    When you call get_permalink() like that it’ll return the URL of the last post queried by WordPress, that’s why it can’t work as you are using it.

    Why you want to attach the onclick event to the LI when there’s a link already on the content?

    I want the entire <li> to be a clickable link to the respectively URL of the post.

    Got any suggestions?

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.]

    Plugin Author Hector Cabrera


    Well, you got two options here: a) hack the plugin’s code so it appends the A tag before the LI tag, o b) use Javascript (jQuery would do wonders here) to get it done.

    Since I’m a jQuery fan (which WordPress uses, too), and considering that any changes made to the plugin would be lost once an update is released, this is what I would do:

    <?php if (function_exists("get_mostpopular")) : ?>
    <script type="text/javascript">
    		jQuery(".popular-posts").delegate("ul li", "click", function(){
    			// get href attribute from A tag
    			var target = jQuery(this).children("a:first").attr("href");
    			// load URL
    			window.location.href = target;
    <?php get_mostpopular("range=all&order_by=views&limit=3&stats_comments=0&thumbnail_selection=usergenerated&thumbnail_width=100&thumbnail_height=100&excerpt_length=80"); ?>
    <?php endif; ?>

    I didn’t test the code but it should do what you need (verify that jQuery is present on your theme’s head section).

    You are a genius.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WordPress Popular Posts] Get permalink from the function loop’ is closed to new replies.