Forum

Thread tagged as: Question, Discussion

Filter Page Links based on detail view

I am trying to only show the previous and next page links ("sectionButtons") only on the list view and not the detail views. Any suggestions?

<?php include('masonry/runtime.php'); ?>
<!doctype html>
<html lang="en">

<?php include('inc/head.php'); ?>

<body class="inventory">
    <?php include('inc/header.php'); ?>

    <div id="mainAreaContainer" class="container">
        <div id="mainArea">
            <?php include('inc/nav.php'); ?>
        </div><!--End Main Area-->
    </div><!--End Container-->

        <div class="container">
            <div class="row">
                <div id="mainContent" class="col-md-12">
                    <span class="pageTitle">
                        <?php perch_pages_title(); ?>
                    </span><!--End Page Title-->

                    <div class="row">
                        <div id="sideBar" class="col-md-3">
                            <div id="sidenavtop">
                                <h2>Categories</h2>
                            </div><!--End Side Nav Top-->

                            <?php
                                perch_pages_navigation(array(
                                    'template' => array('item.html', 'item2.html'),
                                    'from-path'  => '*',
                                    'from-level' => 1,
                                    'levels'     => 2,
                                    'hide-extensions' => true,
                            )); ?>

                            <?php perch_content('Sidebar Content'); ?>
                        </div><!--End Sidebar-->

                        <div id="sideContent" class="col-md-9">
                            <?php

                                 perch_content_create('Products', array(
                                      'template'  => 'product_detail.html',
                                      'multiple'  => true,
                                      'edit-mode' => 'listdetail',
                                 ));


                                 if (perch_get('s')) {

                                      // Detail mode
                                      perch_content_custom('Products', array(
                                           'template' => 'product_detail.html',
                                           'filter'   => 'itemNumber',
                                           'match'    => 'eq',
                                           'value'    => perch_get('s'),
                                           'count'    => 1,
                                      )); 

                                 } else {

                                      // List mode
                                      perch_content_custom('Products', array(
                                           'template' => 'product_listing.html',
                                      )); 
                                 }

                            ?>

                            <div class="sectionButtons">
                                <a class="button" href="/table-of-contents">Table of Contents</a>
                                <?php perch_pages_previous_page(array('hide-extensions' => true, 'template' => 'previoussection.html'));?>
                                <?php perch_pages_next_page(array('hide-extensions' => true, 'template' => 'nextsection.html'));?>
                            </div><!--End Section Buttons-->
                        </div><!--End Side Content-->

                    </div><!--End Row-->
                </div><!--End Main Content-->
            </div><!--End Row-->
        </div><!--End Container-->

    <?php include('inc/footer.php'); ?>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>
        $(document).find('.sidenav li:first-child ul').attr('id', 'level2');
        $(document).find('.sidenav li:nth-child(2) ul').attr('id', 'cslevel2');
        $(document).find('.sidenav li:nth-child(3) ul').attr('id', 'cstlevel2');
    </script>
</body>

</html>
Jonathan Hazelwood

Jonathan Hazelwood 0 points

  • 2 years ago

Example:

https://dev.trishkaufmann.com/florida

^shows the previous and next like wanted.

https://dev.trishkaufmann.com/florida?s=11630

^they should not show on the detail view.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Jonathan,

You already have the logic to conditionally output different things based on the view (list vs detail):

if (perch_get('s')) {

// Detail mode
// Output to detail view only

} else {

// List mode
// Output to list view only
// you can output .sectionButtons here to only display it in list view

}

Hussein Al Hammad said:

Thanks I ended up pulling it in with an include as another template file which seems to work great.

<?php

                                 perch_content_create('Products', array(
                                      'template'  => 'product_detail.html',
                                      'multiple'  => true,
                                      'edit-mode' => 'listdetail',
                                 ));


                                 if (perch_get('s')) {

                                      // Detail mode
                                      perch_content_custom('Products', array(
                                           'template' => 'product_detail.html',
                                           'filter'   => 'itemNumber',
                                           'match'    => 'eq',
                                           'value'    => perch_get('s'),
                                           'count'    => 1,
                                      )); 

                                 } else {

                                      // List mode
                                      perch_content_custom('Products', array(
                                           'template' => 'product_listing.html',
                                      ));

                                     include("sectionButtons.html");
                                }
                            ?>