Forum

Thread tagged as: Question

Categories links in list / detail pages

Hi

I have followed the tutorial on creating a portfolio (https://docs.grabaperch.com/video/v/portfolio-with-categories/) as it is similar to what I am trying to do with a listing / detail page.

I have a couple of different layouts which utilise different prices/offers depending on if someone is a business or personal customer and for this reason they are inside separate folders for example /business or /personal.

I am trying to use categories within these folders so for business it would be /business/category.php and would like it to display a list of offers related to the category selected on the detail page. However I am having issues getting this to work when you click a category link it isnt returning the category.php layout with a list of offers in the way it does in the portfolio tutorial.

Any help would be apprciated.

Neil Irwin

Neil Irwin 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us your code?

Hi Drew

Category.php Page:

<?php    
                if (perch_get('cat')) {
                  perch_category(perch_get('cat'),array(
                    'template'=>'category_single.html'
                ));
                perch_content_custom('Offers', array(
                  'template' => 'cars/business_listing.html',
                  'page'=>'/business/detail.php',
                  'category' => perch_get('cat'),
                ));
                } else {
                  perch_categories();
                }
                ?>

detail.php Category part of the template

<div class="meta">
            <perch:categories id="manufacturers" set="manufacturers">
                <perch:before>
                <h3>Manufacturer</h3>
                <ul class="tags">
                </perch:before>
                <li><a href="category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
                <perch:after>
                </ul>
                </perch:after>
            </perch:categories>
            <perch:categories id="carType" set="car-type">
                <perch:before>
                <h3>Car Type</h3>
                <ul class="tags">
                </perch:before>
                <li><a href="category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
                <perch:after>
                </ul>
                </perch:after>
            </perch:categories>
        </div>

Thanks

I also have this in my htaccess


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

Drew McLellan 2638 points
Perch Support

Ok, great - which part isn't working? How does it fail? What results do you get and what results are you expecting?

What have you tried?

When you click on the category link at the bottom of the detail page it is taking me to business/manufacturers/nissan/ but none of the styles are being pulled through and it isnt producing a list of items associated with the category clicked on the detail page.

If i hit business/category.php it brings back a list of all categories available.

I have tried a number of configurations with the category path but cant get anything to produce a list of items associated with that category.

Drew McLellan

Drew McLellan 2638 points
Perch Support

By styles, you mean the CSS? Do you get any errors in your browser console?

Yeah the CSS isnt being found. I have figured out that it is trying to use detail.php as the page to display the categories on.

Each element being called in the header or footer are causing an error so CSS and Jquery. It seems to be thinking that it is inside a separate folder for each level in the Categories.

I have sent you a DM through slack with the web address of the test site.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Have you linked your CSS and JavaScript so it is root relative?

So:

/js/my-javascript.js /css/my-css.css

Hi Rachel

I had them set to ../css/styles.css. I have removed the .. and the styles are now loading.

Still no joy with the listing of items within a selected category tho. It appears to be using my detail.php template instead of my category.php template.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you are rewriting URLs you will need to link your assets from root.

With regard to the other issue, what do you get on that page if you turn on debug in Perch?

No worries I have changed them over now.



Debug Message SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Offers' AND (regionPage='/business/detail.php' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=68 AND idx.itemRev=45)) AND ((idx.indexKey='slug' AND idx.indexValue='manufacturers/nissan/')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1 Using template: /templates/content/cars/header.html SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/business/detail.php' OR regionPage='*' ORDER BY regionPage DESC SELECT * FROM perch2_pages WHERE pagePath='/business/detail.php' LIMIT 1 SELECT groupID FROM perch2_navigation WHERE groupSlug='main' LIMIT 1 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/business/detail.php' LIMIT 1 Using template: /templates/navigation/main.html SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Offers' AND (regionPage='business/index.php' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=68 AND idx.itemRev=45)) AND ((idx.indexKey='slug' AND idx.indexValue='manufacturers/nissan/')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1 Using template: /templates/content/cars/business.html SELECT groupID FROM perch2_navigation WHERE groupSlug='footer' LIMIT 1 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=2 AND p.pagePath='/business/detail.php' LIMIT 1 Using template: /templates/navigation/footer.html SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0

I changed the link from

<li><a href="category/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>

to

<li><a href="/business/category.php?cat=<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>

That appears to have worked I just need to get the rewrite working correctly as its displaying the link as /business/category.php?cat=manufacturers/nissan/

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

Is there something that Im missing?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you're querying for items where the slug is manufacturers/nissan/

Is that what you'd expect?

Ah rite no I am guessing it should be the category path.rather than using the slug.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which page is that debug output from?

Its from my detail.php page as until I changed the category link over it wasnt going to the category.php page

I must have something wrong within the htaccess rewrite


<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^personal/([a-zA-Z0-9-/]+)$ personal/detail.php?s=$1 [L] RewriteRule ^personal/([a-zA-Z0-9-/]+)$ personal/category.php?cat=$1 [L] RewriteRule ^business/([a-zA-Z0-9-/]+)$ business/detail.php?s=$1 [L] RewriteRule ^business/([a-zA-Z0-9-/]+)$ business/category.php?cat=$1 [L] RewriteRule ^detail/([a-zA-Z0-9-/]+)$ /detail/post.php?s=$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>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What code is on your detail.php page? So far I think you've given me the code from one page and the debug from another. I need both from the same.

business/detail.php


<?php perch_content_custom('Offers', array( 'page' => 'business/index.php', 'template'=>'cars/business.html', 'filter' => 'slug', 'match' => 'eq', 'value' => perch_get('s'), 'count' => 1, )); ?>

business.html categories part of template

<div class="meta">
            <perch:categories id="manufacturers" set="manufacturers">
                <perch:before>
                <h3>Manufacturer</h3>
                <ul class="tags">
                </perch:before>
                <li><a href="category.php?cat=<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
                <perch:after>
                </ul>
                </perch:after>
            </perch:categories>
            <perch:categories id="carType" set="car-type">
                <perch:before>
                <h3>Car Type</h3>
                <ul class="tags">
                </perch:before>
                <li><a href="category.php?cat=<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
                <perch:after>
                </ul>
                </perch:after>
            </perch:categories>
        </div>

Debug Message SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Offers' AND (regionPage='/business/detail.php' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=68 AND idx.itemRev=48)) AND ((idx.indexKey='slug' AND idx.indexValue='nissan-pulsar')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1 Using template: /templates/content/cars/header.html SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/business/detail.php' OR regionPage='*' ORDER BY regionPage DESC SELECT * FROM perch2_pages WHERE pagePath='/business/detail.php' LIMIT 1 SELECT groupID FROM perch2_navigation WHERE groupSlug='main' LIMIT 1 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/business/detail.php' LIMIT 1 Using template: /templates/navigation/main.html SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Offers' AND (regionPage='business/index.php' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=68 AND idx.itemRev=48)) AND ((idx.indexKey='slug' AND idx.indexValue='nissan-pulsar')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC LIMIT 0, 1 Using template: /templates/content/cars/business.html SELECT * FROM perch2_categories ORDER BY catTreePosition ASC SELECT groupID FROM perch2_navigation WHERE groupSlug='footer' LIMIT 1 SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=2 AND p.pagePath='/business/detail.php' LIMIT 1 Using template: /templates/navigation/footer.html SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0

business/category.php


<?php if (perch_get('cat')) { perch_category(perch_get('cat'),array( 'template'=>'category_single.html' )); perch_content_custom('Offers', array( 'template' => 'cars/business_listing.html', 'page'=>'/business/detail.php', 'category' => perch_get('cat'), 'sort'=>'businessCarPrice', 'sort-order'=>'ASC' )); } else { perch_categories(); } ?>

cars/business_listing.html template


<article class="caroffer <perch:every nth-child="3n+2"> odd</perch:every>"> <a href="/business/<perch:content id="slug" for="heading" type="slug" />"> <div class="carofferMain"> <div class="cardetailTop"> <h3><perch:content id="carTitle" /></h3> <p><perch:content id="carModel" /></p> </div> <div class="carimage"> <perch:if exists="carImage"><img src="<perch:content type="image" id="carImage" bucket="cars" width="1000" height="600" crop="true" />" alt="<perch:category id="carTitle" />" /> <perch:else/> <img src="../img/car-no-image.jpg" alt="<perch:content id="carTitle" />" /> </perch:if> </div> <div class="cardetail"> <div class="cardetailright"> <h4>Deposit<br/> <i><perch:content id="businessCarDeposit" /></i></h4> </div> <div class="cardetailleft"> <h4><strong>£<perch:content id="businessCarPrice" /></strong><br/><perch:content id="payment" /> + VAT</h4> </div> <div style="clear: both;"></div> </div> </div> <footer class="carLink"> <span>View Offer</span> </footer> </a> </article>
Debug Message
SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='manufacturers/nissan/') ORDER BY catTreePosition ASC
Using template: /templates/categories/category_title.html
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/business/category.php' OR regionPage='*' ORDER BY regionPage DESC
SELECT * FROM perch2_pages WHERE pagePath='/business/category.php' LIMIT 1
SELECT groupID FROM perch2_navigation WHERE groupSlug='main' LIMIT 1
SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/business/category.php' LIMIT 1
Using template: /templates/navigation/main.html
SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catPath='manufacturers/nissan/') ORDER BY catTreePosition ASC
Using template: /templates/categories/category_single.html
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Offers' AND (regionPage='/business/detail.php' OR regionPage='*')
SELECT idx.itemID FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID WHERE ((idx.regionID=68 AND idx.itemRev=48)) AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'manufacturers/nissan/%'))
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='businessCarPrice' WHERE ((idx.regionID=68 AND idx.itemRev=48)) AND idx.itemID IN ('68', '66', '67') AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
Using template: /templates/content/cars/business_listing.html
SELECT groupID FROM perch2_navigation WHERE groupSlug='footer' LIMIT 1
SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=2 AND p.pagePath='/business/category.php' LIMIT 1
Using template: /templates/navigation/footer.html
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0