Forum

Thread tagged as: Question, Problem, Configuration

Category URL conundrum

I notice the default blog category links are returned as .../blog/archive.php?cat=mycategory (no surrounding /'s or directory/ in the string.

Whereas general category links returned as ../category.php?cat=collections/mycategory/ (surrounding /'s + directory/

Why is that, and how to I change the category link to just ../category.php?cat=mycategory ?

David Owen

David Owen 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Blog has a default category set (blog) so that assumed and the slug is used instead of the path.

If you want to do the same elsewhere, use catSlug instead of catPath and then put it back together in your page.

Ok thanks got that.

When using catSlug I get the link I want but the exiting data is lost on the new URL ../category.php?cat=mycategory and I can't spot why simply changing the string why that should be?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you clarify "exiting data is lost" ?

When I change catPath to catSlug the page ../category.php?cat=mycategory returns my perch:noresults on the template category_single.html

 if (perch_get('cat')) {
    perch_category(perch_get('cat'),array(
    'template'=>'category_single.html'
     ));

It's OK using catPath

...why would that template fail and show no results? It's OK using catPath

Something is different when changing catPath to catSlug

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you're just using catSlug then you're missing valuable information. You need to turn it back into a path.

'setname/'.perch_get('cat')

So I should use?...

if (perch_get('cat')) {
perch_category('setname/'.perch_get('cat'),array(
'template'=>'category_single.html'
));
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is that not working?

Yes that works thanks. It's all becoming clear. Also using same to get category content elsewhere on the site.

'template' =>'_product_listing_with_category.html',
              'page'=>'/myotherpage',
              'category' => 'collections/'.perch_get('cat'),