Forum
Dynamic blog slug with multiple blogs
I've got multiple (two) blogs and I want to use the same date/tags/cats templates for them both. The href was /blog/category/<perch:category id="catSlug" />
, which worked fine for my blog when it was just one blog. But now that I've got another blog ('resources') I need the /blog/
bit to be /blog/
when on the 'blog' blog and /resources/
when on the 'resources' blog. If that makes sense :P
I've tried using <perch:blog id="blogSlug" />
but it doesn't return anything. Can you see what I'm doing wrong?
Thanks for taking a look :)
Martin.
It should do. What does
<perch:showall />
show you?Ah good shout. It only returns
setID
… Is there some way of hooking that up to the set's slug value?Hmm, yes, I see the dilemma. Do you know from the page which blog you're displaying?
I think so, yeah. It's in the URL.
<?php perch_page_url(); ?>
returns 'https://tempertemper.local/resources'. Is there a way of just getting the 'resources' bit?Is this Perch or Runway?
Runway
Do you see the value at the top of the debug?
Here's my debug from the page:
Any clues?
It looks like it's going directly to a page called
resources
- is that right?Yep, it's the 'resources' blog (as opposed to the 'blog' blog). If I did the same with the 'blog' blog, it would say 'blog' rather than resources. The pages listing in the control panel looks roughly like this, if that helps:
I think in future we'll add a way to retrieve all the URL segments, but for now you'll need to use a bit of PHP to do it.
Makes sense. So is
perch_page_path
the way to go? Actually, wouldn't I run into bother when I return categories on /resources/post or /resources/archive (or /blog/post or /blog/archive)? My php chops aren't particularly special…Yes,
explode()
the path on/
and take item 1.Hi Drew, I'm wrestling with the explode thing and can't get it working. I'm doing this on the page:
But neither
<perch:blog id="category_link" />
nor<perch:blog id="category_link" />
returns the variable inside the category_link.html template. Can you see what I'm doing wrong?Maybe it's better I just hold out for a blog release with the way to retrieve the category set slug. It's not pressing that I need multiple blogs – I was just trying to wrap my head around it with my own blog. That said, it would still be really useful :)
Actually, in the meantime I guess I could duplicate the category, tag and date default templates, change
blog
toresources
and define the new templates in theperch_blog_categories
,perch_blog_tags
andperch_blog_date_archive_years
arrays.Uh oh, I can't do it with the 'resource' blog's categories cos of that bug. I'll hold off for now :)