Forum

Thread tagged as: Question, Problem, Error

Blog Issue With Posts

I am having some issues with a site (not sure when these started but perhaps after an update)

Perch: 2.7.2, PHP: 5.4.28, MySQL: 5.1.59, with PDO Server OS: Linux, cgi-fcgi

All posts appear to be fine in admin and display on the listing pages. However clicking an article only displays the heading. The url has this in the link:

/blog/1970-01-01-bedford-dentist-recognized-by-the-british-dental-association

Whats causing this? I tried creating an article from scratch and its still adding this weird date. I suspect this creation date is causing the issue but not sure how its got like that.

Nigel Coath

Nigel Coath 1 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is your post template missing a date field?

Okay that seems to have sorted the date and article display. Something else seems to have changed about the display I had set up for the category links. I think its connected with the release of the Categories app.

I have a list of Categories displayed in a sidebar to show the Categories with a count next to each showing quantity of articles e.g. Practice News (2). However I had to fiddle with this code to get it working again.

But two issues remain different.

  1. Instead of showing a count e.g. Practice News (2) its showing Practice News ()
  2. Previously even empty Categories displayed e.g. Industry News (0) but now they only display if they have articles.

Here is code:

<li><a href="?cat=<perch:category id="catSlug" />"><i class="fa fa-chevron-right"></i> <perch:category id="catTitle" /> (<perch:category id="qty" />)</a></li>

Also how do I display the url in this without the ?cat= as a clean url, I did this for posts in .htaccess

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The changes for category counts are as detailed in the documentation here: https://docs.grabaperch.com/addons/blog/installation/

qty needs to change to count.blog.post.

Just change the value of href to whatever is correct for your rewrite rules.

Thanks, I stumbled on the changes last night and got qty working.

However, previously even empty Categories displayed e.g. Industry News (0) but now they only display if they have articles.

Is there a way to restore this way of working?

This is the code I now have in my category links template:

<li><a href="?cat=<perch:category id="catSlug" />"><i class="fa fa-chevron-right"></i> <perch:category id="catTitle" /> (<perch:category id="count.blog.post" />)</a></li>

Finally these category links appear on the article detail page, but the url does not display the categories but changes to the url of the article its displaying on, how can I fix this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What should the URL be?

/news/?cat=practice-news

however on an article page its: /news/my_article_title/?cat=practice-news

Also even though I have the empty => true inside the listing and detail pages call to the links template its no longer showing empty categories (it did before).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so how about setting the link to that?

<a href="/news/?cat=<perch:category id="catSlug" />">

Wouldn't that solve it?

That works, thanks. How about the other issue?

Even though I have the include-empty => true inside the listing and detail pages call to the links template its no longer showing empty categories (it did before).

<?php perch_blog_categories(array('template'=>'category_link.html','include-empty' => true)); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, I don't know about that.

Could it be a bug, it worked before. In fact I think it was adapted from code you kindly provided.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Before being when?

Well unfortunately I cannot be sure as I only spotted it was not working right when I was trying to add a blog feature to another site and was referencing the code for this site.

I think it might be after updating the Blog app from 4.5.2 but it could have been after updating to 2.7.2.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right, so as a result of a change rather than just randomly stopping working?

Yes correct, checked docs and its done the correct way.

Just checked the testing version of this site, its using perch_blog 4.1 and it displays empty categories using the same code as above. So maybe there is something missing in perch_blog 4.5?

FYI Did a bit of testing. If I place the category_link template in the category folder in templates and call it from there there empty categories show. However the count.blog.post no longer works.

2 steps forward 1 back!

So studying the contents of blog 4.1 and blog 4.5 seems the code for include-empty is inside PerchBlog_Categories.class.php which is no longer in blog 4.5 probably because its no longer used by the blog app but by categories.

However by calling the template inside /category in templates breaks whatever drives the count.blog.post

Maybe you can shed some light?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, sounds like you'll either need to stick with the old version or go without it for now.

Okay shame.

I think its something in this code which is in the original PerchBlog_Categories.class.php file which is no longer in the app.

public function get_custom($opts)
    {
        $API = new PerchAPI(1.0, 'perch_blog');

        $manual_count = false;

        if ($opts['section']) {
            $manual_count = true;
            $Sections = new PerchBlog_Sections($this->api);
            $Section = $Sections->get_one_by('sectionSlug', $opts['section']);
        }

        if ($manual_count && is_object($Section)) {

            if ($opts['include-empty']) {
                $sql = 'SELECT cat.*, cat.categoryID AS _id, IFNULL((
                            SELECT COUNT(p2c.postID)
                            FROM perch2_blog_categories c, perch2_blog_posts_to_categories p2c, perch2_blog_posts p
                            WHERE p2c.categoryID=c.categoryID AND p2c.postID=p.postID
                                AND p.postStatus=\'Published\' AND p.postDateTime<='.$this->db->pdb(date('Y-m-d H:i:s')).' 
                                AND p.sectionID='.$this->db->pdb($Section->id()).' AND c.categoryID=_id
                            GROUP BY c.categoryID
               ),0) as qty FROM '.$this->table.' cat ORDER BY cat.categoryTitle ASC';
            }else{
                $sql = 'SELECT *, categoryID AS _id, IFNULL((
                            SELECT COUNT(p2c.postID) AS thecount
                            FROM perch2_blog_categories c, perch2_blog_posts_to_categories p2c, perch2_blog_posts p
                            WHERE p2c.categoryID=c.categoryID AND p2c.postID=p.postID
                                AND p.postStatus=\'Published\' AND p.postDateTime<='.$this->db->pdb(date('Y-m-d H:i:s')).' 
                                AND p.sectionID='.$this->db->pdb($Section->id()).' AND c.categoryID=_id
                            GROUP BY c.categoryID
               ),0) as qty FROM '.$this->table.' HAVING qty>0 ORDER BY categoryTitle ASC';
            }


        }else{

            if ($opts['include-empty']) {
                $sql = 'SELECT *, categoryID AS _id, categoryPostCount as qty FROM '.$this->table.' ORDER BY categoryTitle ASC';
            }else{
                $sql = 'SELECT *, categoryID AS _id, categoryPostCount as qty FROM '.$this->table.' WHERE categoryPostCount>0 ORDER BY categoryTitle ASC';
            }

        }

This seems to be missing from the PerchCategories_Categories.class.php file. There is some code about include-empty at line 154 but maybe its missing some extra lines. As I am no php coder its beyond me!

Only posting this in case it helps...

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's ok, I've fixed it.