We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Feathers

Getting results URL in title

I have a filter form on my website which filters job type and location. How can I get the result page title to display like below:

Showing results for: Building Services in Cheddar

This is my URL of the results page: /results.php?type=Building+Services&location=Cheddar

James Tedder

James Tedder 0 points

  • 3 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

For similar stuff, I've used perch_get() and perch_page_attributes_extend(). So, at the top of your page:

$type = perch_get('type');
$location = perch_get('location');

perch_page_attributes_extend(['pageTitle' => 'Showing results for: ' . $type . ' in ' . $location]);

Thanks for the reply. Not sure I follow this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which part don't you understand?

Duncan Revell

Duncan Revell 78 points
Registered Developer

This code is needed in your results.php page - perch_get() gets the arguments from the url (in your case, type and location). You can then use those variables to dynamically update the title for the page - using perch_page_attributes_extend(). Passing the string to pageTitle essentially "overwrites" the value that may already have been set for the results.php page title.

Check out the docs for both functions for further examples (I think).

sorry my fault. I didn't mean the page title. I meant the title on the page above the results.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. Does that answer your question then?

Sorry, not really. What would I put between the <h1> tags on my page to show the two key terms the page is showing the results for?

Duncan Revell

Duncan Revell 78 points
Registered Developer

Referring back to my first post, you have the values from the url stored in $type and $location - use those to build a string and plonk it between the h1 tags. Job's a good 'un.

sorry? build a string?

I am not to good with php language. please can you help with the code I would need?

Duncan Revell

Duncan Revell 78 points
Registered Developer

James. It turns out I was happy to give you an answer in my first post, so I should be equally happy to provide you with an answer in this post.

However - (this is just an opinion of mine) - that kind of bypasses the fun in learning why the answer you've been given is the answer. As it turns out, the code/string you need is in my first post - I'm passing a string to an array item called 'pageTitle'. You could use that same string in your code as follows (concatenating, or building, a string):

<h1><?php echo 'Showing results for: ' . $type . ' in ' . $location; ?></h1>

However, there's loads of ways of doing the same thing, depending on your coding preferences and/or style. Doing a Google search for "php build string with variables" will show most ways (along with a good smattering of angry internet people who will argue their way is THE BEST). Assuming you're storing the url values in variables as per my first post, you could do:

<h1>Showing results for: <?php echo $type; ?> in <?php echo $location; ?></h1>

Or if you don't want to use variables, just do:

<h1>Showing results for: <?php echo perch_get('type'); ?> in <?php echo perch_get('location'); ?></h1>

Actual apologies for the (unintentional) sanctimonious tone and general waffle.

Thank you, thank you... that's perfect.

It makes perfect sense when I see the code, but unless you know the correct php terminology it can be hard to google the function I need.

Cheers :-)