Tag Cloud - Linked Tags To Search Blog Posts With That Tag

  • On Perch 2 vs Perch 3, I noticed blog details for "Tags" are now under the "Meta and Social" tab.


    I'm making a tag cloud of those tags linking to a search for articles with those tags. I can't find a Perch resource that shows the syntax for linking to this type of search. Right now, I'm doing this:

    Code
    1. <a href="/about/newsroom/archive.php?tag=<perch:content id="text" type="text" label="Tag" title="true" help="Enter the tag exactly, without spaces. Case sensitive." />" rel="tag" class="tag" ><perch:content id="text" type="text" label="Tag" help="Enter the tag exactly, without spaces. Case sensitive." /></a>


    Of course that leads to a 404 page. What did I miss?

  • Right. As you can see, my code is almost identical, but missing the tagSlug. That is because the CMS user will be adding the slug.


    But that just made me realize I think I have the link wrong. Now I tried it without the /archive.php and it worked! I don't know what template it's using to display the results, so I am hunting for that now. Looks to be using post.php ....but I'd rather have a custom template page for "tag searches" like this. Do you know what that is called?

  • The tag slug is generated by Perch after the user enters the tag on Meta and Social tab. is that not what you want?


    I'm not sure how your site is working because you are using <perch:content> tags in a blog context. I would normally expect to use <perch:blog>


    The archive.php example page that comes with Perch Blog has code for displaying tags in a list.

  • Thanks @clive - yes, it might be confusing at first, but I am letting the CMS editors create the tags (instead of displaying all of them) so they can control the "most popular" tags and prioritize what they want. So the perch:content is in a shared region. But the key is the linking.


    I thought it was working, but it actually is not. :( The page is blank using the post.php as its base.

  • Ideally you'd have 2 different category fields if you need the separation:


    HTML
    1. <perch:categories id="categories" set="blog" label="Categories" />
    2. <perch:categories id="tags" set="tags" label="Tags" />


    However, the category option in perch_blog_custom() only works for the Category Set blog. So you cannot filter by tags like so:


    PHP
    1. perch_blog_custom([
    2. 'category' => 'tags/test/'
    3. ]);


    Fortunately, you can use a normal filter instead:


    PHP
    1. perch_blog_custom([
    2. 'filter' => '_category',
    3. 'value' => 'tags/test/',
    4. ]);



    If you want to read more about category filtering: https://grabapipit.com/blog/category-filtering