Multiple Blogs Split By Section - Can They Share A Page?

  • no, the perch code specifically looks for categories under a set called : blog.


    Here is the code that does that:

    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:

    Code
    1. <!-- CHOOSE A CATEGORY -->
    2. <perch:categories id="tags" label="Choose Category Tags" order="3" set="Blog" >
    3. <a href="/newsroom/category/<perch:category id="catPath" />" class="tag"><perch:category id="catTitle" /></a>
    4. </perch:categories>

    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:


    Code
    1. <!-- Category Tag -->
    2. <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
    3. <a href="/newsroom/category/<perch:category id="catPath" />" class="tag"><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></a>

    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.



    Quote

    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?


    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


    Code
    1. <perch:category id="catTitle" />

    which will simply just render the title... thats it.


    you render it with:


    Code
    1. perch_category('blog/' . $categorySlug, ['template'=> 'category_title.html']);



    Alternatively from your page (say it was in a h1 tag or something):


    Code
    1. echo "<h1>" . perch_category('blog/'.$categorySlug, ['skip-template'=>true], true)['catTitle'] . "</h1>";



    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:


    Code
    1. echo "<h1>" . perch_category('blog/'.$categorySlug, ['skip-template'=>true], true)[0]['catTitle'] . "</h1>";

    Note the [0] to specify the first item returned.

  • Not sure what you mean. You have /blog in the code. Is that something I should change? I thought that's baked-in?


    PHP
    1. <div class="header-text"><?php perch_category('blog/' . $categorySlug, ['template'=> 'category_title.html']); ?> Articles</div>

    Should say "Slug-Name Articles"

  • 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
    1. SELECT setID FROM cms1_category_sets WHERE setSlug='' LIMIT 1
    2. [nil]SELECT main.* FROM cms1_categories main WHERE 1=1 AND (catPath='blog/') ORDER BY catTreePosition ASC
    3. Using template: /templates/categories/category_title.html
    4. [0]SELECT setID FROM cms1_category_sets WHERE setSlug='' LIMIT 1
    5. [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:

    Code
    1. <perch:category id="catTitle" />
  • 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

  • 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....



    So 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.


    Code
    1. <div class="header-text">NAME-OF-THE-CATEGORY-TITLE Articles</div>
  • 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():


  • Success! That was the missing piece. Previous I had no results with....


    PHP
    1. <?php perch_category('blog/' . $categorySlug, ['template'=> 'category_title.html']); ?>

    But when adding....


    Code
    1. $categorySlug = perch_get('categorySlug');

    It finally makes the connection....

    PHP
    1. <?php $categorySlug = perch_get('categorySlug');perch_category('blog/' . $categorySlug, ['template'=> 'category_title.html']); ?>

    Thank you both JordinB and hus_hmd for all the help! I hope this last post helps someone make the same edit.