Forum

Thread tagged as: Question, Problem, Blog

No " Archive of " heading for blog categories -- changed catSlug to catPath to d...

I'm trying to set up an archive page for categories and sub-categories.

I see that in order to display the archive of sub-categories I must change id="catSlug" to id="catPath". I've made those changes to my category links everywhere, and the sub-categories now appear in an archive, however it has broken the "Archive of:" heading display.

I'm using the standard:

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

                    perch_blog_custom(array(
                            'category'   => perch_get('cat'),
                            'template'   => $template,
                            'count'      => $posts_per_page,
                            'sort'       => $sort_by,
                            'sort-order' => $sort_order,
                            ));

                    $posts_displayed = true;
                }

I've tried to pass in a few different arguments for:

'.perch_blog_category(perch_get('cat'), true).'

I've not had any luck getting the heading to populate with the proper category or sub-category title.

Thanks for the assist!

Olympia Kyriakides

Olympia Kyriakides 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the value of cat on your query string?

So it looks like when I use id="catSlug" it's cat=design (design being a parent category); this displays the parent title and post properly, but no sub-cat titles or posts.

0.0928  0.0055  SELECT * FROM perch2_categories WHERE catPath='blog/design/' LIMIT 1
0.0953  0.0025  SELECT DISTINCT idx.itemID FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' AND (idx.indexKey='_category' AND idx.indexValue LIKE 'blog/design/%' OR idx.indexKey='_category' AND idx.indexValue='blog/design/')

When I switch to id="catPath" (enabling display of both cat and sub-cat posts), it's cat=blog/design/interiors/

0.0967  0.0055  SELECT * FROM perch2_categories WHERE catPath='blog/blog/design/interiors/' LIMIT 1
0.0985  0.0018  SELECT DISTINCT idx.itemID FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' AND (idx.indexKey='_category' AND idx.indexValue LIKE 'blog/design/interiors%' OR idx.indexKey='_category' AND idx.indexValue='blog/design/interiors')

I get the sub-cat posts but no titles. If just delete "blog/" from the string in the browser the sub-cat title shows up, but with no posts.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Instead of perch_blog_category try perch_category.

Thanks Drew, this will work.

With echo '<h1>Archive of: '.perch_category(perch_get('cat'),true).'</h1>'; the category and sub-category posts come in properly, but the cat / sub-cat titles come in above, not in line with, the "Archive of:" header.

Figured that's because these cat titles are now controlled by perch/templates/categories/category.html.

I created a new template blog_cat_archive.html in perch/templates/categories/. I copied the default category.html template located there, but I stripped the container elements (ul li h4) so the output is just the category title. This seems to fix the issue. I'm getting the posts, and titles where they should be (inline with "Archive of:")

This is the new code and template:

/* --------------------------- POSTS BY CATEGORY --------------------------- */
                if (perch_get('cat')) {


                    echo '<h1 class="post-section-header">Archive of: '.perch_category(perch_get('cat'), array ('template'=>'blog_cat_archive.html',),true).'</h1>';

                    perch_blog_custom(array(
                            'category'   => perch_get('cat'),
                            'template'   => $template,
                            'count'      => $posts_per_page,
                            'sort'       => $sort_by,
                            'sort-order' => $sort_order,
                            ));

                    $posts_displayed = true;
                }
<perch:category id="catTitle" type="smarttext" label="Title" required="true"/>
    <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
    <perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" />