WordPress.org

Ready to get started?Download WordPress

Forums

need post ID in text widget for "like" button to work (5 posts)

  1. drkknght
    Member
    Posted 3 years ago #

    long story short, I'm looking to duplicate the following line in a non-php, text-widget friendly fashion. (shortcode, maybe?) :
    <?php echo urlencode(get_permalink($post->ID)); ?>

    short story long:
    In an effort to reduce my plugin dependence, i'm trying to hardcode some features to my blog. one such feature is the facebook like button. with ease, i can create a text widget that offers the like-ability of a specific post on my blog. what i'm TRYING to do is create a like-button widget that dynamically recognizes which post it is on, so that the button is unique to each post ID. (in other words, if you click "like" on "10 things i hate about baseball", you're liking that post and not the site over all, or the "50 things i love about football" post, which would have it's own like button).

    the code i have so far is:
    <iframe src="http://www.facebook.com/plugins/like.php?href=http://toonbarn.com/&layout=standard&show-faces=true&width=322&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:322px; height:60px"></iframe>

    with my site being "toonbarn.com". how can i made it so that it will recognize the individual postIDs of each page? is there a WP shortcode I'm overlooking?

    SPECIAL NOTE: this is being created in a text widget, not single.php or other database accessible stuff.

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    is there a WP shortcode I'm overlooking

    probably not - but you can make your own:
    http://codex.wordpress.org/Shortcode_API

    and you may need to add this to functions.php of your theme:

    add_filter('widget_text', 'do_shortcode');
  3. drkknght
    Member
    Posted 3 years ago #

    thanks for the response, alchymyth. at this point, i'm not even sure what the best path is, anymore, to get the results i'm looking for. the coding feels like it's going over my head a bit!

  4. drkknght
    Member
    Posted 3 years ago #

    alright, so, long story short, i created my own facebook like button shortcode. i have no idea if that was the best way, but it does work for what i need :)

    i added the following to my theme's functions.php:

    function fblike() {
        return '<iframe src="http://www.facebook.com/plugins/like.php?href='.get_permalink($post->ID).'&layout=standard&show-faces=true&width=322&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:322px; height:60px"></iframe>';
    }
    add_shortcode('like', 'fblike');

    then, i placed a text widget where i wanted it to be in my widgets panel, and dropped in the new [like] code. bam, done!

  5. gxxaxx
    Member
    Posted 3 years ago #

    Thanks for the posts alchymyth and drkknght.
    It served to introduce me to a whole new area in the wordpress world.
    Between this code and the http://codex.wordpress.org/Shortcode_API page everything went great.

Topic Closed

This topic has been closed to new replies.

About this Topic