Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!! :)

share|improve this question
    
Are you referring to the native WordPress function`get_comment_count` or something else? –  iambriansreed Dec 11 '12 at 0:55

2 Answers 2

up vote 0 down vote accepted

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;
    }
}
share|improve this answer
    
awsome man!! Worked like a charm, thanks a lot. –  I am not a Frog Dec 11 '12 at 0:55
    
@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

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;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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