Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2017-11-21 05:42:39

peter
Member
Registered: 2012-09-26
Posts: 271

Can some code be added to a gallery?

I may need to add a javascript to some galleries.
It is for page stats. Tells me if a customer has viewed an album.

Offline

#2 2017-11-21 05:54:50

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Can some code be added to a gallery?

You can add page copy to an album via Lightroom (edit album > page content) but I don't know what would happen if you tried to insert HTML via that route.

Offline

#3 2017-11-21 06:25:07

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Can some code be added to a gallery?

I would use phplugins to do this. Otherwise, you can get page statistics from Google Analytics too.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#4 2017-11-21 06:27:55

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Can some code be added to a gallery?

I think phplugins will apply to every gallery and not really show if a particular person has viewed a particular gallery?

Offline

#5 2017-11-21 06:59:57

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

If you want to try adding javascript, I suggest creating a test album for it.

Try putting the script in the page copy and see what happens. Can't really hurt.

But I'm also guessing the phplugins route might be needed. Does this script tell you what url is visited? I'm guessing it reports back on the page that the script is living in. So hopefully you'd get reports back for each album you place the script in.

The phplugins route:

To make sure that the script is run in only the albums you want it run in, first create a new page (not album) template. In this template you'll activate phplugins from the Advanced Setup section.

Create the phplugins file you'll need. Documentation on how to use it is here: http://backlight.theturninggate.net/doc … _phplugins
in the backlight/custom/phplugins folder you'll find several sample files. You can use any of them, you just won't be using the functions within them.

Create your own function using any of the existing ones as a guideline. Be sure to do all your work in a plain text editor.
I'd suggest inserting the script into the page by using the ttg_scripts hook.

Once you've done this, upload the saved file (I'd name it something that makes it unique from the other files, like jenkins.php) to /backlight/custom/phplugins/

Go back into Backlight, to your new page template, and active phplugins in the Advanced Setting section. Choose your new file and save the template.

Now clone your album template and give it a name that makes sense, like tracking-script-album-template.
Assign the page template you created to this new album template.
Assign the album template to the albums that need tracking. Each album to which that template is assigned will have the script in it.

Is this a javascript or jQuery script?

Anyway, if you need help forming the function in the phplugins file, post the script here and one of us will give it a go.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#6 2017-11-21 07:40:03

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

That's a bit of work, and right now, I have to stop working on this and get back to my regular life!
Thanks for the suggestions. I have the jscript on the main pages for now.
Peter

Offline

#7 2017-11-21 08:03:48

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Can some code be added to a gallery?

Rod's instructions are clear and straightforward.

Offline

#8 2017-11-21 08:11:09

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Can some code be added to a gallery?

charlie.choc wrote:

I think phplugins will apply to every gallery and not really show if a particular person has viewed a particular gallery?

As Rod pointed out, you can have a phplugins file for a specific template. Or, what I do, check the location/name of the gallery served and only execute your tagging code when needed.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#9 2017-11-21 08:12:52

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

peter wrote:

That's a bit of work, and right now, I have to stop working on this and get back to my regular life!
Thanks for the suggestions. I have the jscript on the main pages for now.
Peter

Hmm. I don't see it showing up in any of the pages. Have you tried placing it yet?


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#10 2017-11-21 08:16:57

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Can some code be added to a gallery?

I understand you can have multiple page templates with different phplugins files, I just wasn't sure that what he was looking for rather than do things differently on an individual album by album basis. And I wasn't sure you could get the album name in phplugins. Live and learn.

Offline

#11 2017-11-21 08:19:38

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

I placed it in Tray 01 Copy. Thought that would be ok. I'll move it to the Page copy.
Actually, what are the Tray's used for?

Offline

#12 2017-11-21 08:24:55

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

Ben wrote:

Rod's instructions are clear and straightforward.

Yeah, but based on past experiences with my page design issues, are you sure you want me messing around again... smile

Offline

#13 2017-11-21 08:38:50

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

Trays are basically the same as sidebars. In a two-column Layout you'll have a sidebar on the left or right, depending on where you place a tray.
In mobile views, a tray is used to house your navigation.
If you place text in a tray in you page, but you're using a one-column layout, nothing will appear on the page. Same with placing code in a tray. If it's in a one-column layout, it won't be used.

Give it a try. Create a new page template using two or three columns and assign the trays where you want them. Then create a page using the template. You'll quickly see what the trays are for.
And there is some neat things you can do with, like having vertical navigation on the desktop, place affiliate ads, place call-to-action buttons. all sorts of things.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#14 2017-11-21 08:39:04

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

peter wrote:
Ben wrote:

Rod's instructions are clear and straightforward.

Yeah, but based on past experiences with my page design issues, are you sure you want me messing around again... smile

Hah! smile


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#15 2017-11-22 08:21:44

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

Alright, I followed the instructions, and i have set up templates all ok.
The part that is not clear, is how I use the script in the phplugins file.
I have this:

<?php

function ttg_scripts( $style, $path ) {   

    <script type="text/javascript">
document.write('<div align="center">');
var sc_project=7247521;
var sc_invisible=1;
var sc_security="8a4441b8";
var scJsHost = "http://www.";
document.write("<sc"+"ript type='text/javascript' src='" + scJsHost + "statcounter.com/counter/counter.js'></"+"script>");
document.write('</div>');
</script>

    }    //END

?>


but I am getting am error when I acces the page:

Something went wrong

Unexpected error: syntax error, unexpected '<' in my_phplugins.php on line 11

Please report error at http://community.theturninggate.net

So... help?

I edited the file to show all of it, so the line number of the error is different now, but same error place, at start of the <script

Last edited by peter (2017-11-22 08:30:05)

Offline

#16 2017-11-22 08:37:23

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Can some code be added to a gallery?

you need to enclose the code within the function with

echo '

... code here ...

';

Offline

#17 2017-11-22 08:41:09

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: Can some code be added to a gallery?

peter wrote:

<?php

function ttg_scripts( $style, $path ) {   

    <script type="text/javascript">
document.write('<div align="center">');
var sc_project=7247521;
var sc_invisible=1;
var sc_security="8a4441b8";
var scJsHost = "http://www.";
document.write("<sc"+"ript type='text/javascript' src='" + scJsHost + "statcounter.com/counter/counter.js'></"+"script>");
document.write('</div>');
</script>

    }    //END

?>

It's just as the error states. This code is not valid PHP and is generating a "syntax error."

The file to be used with PHPPlugins is a .php file, and as such should have <?php at the top and then end with ?>. The functions that appear within the php file should not repeat this.

The other error is the <script> and </script> tags.

There's another problem with this code, such as where are you expecting the output on the web page?


I can guess that you're trying to include http://statcounter.com/ but for what purpose?

If you simply want to know how many visitors, you could probably just get all this done with Google Analytics.  Maybe there's something else you're looking for.

I found there's a simple way to install that code, as documented here:  http://statcounter.com/support/knowledge-base/14/


Also note that if you install the code into Backlight's PHPPlugin, then you won't have it in your WordPress pages. If I recall you are also using WordPress, so if you want to track WP pages then you'll need to add the code there too.


--Jim

Offline

#18 2017-11-22 08:48:22

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

I prefer the statcounter because it lists the ip addresses.
The other stuff you mention, is all new to me, so I will have to research it more - I was under the impression that this is how a java script was added.

Offline

#19 2017-11-22 08:57:39

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: Can some code be added to a gallery?

peter wrote:

I was under the impression that this is how a java script was added.

Can you show us the original code you were provided. Then we can show you how to add it to PHPPlugins.

It's also important to know where the code should be added. In the wrong place it can slow your web site.

And this only gets you the statcounter on your Backlight photo pages. You'll need another method to get this on your WordPress pages, assuming you want to track those as well.


--Jim

Offline

#20 2017-11-22 09:06:40

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

peter wrote:

I prefer the statcounter because it lists the ip addresses.
The other stuff you mention, is all new to me, so I will have to research it more - I was under the impression that this is how a java script was added.

I saw that you had added it to the page content area yesterday. The script showed up in the page source code. We’re you expecting something to appear on the page as well? On your site, the div in the code is stuck inside the <script> tag and won't show on the page.
and that div in the code iss using deprecated html (which means you probably should be looking for more up to date code)


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#21 2017-11-22 09:20:12

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

Just on the road right now. The code is on regular pages and works fine. Today I decided to look in to adding it via hooks to albums. I followed the info on using with albums as above. Will investigate later...

Offline

#22 2017-11-22 09:27:09

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

You missed a few steps I think. You'll also need to escape any single quotes in the code (place a backslash in front of them: \'

If you go the phplugins route, try this. I've escaped the single quotes:

function ttg_scripts( $style, $path ) {   
	echo'
    <script type="text/javascript">
document.write(\'<div>\');
var sc_project=7247521;
var sc_invisible=1;
var sc_security="8a4441b8";
var scJsHost = "http://www.";
document.write("<sc"+"ript type=\'text/javascript\' src=\'" + scJsHost + "statcounter.com/counter/counter.js\'></"+"script>");
document.write(\'</div>\');
</script>
';

    }    //END

I left the divs in there, though I don't know that they're actually doing anything (but I did remove the invalid html)

this code needs to go into a php file. Use one of the sample files found in your backlight download at backlight/custom/phplugins and place it in the User area (below line 214)


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#23 2017-11-22 09:36:25

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

As Jim mentioned, Google Analytics is probably the way to go if you just need information and you don't need one of those super annoying stat counters on an otherwise classy looking site </sarcasm>. Google analytics can give you all sorts of data. Here's an article outlining just a few examples: https://blog.kissmetrics.com/awesome-google-analytics/

And the code is already in Backlight.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#24 2017-11-22 09:57:44

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Can some code be added to a gallery?

Hi Rod,
(Still out of office) Thanks for fixing it up. Looks like I was on the right path. This counter doesn't add any ugliest to the site, it just logs the info and displays the stats on their site. I will definitely look at other options and check out your link later. Since I've started the plugin, I do want to finish it so I can at least see it in action!

Offline

#25 2017-11-22 10:07:00

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Can some code be added to a gallery?

Chances are you'll kill your site the first time you try it (that's what often happens to me, anyway). Don't worry.
If that happens, just go to your page template and disable phplugins.
The problem is usually a syntax error: a missing semi-colon or curly brace or an un-escaped single quote mark.

try fixing the problem and re-uploading the file. Then enable phplugins in the template again and see what happens.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

Board footer

Powered by FluxBB