0

I'm trying to get post's permalinks outside of the loop via a wordress plugin. Nothing seems to be working. Here is the original code that does not link to any permalink.

public function get_comments_count($single){
        if (isset($this->params['comments']) && $this->params['comments'] == 'yes'){
            return '<div id="disquscomments"><a href="'.$permalink.'#disqus_thread">Comments</a></div>';
        } else {
        return null;
        }
    }

To get the comments linking to the permalink, I tried adding echo get_permalink within the href link, like so..

public function get_comments_count($single){
        if (isset($this->params['comments']) && $this->params['comments'] == 'yes'){
            return '<div id="disquscomments"><a href="<?php echo get_permalink($post->ID); ?>#disqus_thread">Comments</a></div>';
        } else {
        return null;
        }
    }

This just returned the link as mysite.com/< ? php echo get_permal... So, I then tried setting a function for permalink and putting it in the href link.. I did this like so...

    public function get_comments_count($single){
                $permalink = get_permalink($post->ID);
        if (isset($this->params['comments']) && $this->params['comments'] == 'yes'){
            return '<div id="disquscomments"><a href="'.$permalink.'#disqus_thread">Comments</a></div>';
        } else {
        return null;
        }
    }

Unfortunately, this did not work. It just returned the link as mysite.com/#disqus_thread without the actual permalink.

I have no idea why this isn't working. :( Any help would truely be appreciated, and if you would like me to paste the full plugin code via pastebin, I gladfully will! Please help a bro out!! :)

  • Are you referring to the native WordPress functionget_comment_count or something else? – iambriansreed Dec 11 '12 at 0:55
0

According to: http://wpseek.com/get_comment_count/ $single is the post ID.

Try:

public function get_comment_count($single){
    if (isset($this->params['comments']) && $this->params['comments'] == 'yes'){
        return '<div id="disquscomments"><a href="'.get_permalink($single).'#disqus_thread">Comments</a></div>';
    } else {
    return null;
    }
}
  • @user1658560 Up vote and accept please! – iambriansreed Dec 11 '12 at 0:56
  • Of corse, It says 3 more minutes though, be patient. :) – I am not a Frog Dec 11 '12 at 0:57
-1

Inside your function, you are outside of scope from your loop. You should call the function with the ID of the post, so add a 2nd parameter:

public function get_comments_count($single, $postid){
     $permalink = get_permalink($postid);
    if (isset($this->params['comments']) && $this->params['comments'] == 'yes'){
        return '<div id="disquscomments"><a     href="'.$permalink.'#disqus_thread">Comments</a></div>';
    } else {
    return null;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.