Forum

Thread tagged as: Question, Problem, Error

Breadcrumbs not working (for Detail item)

Hi, I can't get breadcrumbs to work for a item detail page. Even when outputting dummy text.

breadcrumbs_test.html is within the navigation folders.

Appreciate any help!

.HTACCESS

RewriteEngine On
RewriteRule ^product/([a-zA-Z0-9-/]+)$ /admin/templates/pages/products-detail.php?s=$1 [L]
RewriteRule ^category/([a-zA-Z0-9-/]+)$ /admin/templates/pages/products-category.php?cat=$1 [L]

Page PHP

                <?php   

                    perch_pages_breadcrumbs(array(
                        'template'=>'breadcrumbs_test.html'
                    ));

        ?> 

Navigation Template

TESTESTESTS
<perch:before>
sdfgdfsgdfsg
<ul class="breadcrumbs">
</perch:before>
<perch:pages id="pagePath" />

    <li>
        <perch:if exists="perch_item_last">
            <perch:pages id="pageNavText" />
        <perch:else />
            <a href="<perch:pages id="pagePath" />?s=<perch:content id="test" type="slug" />"><perch:custom id="pageNavText" /></a>
        </perch:if>
    </li>
<perch:after>
</ul>
</perch:after>
James Hazelton

James Hazelton 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you add debug to the page, what does it output?

SELECT * FROM perch2_pages WHERE pagePath='/admin/templates/pages/products-detail.php' LIMIT 1
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using template: \templates\search\search_product_form.html
Using template: \templates\search\search_product_mobile_form.html
SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/admin/templates/pages/products-detail.php' OR pageSortPath='/admin/templates/pages/products-detail.php' LIMIT 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure navigation functions will work for you due to the unusual way you're rewriting your URLs directly into the templates folder.

Am using the same method as the Portfolio with Categories set-up ( https://docs.grabaperch.com/video/v/portfolio-with-categories/ ). i.e. Slug and redirection.

Is there a way the page hierarchy can be saved?

i.e. Pages:

Products
 - Chairs
    - - Lounge

The Perch Content item exists on the 'Lounge' page.

The breadcrumb should be:

Products > Chairs > Lounge

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can tell Perch what the page should be by using PerchSystem::set_page()

Not sure how to get the ideal outcome with that?

The problem is that the detail page is not actually a page, it's just perch content, and it's not a sub-page of the page (i.e. Lounge) that the content exists.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. How can I help you?

Would like the Perch Content items to be simulated as an actual page, a sub-page of where the Perch Content is saved.

Current: Products > Chairs > Lounge (Perch Content)

Would like: Products > Chairs > Lounge > Lounge-Name (i.e. Perch Content item). At least just for using Perch Breadcrumbs.

The problem with using a slug, even on the back of the Lounge page, is that the Lounge text is not linked within the breadcrumbs.

I.e. Products (linked) > Chairs (linked) > Lounge (not linked, because active page)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Why do these need to come from the navigation functions? Why not pass them into the template?

Am currently passing HTML breadcrumbs via the template however it's inefficient and repetitive for 100's of products.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Surely you just do it once for all products?

Nope, there are 4 primary categories, and around 10 sub-categories under each primary. So there are basically around 40 variants. Hence the Breadcrumbs would be perfect for automation.

Next best thing I can think of (if the sub-page simulation can't be done for perch breadcrumbs), is to create categories/sub-categories along with a breadcrumb HTML textarea. Then display the breadcrumb HTML in page via custom template if the sub-category is selected in item content. It just means the category/sub-category needs to be selected for every product, no huge biggie, better than the general textarea HTML method per item at least.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You don't have 40 pages all doing the same thing though? The logic can run through one central point.

One master page for summary and detail.

Same as the Portfolio with Categories set-up ( https://docs.grabaperch.com/video/v/portfolio-with-categories/ ). i.e. Slug and redirection.

Perch CMS pages as follows:

Products
 - Chairs
 - - Dining
 - - Lounge
 - - Dining
 - - Office
 - Tables
 - - Bar
 - - Bistro
 - - Dining
(etc.)

All the above are using the products-summary.php page

At the third level i.e.

 - - Bar
 - - Bistro
 - - Dining

Perch content exists as product-item. product-item may be 1 to 100+ products/items.

The product-item is displayed through the master page product-detail.php via slug.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great, so you just need to set the breadcrumb once, dynamically, not 40 times.

Yep, except can't get breadcrumbs working for the product detail page, because the item is from perch content, it's not an actual page, would need the item detail simulated as a page. I don't know how to get working.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me what you're trying and how it's not working? The solution here is to use the content, not just navigation functions.

<?php

    /* Breadcrumbs doesn't work */
    perch_pages_breadcrumbs();


    /* Works */
    perch_content_custom('Product-Items', array(
    'page'              =>      '/products/*',
    'template'          =>      'product_item_detail.html',
    'filter'            =>      'slug',
    'match'             =>      'eq',
    'value'             =>      perch_get('s'),
    'count'             =>      1,          
    )); 

?>

How can I get the page hierarchy with links automatically into the content then? It needs to work like breadcrumbs.

Content exists on perch page Lounge: Products > Chairs > Lounge

Products
 - Chairs
    - - Lounge
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does perch_pages_breadcrumbs() output?

Nothing, as per start of thread.