Add a Facebook Like Button to Your Category Pages 5 Comments

I’ve just implemented this trick on my personal blog for each category. In the left sidebar, I have a listing of my blog’s categories with the heading “let’s talk” (because I want to create and join conversations in these niches). Then, the heading of every category’s archive page has a Facebook Like button. When clicked, the reader is posting a link not to my site as a whole and not to a particular post, but to the category page itself.

Like Button for Category Archives

Why is this valuable?

  • It’s viral, offering one more thing people can share.
  • It gauges popularity of a given subject.
  • It allows me to market to a specific niche later via the Facebook page’s administrator controls (assuming you’re using your profile ID as the admin of all like buttons on your website via the Open Graph head tags).

The code below would need to be inserted in your category.php file just inside your content area and before you start your loop. Because themes are coded so differently, it’s impossible for me to show the specifics, but in my theme, it went just inside the “content” div.

 PHP |  copy code |? 
<!<!--DVFMTSC--><!--DVFMTSC--><!--DVFMTSC--> The<!--DVFMTSC--> first<!--DVFMTSC--> part<!--DVFMTSC--> is<!--DVFMTSC--> just<!--DVFMTSC--> my<!--DVFMTSC--> way<!--DVFMTSC--> of<!--DVFMTSC--> automatically<!--DVFMTSC--> echoing<!--DVFMTSC--> "Lets<!--DVFMTSC--> Talk<!--DVFMTSC--> About<!--DVFMTSC--> the<!--DVFMTSC--> Subject<!--DVFMTSC--> at<!--DVFMTSC--> Hand."<!--DVFMTSC--> <!--DVFMTSC--><!--DVFMTSC-->−>
<h3<!--DVFMTSC--> class="category<!--DVFMTSC-->−heading"><?php<!--DVFMTSC--> printf(<!--DVFMTSC--> __(<!--DVFMTSC--> 'Lets<!--DVFMTSC--> Talk<!--DVFMTSC--> About<!--DVFMTSC--> %s'<!--DVFMTSC--> ),<!--DVFMTSC--> ''<!--DVFMTSC--> .<!--DVFMTSC--> single_cat_title(<!--DVFMTSC--> '',<!--DVFMTSC--> false<!--DVFMTSC--> )<!--DVFMTSC--> .<!--DVFMTSC--> ''<!--DVFMTSC--> );?></h3>
<!<!--DVFMTSC--><!--DVFMTSC--><!--DVFMTSC--> I'm<!--DVFMTSC--> hard<!--DVFMTSC-->−coding<!--DVFMTSC--> part<!--DVFMTSC--> of<!--DVFMTSC--> the<!--DVFMTSC--> url<!--DVFMTSC--> parameter<!--DVFMTSC--> for<!--DVFMTSC--> Facebook<!--DVFMTSC--> based<!--DVFMTSC--> on<!--DVFMTSC--> my<!--DVFMTSC--> permalink<!--DVFMTSC--> structure<!--DVFMTSC--> for<!--DVFMTSC--> category<!--DVFMTSC--> archives,<!--DVFMTSC--> then<!--DVFMTSC--> adding<!--DVFMTSC--> the<!--DVFMTSC--> actual<!--DVFMTSC--> category<!--DVFMTSC--> slug<!--DVFMTSC--> with<!--DVFMTSC--> php.<!--DVFMTSC--> <!--DVFMTSC--><!--DVFMTSC-->−>
<iframe<!--DVFMTSC--> src="<?php<!--DVFMTSC--> if<!--DVFMTSC--> (is_category(<!--DVFMTSC--> ))<!--DVFMTSC--> {
<!--DVFMTSC--> <!--DVFMTSC--> $cat<!--DVFMTSC--> =<!--DVFMTSC--> get_query_var('cat');
<!--DVFMTSC--> <!--DVFMTSC--> $yourcat<!--DVFMTSC--> =<!--DVFMTSC--> get_category<!--DVFMTSC--> ($cat);
<!--DVFMTSC--> <!--DVFMTSC--> echo<!--DVFMTSC--> $yourcat<!--DVFMTSC-->>slug;
<!--DVFMTSC--> }<!--DVFMTSC--> ?>&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80"<!--DVFMTSC--> scrolling="no"<!--DVFMTSC--> frameborder="0"<!--DVFMTSC--> style="border:none;<!--DVFMTSC--> overflow:hidden;<!--DVFMTSC--> width:450px;<!--DVFMTSC--> height:80px;"<!--DVFMTSC--> allowTransparency="true"></iframe>

That’s it. Quick and easy.

About Brandon Cox

Pastor at Saddleback. Church Planter Editor of Communications Thinker & Web Designer. Love Jesus, @angiercox, & kids!

Tags: categories, facebook, facebook like button, hacks, like button, tips, tricks, wordpress


This Post Has 5 Comments

  1. Matt says:

    I’m trying to figure out exactly where/how I edit this code on my site. It looks like the last WP update too away my “edit” link on the dashboard. Suggestions?

    • Brandon Cox says:

      Matt, your question prompts me to make a couple of edits to my article. This code would actually need to be added to the theme file named category.php. If category.php doesn’t exist in your theme files, it would need to go in either archive.php or index.php within conditional tags. I’m afraid it can’t be added to your posts and function properly.

      If you’re looking to add a Like button to posts, I’d suggest using a plugin. Under Plugins in your dashboard go to “Add New” and search for Facebook Like Button or my own favorite – Digg Digg.

  2. Matt says:

    Thanks for the quick response! I’ll look for those php files and make the adjustments.

  3. Okay…I want to share my experiences with the “Like” button. I added one to one of my sites a few weeks ago, it’s gotten some votes, but has not really changed how many hits the site gets or signups or activity. I guess it helps people connect with it on Facebook, but other than that doesn’t seem to confer any benefit.

    • Brandon Cox says:

      The benefits of the “like” button are threefold: 1. It’s quick to hit – just one click and Facebook puts the link, image, and excerpt on the “liker’s” wall. 2. It adds weight to the “relevance” of your page when people search for something on Facebook. So when your friend Bob is searching for Warrior Cats, if his friends Suzie and Henrietta both like your page, he sees your page in the search results even if he’s never liked it. and 3. Only 14% of Americans trust ads, but 78% trust the recommendation of a friend.

      (All names are fictitious.) :)

Leave A Reply

Have you Subscribed via RSS yet? Don't miss a post!