Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 03:27 pm EDT

Geeklog Forums

Adding a +1 button


Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
I wanted to add a Google +1 button to one of my sites. The instructions are easy enough but I thought a little writeup can't hurt.

The theme I'm using is loosely based on the Professional theme, so it has the story icons (email, printer, edit option) next to the story title. That seems like a good place to put the +1 icon as well. There's a small version of the icon which fits there just fine.

Step 1: In storytext.thtml, featuredstorytext.thtml, and archivestorytext.thtml, add a new template variable "plus_one":
Text Formatted Code
<div class="story">
    <span class="story-icons">
        {email_icon}
        {print_icon}
        {edit_icon}
        {plus_one}
    </span>


Step 2: To populate that variable, we need a small snippet of code in lib-custom.php. Find the function CUSTOM_templateSetVars, make sure it's not commented out(!), then add this piece of code:
Text Formatted Code

function CUSTOM_templateSetVars($templatename, &$template)
{
    case 'storytext':
    case 'featuredstorytext':
    case 'archivestorytext':
        if (strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
            $template->set_var('plus_one', '<g:plusone size="small"></g:plusone>');
        }
        break;
    }
}
 

This makes sure that the +1 button only appears on the article page but not on the index pages.

Step 3: If you're using Geeklog 1.8.0, add this new function to your lib-custom.php (see below for instructions for older Geeklog versions):
Text Formatted Code

function CUSTOM_getfootercode()
{
    $retval = '';

    if (strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
        $retval = '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
    }

    return $retval;
}
 

On Geeklog 1.8.0, you're already done now. Check your article pages for your shiny new +1 button.

Step 4: (Geeklog versions prior to 1.8.0 only) We need to introduce another template variable. This time for the footer template. In lib-custom.php again, add this piece of code to the CUSTOM_templateSetVars that you just edited in Step 2:
Text Formatted Code

    case 'footer':
        if (strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
            $jsplus = '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
            $template->set_var('plus_js', $jsplus);
        }
        break;
 


Step 5: (Geeklog versions prior to 1.8.0 only) Now we need to add the new "plus_js" variable to the theme's footer.thtml file. Put it right before the closing body tag (and leave the rest of the file as it is):
Text Formatted Code

{plus_js}
</body>
</html>
 

And now the +1 button should appear in your articles.

Happy +1ing.

bye, Dirk
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
:shakehands: Thanks for this tutorial.

Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EDT. The time is now 03:27 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content