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 2019-03-19 01:50:15

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Target Specific Pages in PHP

Hi Folks,

been a while!

Could someone please remind an old man how to target specific pages in PHP?

Used to go somewhat like:  if (G_PATH == 'HOME') {

But had no joy with that.....


Jon

Offline

#2 2019-03-19 06:51:22

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

Re: Target Specific Pages in PHP

Have a look at how I did this in Backlight: http://community.theturninggate.net/vie … hp?id=8429

For BL2, the call to page_match needs to be updated as follows:

	if ( $this->page_match('/about') ) {
		echo '....';
	} elseif ( $this->page_match('/contact') ) {
		echo '....';
	} elseif ( $this->page_match('/galleries/') ) {
		echo '....';
	} elseif ( $this->page_match('/backlight/search') ) {
		echo '....';
	}
}

And the example function ttg_main_top( $style, $path ) is now main_top() in BL2.

Last edited by Daniel Leu (2019-03-19 06:56:15)


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

Offline

#3 2019-03-19 17:41:01

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Re: Target Specific Pages in PHP

Thanks Daniel,

Top man!

Offline

#4 2019-03-19 18:25:51

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Re: Target Specific Pages in PHP

OK,

that worked brilliantly for every page on my site, now how do I get it to target the Home page! I've tried '/home', '/Home', 'home', '/', etc. etc.

What am I missing this time?

Offline

#5 2019-03-19 22:10:58

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Re: Target Specific Pages in PHP

Sorted Now thanks.

Offline

#6 2019-03-19 22:23:39

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

Re: Target Specific Pages in PHP

Just curious, what was the solution?


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

Offline

#7 2019-03-19 23:39:39

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

Re: Target Specific Pages in PHP

lofty wrote:

Thanks Daniel,

Top man!

smile


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

Offline

#8 2019-03-20 00:44:00

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Re: Target Specific Pages in PHP

Hi Rod,

hope you are well. Long story, thought I had the Answer, which was using: if ( $this->page_match("/")...

However, this worked on the Home page - and all the others too! Doh! So it wasn't the answer at all.

I found that if I just used - echo $_SERVER['REQUEST_URI']; it showed the url returned for the pages ie. /about/ and /contact/ for the about and contact pages. The home page returned / (backslash). However, using '/' or "/" as the match worked on all pages.

Now I'm back to trying over to find the right escapes to the 'if' statement. using '/contact' only targets the contact page etc. Just doesn't work on the home page.

Please, anyone chip in if you have any suggestions.

Offline

#9 2019-03-20 00:55:34

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

Re: Target Specific Pages in PHP

lofty wrote:

Hi Rod,

hope you are well. Long story, thought I had the Answer, which was using: if ( $this->page_match("/")...

However, this worked on the Home page - and all the others too! Doh! So it wasn't the answer at all.

I found that if I just used - echo $_SERVER['REQUEST_URI']; it showed the url returned for the pages ie. /about/ and /contact/ for the about and contact pages. The home page returned / (backslash). However, using '/' or "/" as the match worked on all pages.

Now I'm back to trying over to find the right escapes to the 'if' statement. using '/contact' only targets the contact page etc. Just doesn't work on the home page.

Please, anyone chip in if you have any suggestions.

Hi Lofty,

Using my page_match function, '/contact' selects all pages that start with '/contact'. This means that with /gallery, all your gallery pages are selected at once. That's how I use it. Since all pages start with '/', you can't use this to select the home page.

To select just the home page you might want to use:

	if ($_SERVER["REQUEST_URI"] == "/") {
		echo "home page";
	}

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

Offline

#10 2019-03-20 01:43:18

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Re: Target Specific Pages in PHP

That Definitely works Daniel,

many thanks again for your help

Offline

#11 2019-03-20 01:47:19

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

Re: Target Specific Pages in PHP

Just curious, what cool feature are you adding to your site?


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

Offline

#12 2019-03-20 02:26:03

lofty
Member
From: UK
Registered: 2012-09-26
Posts: 259
Website

Re: Target Specific Pages in PHP

Well,

not new just yet Daniel, doing what I meant to do as advised by Matt some time ago. I have a grid of static links to Galleries and also the latest two Blog Posts. It's been there a while and works well but the html was just in the page copy. So I'm trying to move that code into the php.

Stage 1 completed, thank you. Stage 2 is to get the existing php for the blog posts working. Which I will probably need some pointers on....

Once I have that sorted, I can do other stuff smile

Offline

#13 2019-03-20 03:39:50

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

Re: Target Specific Pages in PHP

There's a sample function in the latest phplugins-pangolin-sample.php file that calls blog posts. It starts at line 561.


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