Forum

Thread tagged as: Problem, Error, Blog

Blog Categories Issue

Hello,

I'm using Perch with URL rewrite on a project and all seems to be working well except for categories. I have Archive by Date & Month links and they are working fine, so I know the archive page and rewrite rules are working, but when it comes to categories, my page will load but has no results listed, for example my page heading reads as "Archive of: (nothing here) " and the URL in my address bar is https://jlmarsh2015.dev/news/category/announcements. I do have my blog pages in a root-level folder called "News" and my post page path under Settings is set to /news/{postSlug}. I followed the video tutorial for "Simple URL Rewriting" and here is my htaccess file (had to reorder a few before I could get them to all work):

<IfModule mod_rewrite.c>
RewriteEngine on

# Rewrite Blog Date Archive URLs
RewriteRule ^news/date/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /news/archive.php?year=$1&page=$2 [L]
RewriteRule ^news/date/([a-zA-Z0-9-/]+)-([a-zA-Z0-9-/]+)$ /news/archive.php?year=$1&month=$2 [L]
RewriteRule ^news/date/([a-zA-Z0-9-/]+)$ /news/archive.php?year=$1 [L]

# Rewrite Blog Post, Tag, Category, Preview URLs
RewriteRule ^news/([a-zA-Z0-9-/]+)/preview$ /news/post.php?s=$1&preview=all [L]
RewriteRule ^news/category/([a-zA-Z0-9-/]+)$ /news/archive.php?cat=$1 [L]
RewriteRule ^news/tag/([a-zA-Z0-9-/]+)$ /news/archive.php?tag=$1 [L]
RewriteRule ^news/([a-zA-Z0-9-/]+)$ /news/post.php?s=$1 [L]

# Redirect to PHP if it exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

</IfModule>

Now I turned on debug and after reviewing the query's for my categories, I noticed these two lines:

[1] SELECT * FROM perch2_categories WHERE catPath='blog/announcements/' LIMIT 1
...
SELECT setID FROM perch2_category_sets WHERE setSlug='blog' LIMIT 1

...and I was wondering if when I create the categories for my blog in the Category App, does the set need to be named "Blog" or can I use "News"?

Because I see the query searching for catPath='blog/announcements' and In my Categories App, I created a set named "News" (I have no Blog set), so shouldn't that be catPath='news/announcements' instead? In my post.html template I have the following where you can see the set is news, not blog.

<perch:categories id="categories" set="news" label="Categories" required="true">
            <a href="/news/category/<perch:category id="catSlug" type="slug" />" class="p-category"><perch:category id="catTitle" type="text" /></a><perch:if exists="perch_item_last"><perch:else/>, </perch:if>
</perch:categories>

This field displays the correct category set and the categories selected are displaying and listed with each post, but upon clicking on a category link from any post, I get the same page I mentioned above with no results displayed even though the URL looks correct and the rewrite rule is working properly. I also tried changing my url to: https://jlmarsh2015.dev/news/archive.php?cat=announcements, but same results.

My post.php page is using the default blog function <?php perch_blog_post(perch_get('s')); ?> and here is my diagnostics report:

Perch: 2.8.31, PHP: 5.4.16, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: e707c415db32080b3752b232487a435ee0372157 $, with PDO
Server OS: WINNT, apache2handler
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_events (1.9.3), perch_gallery (2.8.6), perch_blog (5.0)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_events', 'perch_gallery' );
PERCH_LOGINPATH: /cms
PERCH_PATH: C:\xampp\htdocs\jlmarsh2015\cms
PERCH_CORE: C:\xampp\htdocs\jlmarsh2015\cms\core
PERCH_RESFILEPATH: C:\xampp\htdocs\jlmarsh2015\cms\resources
Image manipulation: GD
PHP limits: Max upload 10M, Max POST 20M, Memory: 128M, Total max file upload: 10M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: marsh2015.dev
DOCUMENT_ROOT: C:/xampp/htdocs/jlmarsh2015
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php

Please let me know if you need any other info or the extended diagnostics report.

Thank you.

Joshua Rodriguez

Joshua Rodriguez 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think this is your question:

I was wondering if when I create the categories for my blog in the Category App, does the set need to be named "Blog" or can I use "News"?

By default the category set is Blog. You can use a different set if you wish, but to do so you need to make sure you then use full category paths rather than just the slug. If you use just the slug, the default set will be assumed.

Drew,

Thanks and yes that was the summary of my long question :)

I understand what you're saying, but can't quite wrap my head around how to do it.

So this is my category_link.html template:

<perch:before><ul class="list-unstyled"></perch:before>
    <li><a href="/news/category/<perch:category id="catSlug" />"><i class="fa fa-fw fa-circle-o"></i><perch:category id="catTitle" /> (<perch:category id="count.blog.post" when-empty="0" />)</a></li>
<perch:after></ul></perch:after>

and this is my htaccess file url rewrite for my news categories:

RewriteRule ^news/category/([a-zA-Z0-9-/]+)$ /news/archive.php?cat=$1 [L]

How would I need to modify these?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The only thing this pertains to is how you filter posts by the category.

If your rewrite rules aren't working, that's something you'll need to work on. We have routing in Perch Runway to make that process easier - that's our supported solution for URL rewriting.

Thanks Drew, I think I understand.

I have used Runway on several projects and agree that it is by far much easier to customize using routes, but I still have a few clients who are using Perch and I know something like this is possible. I've just struggled a bit with trying to figure out how because once I think I have a way to do it, I realize "oh wait...that's Runway."

What I wanted to accomplish in the end was to avoid confusion for my client in case they wanted to add categories for their News section.

I reviewed another project where I had done this with no problem and realized I had used the indelible="true" attribute on the setSlug field. So I was able to change the Category set Title to "News", but keep "blog" as the slug. Everything is working fine now.

One last question, would the process from the "Portfolio with Categories" video be a reference I could apply to my original question and the approach for "full category paths"?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, I believe so. That should work fine.

Ok great. Thanks again for all your help!