Ok, since my "blog" is called newsroom, shouldn't the set be "newsroom" with categories under it? I'm trying a test and not seeing results.

Multiple Blogs Split By Section - Can They Share A Page?
- dosa
- Thread is marked as Resolved.
-
-
no, the perch code specifically looks for categories under a set called : blog.
Here is the code that does that:
Code- if (isset($opts['category'])) {
- if (!is_array($opts['category'])) {
- $opts['category'] = array($opts['category']);
- }
- if (PerchUtil::count($opts['category'])) {
- foreach($opts['category'] as &$cat) {
- if (strpos($cat, '/')===false) {
- if (substr($cat, 0, 1)=='!') {
- $cat = '!blog/'.substr($cat, 1).'/';
- }else{
- $cat = 'blog/'.$cat.'/';
- }
- }
- }
- }
- }
So if you pass 'category' to the options, it loops over each category and will prepend 'blog' to the passed category. so if you pass: 'awards' from the query string through the 'category' option, the perch code will transform that to: blog/awards. So that path needs to exist in your categories.
-
Yay! You rock JordinB! Thank you for your diligence. I didn't know the "blog" Category name was hard-coded in Perch. I had renamed it to "newsroom" a while ago. Good to know.
So now I've got this:
1. Categories - a Set added called "Blog" with the "blog" slug and added a 'test' tag.
2. Changed the post.html call for the Categories to:
3. Opened a post, added the tag "test" to it.
4. Tried mysite.com/newsroom/category/test
Filter works
Finally!
One more question you might know - I'd like to now add a dynamic title for the tag. How do I display the name of the tag from the URL in the page?
-
Another question in displaying the Categories. In categories/category.html I have:
But the link is using the real path to the Category, and not just the slug portion....so its using: mysite.com/newsroom/category/blog/the-slug instead of the re-mapped link. Thoughts on how to remove the /blog part of the link?
-
Quote
i'd like to now add a dynamic title for the tag.
If i'm understanding, you'd like to display the category name that matches the slug "tag" ?
To do that you need to get the category from perch_category. Then either render a specific template or simply return the data and echo it in php.
QuoteBut the link is using the real path to the Category, and not just the slug portion....so its using: mysite.com/newsroom/category/blog/the-slug instead of the re-mapped link. Thoughts on how to remove the /blog part of the link?
Don't use the 'catPath', rather use the 'catSlug' in the url. Don't forget that you can use <perch:showall> in a template to see all the variables and values available to you within the template.
-
Ok, "catSlug" did it for the busted link. Thanks for the show:all tip - I always forget that one.
For the Category page - I just want to show the current Category the user is on. I see the options for perch_category, but my code isn't getting there. Is there a snippet to show the current Category 'catTitle'?
-
since you just have the slug, you'll need to build the category path, create simple template and do something like:
template: category_title.html
which will simply just render the title... thats it.
you render it with:
Alternatively from your page (say it was in a h1 tag or something):
but not sure if perch_category is going to return a 1 item indexed array...probably, i can't remember ... so in that case it would be:
Note the [0] to specify the first item returned.
-
Tried both, neither work
-
what is the path you're passing to perch_category?
pass these options and dump the output then post here so we can see: ['skip-template' => true, 'raw'=> true]
-
-
the /blog is baked in for the perch_blog functions not perch_category functions. does the value of $categorySlug match what you see in the cms for the category you're trying to pull ?
Also what is your category_title.html look like ?
-
With debug on, I can see the template. I see the catSlug is correct, but that's not because of the line above. When I add it in, debug shows:
SQL- SELECT setID FROM cms1_category_sets WHERE setSlug='' LIMIT 1
- [nil]SELECT main.* FROM cms1_categories main WHERE 1=1 AND (catPath='blog/') ORDER BY catTreePosition ASC
- Using template: /templates/categories/category_title.html
- [0]SELECT setID FROM cms1_category_sets WHERE setSlug='' LIMIT 1
- [nil]SELECT main.* FROM cms1_categories main WHERE 1=1 AND (catPath='/') ORDER BY catTreePosition ASC
The categories do live in the /blog/ path, so why isn't it working? Should blog/ be switched to newsroom/category/ ?
The category_title.html:
-
From that sql it doest look like the concatenation of the category slug is working being passed to the perch_category function.
to save some time guessing, can you please post your php file from the beginning up to that perch_category function call? If you don’t want to post it, you can email it to me:
jbrown [at] cognetif dot com -
Sorry I dropped the ball on this one. We launched the site anyway, so I am back to this tasks. I'll get that code to you soon. Thanks again for keeping this going.
-
hi JordinB (and maybe help from hus_hmd ) .....
I have picked this issue back up again and I'm not seeing a solution. What confuses me is that the page already has Category filtering working just fine....
PHPSo with that, shouldn't I be able to pull the name of the category it's displaying? I want to add it to the title of the page so it's clear what the user is filtering/viewing.
-
-
That's my question for you guys. I'm not sure how to output the title of the Category in that simple HTML I have ready for it. Looking for the snippet to use in place of the "NAME-OF-THE-CATEGORY-TITLE" placeholder.
-
What JordinB suggested sounds like it should work. From the debug message it shows you are not passing the category slug correctly. Make sure you assign a value to the variable $categorySlug before calling perch_category():
PHP- $categorySlug = perch_get('categorySlug');
- perch_category('blog/' . $categorySlug, ['template'=> 'category_title.html']);
- perch_blog_custom([
- 'category' => $categorySlug,
- 'cache' => false,
- 'count' => 12,
- 'sort' => 'postDateTime',
- 'template' => 'blog/post_in_column.html',
- 'sort-order' => 'DESC',
- 'paginate' => true,
- ]);
-