Forum

Thread tagged as: Question, Runway, Blog

Does a category set have still have to be called 'blog' to work with the Blog ap...

Hi

I'm trying to get a category archive page working with a multi-blog, but I'm not having much luck.

After a quick search in the forum I found a post I wrote last year.

I was experiencing a similar problem then as I am now.

My blog category archive pages are working, but my news category pages aren't.

My blog category setup:

       <perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes">

And my news category setup:

         <perch:categories id="newsCategories" set="news" label="Categories" display-as="checkboxes">

At the bottom of the previous post I asked:

Does the category set have to be called 'blog' to work with the Blog app?

Drew replied:

Yes it does - that's what you just proved by changing it and breaking the functionality, then changing it back and it all working again.

  1. Is this still the case?
  2. Do all my categories for each individual blog need to be in the same category set?

Diagnostic Information

  • Perch Runway is up to date (2.8.19)
  • PHP 5.6.10 is up to date
  • MySQL 5.5.42 is up to date
  • Image processing available
Stephen Meehan

Stephen Meehan 4 points

  • 5 years ago

Sorry, I've just checked the documentation

A blog can have its own dedicated post template, category set, and additional fields can be added in the blog/blog.html template.

Hmmmm... I'll have another look over the templates I've made - try to find out what's going wrong...

Drew McLellan

Drew McLellan 2638 points
Perch Support

The default is called blog. If you don't use that you need to make sure you give the correct category path when filtering by category.

Thanks Drew

Here's the solution:

In archive.php add the category path like this: 'category' => 'news/' . perch_get('cat')

                /* --------------------------- POSTS BY CATEGORY --------------------------- */
               if (perch_get('cat')) {
                echo '<h1>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>';

                perch_blog_custom(array(
                        'category'   => 'news/' . perch_get('cat'), // Add the category path here
                        'template'   => $template,
                        'count'      => $posts_per_page,
                        'sort'       => $sort_by,
                        'sort-order' => $sort_order,

                        ));

                $posts_displayed = true;
            }

The code above displays the archived posts for the blog called news, but it's not displaying the category name in the Archive of title

'<h1>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>'

How would I display the news category title here?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If cat is a slug, you need to turn it into a category path.

'news/'.perch_get('cat')

If cat is a slug, you need to turn it into a category path.

Is this in relation to my first post?

I can display the archived posts of the news blog.

I'm having trouble with displaying the category title on the archive page. I can display the category slug using this:

   echo '<h1>Archive of: '.perch_get('cat').'</h1>';

Perch Screenshot

But I really need to output the title.

If the blog isn't called blog (in this case it's called news) how do I include the name of the category in the Archive of title?

   echo '<h1>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>';

Solved

I used this in my post_in_list.html template:

   <perch:before>
      // Add perch:categories to display the current CatTitle
       // Make sure to wrap in a perch:if, otherwise this will show on the blog home page (assuming you use the same post_in_list.html template)
   <perch:if exists="url_cat">
  <h1>Archive of: <perch:categories id="newsCategories" set="news" ><perch:category id="catTitle" type="text" />  </perch:categories></h1>
   </perch:if>
   <ul class="hfeed listing"></perch:before>
    // ... rest of template removed to keep this short!

In archive.php I deleted echo '<h1>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>';

         /* --------------------------- POSTS BY CATEGORY --------------------------- */
            if (perch_get('cat')) {
                echo '<h1>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>'; // deleted this

Perch Screenshot

Ta-Dah! :)

Thanks for this! I was struggling with the same situation. Most sites I create use the blog as News sections so I don't like the phrase blog...

Ooh, I am so close on having this set up properly, following Stephan's code from above.

I ended up making a "post_in_category_list.html" template instead of using the perch:if conditional above. So my code in the template looks like this:

<h1>Archive of: <perch:categories id="categories" set="news" ><perch:category id="catTitle" /> </perch:categories></h1>

The only trouble I'm having is that if a post has more than one category assigned, they both show up in the h1 element.

So, if I have categories Blue and Green, and 5 posts categorized as Green, and one of those also is categorized as Blue, and I go to "archive.php?cat=green", the h1 reads: "Archive of: Blue Green".

I'm really not sure how to go about getting just the one category title ("Green" in the above example) that I want in the h1. Can anyone help point me in the right direction?

Hi Laura

If you need to output the title of the category, use this solution instead.

I found the default archive template outputs the category title fine, as long as your blog is called blog. But you hit a problem when you have a second blog, that isn't called blog. I had a blog called DIY tips. Hopefully, the link above will help. Good luck!

Oh that's perfect! Thanks so much for the pointer!