Forum

Thread tagged as: Question, Problem

Portfolio with Categories - link to category not working

I have followed the step-by-step tutorial for this but when I create a link to the category it does not work. When I click on the category it seems to find a page but nothing displays not even the global header and footer.

I'm thinking this is something to do with the path I have in this section but there is no explanation as to what this path should be if I have my files in a folder and am not using htaccess to avoid displaying .php on my pages.

<perch:categories id="Work" label="Type of work" set="type" required="true">
  <perch:before>
    <h3>Tags</h3>
    <ul class="tags">
  </perch:before>
      <li><a href="/work/category.php/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
  <perch:after>
    </ul>
  </perch:after>
</perch:categories>

from the root my category.php is in work/category.php as are listing and detail pages for this portfolio. I have tried a few different paths but nothing seems to work so I'm hoping you can help?

Link to the page: https://kc.kubiaktest.co.uk/work/detail.php?s=portwall-place

Emily Taylor

Emily Taylor 0 points

  • 7 years ago

Hi Emily

Your link path structure is wrong and needs to instead be:

href="/work/category/<perch:category id="catPath" />"

Then you also need to ensure that you have an appropriate rewrite rule in your .htaccess file.

At the moment this site is a test and hosted on a subdomain so I have no idea what the rewrite rule should be. Could you advise?

It shouldn't matter where it is hosted as you can have an .htaccess file in the root of the folder for this test site.

The actual rule would then be:

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

If you need the full .htaccess rewrite set up let me know.

Ok, I have gone back over the video and used that code you have given me as the rewrite. I've also actioned it for the detail.php file as suggested in the video. The rewrite works for the listing link to the detail pages but it's still not working for the categories.

I'm still just getting a blank page, could it be something I'm missing in the code on the category.php page?

It could be but I am not part of the Perch team, just advising you on what I know from using it :) Can you check the PHP error logs on your server? Can you post your code here?

I'm not getting a 404 error or anything I'm just getting a blank page. It has the correct background tint so it is registering the css.

The only errors I have that point to these pages look just like this:

[Thu Sep 25 06:00:09 2014] [error] [client 82.69.82.79] File does not exist: /home/kubiak/public_html/kc/work/js, referer: https://kc.kubiaktest.co.uk/work/

my htaccess says this:

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteRule ^work/detail/([a-zA-Z0-9-/]+)$ work/detail.php?s=$1 [L]
RewriteRule ^work/category/([a-zA-Z0-9-/]+)$ /work/category.php?cat=$1 [L]

# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]

</IfModule>

I'm using this php to call the categories in:

    <?php
    if (perch_get('cat')) {
      perch_category(perch_get('cat'));
    } else {
      perch_categories();
    }
    ?>

Does that help?

You wouldn't get a 404 unless the page hadn't been found so it looks like a page is at least being loaded (though maybe not the right one).

The easiest way to check the page itself is working is to bypass the nice url for the moment, so try putting in the full url manually into the browser and see what happens, for example

https://kc.kubiaktest.co.uk/work/category.php?cat={put a category slug here]

Ok, I think is must be something to do with the page because it's still blank when I use the full url.

It seems to be the php, if I take the above (my last reply) perch_category code block out of the page it displays all of the other content i.e. header and footer but when I pop it back in it's a blank page again with no content at all.

Does that give any indication of what's wrong?

I have copied and pasted that code from the tutorial and not changed the rest of my page at all, I have also tried the code below and it does the same.

<?php
perch_categories();
?>

All my other pages work fine.

Sorry! I've just found this in my error log:

[23-Sep-2014 14:25:23 UTC] PHP Fatal error:  Call to undefined function perch_categories() in /home/kubiak/public_html/kc/work/category.php on line 7

What's on line 7 is

if (perch_get('cat')) {

or

perch_categories();

depending on what bit of those two examples I've paste in but seems like both of them bring in that error.

I did have to update my version of perch to get categories to do this part of the site. Could I have missed something while updating?

I don't think so but not 100% sure - that is something Drew or Rachel would have to answer

I presume you have your html templates set up correctly as per the tutorial?

I believe so, I'll go back through the tutorial and make sure I've done everything...

I cannot find the problem. Could Drew or Rachel weigh in on this feed?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the current problem?

The problem is that I have followed the instructions in the Portfolio with Categories video tutorial but when I get to the point where I paste this code:

<?php
perch_categories();
?>

into my category.php file and test it, it brings back a blank page, no header or footer but the background colour.

I cannot for the life of me figure out what the problem is because I've gone over the tutorial several times and all seems to work up until that point so I'm hoping you can help?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you added the Categories app in your config/apps.php file?

Ooops!! No you are right I haven't. red face Is that a case of putting 'perch_categories', in that file?

Oh no wait it's just 'categories', isn't it?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, see https://docs.grabaperch.com/docs/installing-perch/installing-apps/

It's either like this for new configurations:

$apps_list = array(
        'content', 
        'categories', 
    );

or like this for legacy sites:

include(PERCH_PATH.'/core/apps/content/runtime.php');
include(PERCH_PATH.'/core/apps/categories/runtime.php');

Thank you Drew!!!