Forum
Shop page titles
Hi How do I make my product name or category name dynamically appear in the page title? I found information when using a blog post by setting <title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?></title> but can't seem to find an equivalent for the shop.
I'm using runway btw.
This is what I have..
Header.php
Categories layout
categorytitle.html
You're filtering using the category title - is that really what you have in the URL? Normally that would be the category slug or category path.
I think you probably want something like:
where the value of
s
on your URL is a path likeproducts/trousers
Something like 'products/trousers' or on the page I'm testing with 'greetings-cards/birthdays' is exactly what I want in my title.
I retrieve my url with
So is anything wrong in my html template. I've tried changing it also to catPath but no change.
I'm getting this in debug with both set to catPath
SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1 0 SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='') ORDER BY catTreePosition ASC nil
Have you tried hardcoding the path to identify whether the problem is that what you think is being passed in is not? As your debug shows that the path is not being passed in.
Ok I've gone back to my layout and tried to rework it as I was creating more and more pages to get to my sub pages with names like ' sub sub category ' which didn't seem right. I also had many else if perch get() statements in order to get me there in my category php.
This is probably why I couldn't access the link for my title. So i'm trying to rework it to be more dynamic but need a little help or explanation.
I now have this in my category page
That provides my links which open this on my product.php page
but I can only go one category deep. After that no products show. My routes are working ok as each link does open and debug shows it is loading my product list.html template. What am I missing in the code above?
Can you give us a sense of what your URLs look like? What pattern are you using to match the category paths? Does it account for multi-segmented paths?
Hi Just so you know, to better understand Runway and Shop I have downloaded and updated your nest run demo.
My links are like so
https://localhost/products/memberships/ This one shows content
https://localhost/products/memberships/passes/ This one shows no content
my routes are
category/[slug:s]
products/[slug:s]
products/[slug:cat2]/[slug:s]
products/[slug:cat3]/[slug:cat2]/[slug:s]
I have it set so it goes to products after the category listing page as that is the route from the set.
In the case of
are you piecing the path back together using
cat2
ands
?In my routes, yes
How about in your page? How are you reading those in?
It's like I showed above. I'm wondering if i'm missing a concept here.
I'm trying to make it so my client can create a new sub category or sub sub category or go as deep as they like and when they do the link will take them to the page. I am able to show these categories and make them links with paths. But is the reason nothing shows when I go as deep as category/membership/passes because a new sub category page for passes should be created by the client as well or can this be dynamically created with just one layout. I'm obviously trying for the latter but maybe thats where i'm going wrong.
I don't see you doing that above, which is why I'm asking.
I think you would be better to use a multi-segment token in your route so that you don't need to worry about how many levels of category you're dealing with.
Add a custom token (https://docs.grabaperch.com/runway/routing/custom-tokens/)
then use
and
I've done that, the links are still working but no products show. Here is my debug, hope it helps.
Ok, that looks promising. Can you show us the full code and you now have it?
Fixed - I still had perch_get('s') on my if statement but this is it for anyone else trying.
Thanks Drew I will be able to sleep now hopefully )
Still up. Ok to complete the original topic. Category name in page title..
I have this working fine with catpath but I want to grab the final part of the path, e.g. if it is more than one deep as in membership/passes I want to display just ' passes '.
can I just filter this or do I need a template?
Do you need the title of the category or its slug?
Title of the category.
this is what I now have
as before pretty much
also my template category title.html has just this
I think you'll want to change
to
Finally I have a working solution.
I was using perch categories instead of category and my code was the wrong way around. It would only pull in titles when I took off the
Phew, got to get this working with individual product display now.
Brilliant thank you for your patience )