Welcome to Geeklog Sunday, October 22 2017 @ 09:56 am EDT


Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/2002
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":
PHP 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:
PHP 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):
PHP 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:
PHP 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):
PHP Formatted Code

{plus_js}
</body>
</html>
 

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

Happy +1ing.

bye, Dirk

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/2005
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

All times are EDT. The time is now 09:56 am.

  • 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