Forum

Thread tagged as: Question, Problem, Blog

perch_blog_post_categories() not working with multiple category sets

I have two category sets: 'Family' and 'Type' and I want to list post categories only from the 'Family' set. How can I do that? Right now I have the following code and nothing gets listed, as if there were no categories on the post.

post.php — displays a single post:

<?php
include('../global.includes.php'); ?>

<div class="o-list-inline c-card-holder">
<?php
// perch_blog_post(perch_get('s'));
perch_blog_custom([
    'filter' => '_id',
    'value' => perch_get('id'),
    'data' => [
        'singlePost' => 'yes',
    ],
]); ?>
</div>

<div class="c-card-meta c-card-meta--single">
    <?php perch_blog_author_for_post(perch_get('id'), [
        'template' => 'author.html',
    ]); ?>
    <div class="cats">
        <?php perch_blog_post_categories(perch_get('id'); ?>
    </div>
    <div class="tags">
        <?php perch_blog_post_tags(perch_get('id')); ?>
    </div>
</div>


<?php perch_layout('global.bottom'); ?>

post.html — post template:

<div class='o-list-inline__item [ c-card <perch:if id="singlePost" value="yes" match="eq"><!--*
        *-->c-card--single<!--*
        *--><perch:else /><!--*
            *-->c-card--multiple c-card--<perch:blog id="cardSize" type="select" label="Card size" options="Regular|regular, Medium|medium, Large|large" order="5" /><!--*
    *--></perch:if> ] <!--*
*-->[ <perch:categories id="cardFamily" set="family" label="Card family" required="true" order="3">family--<perch:category id="catSlug" /> </perch:categories>] <!--*
*-->[ <perch:categories id="cardType" set="type" label="Card type" required="true" order="4">type--<perch:category id="catSlug" /> </perch:categories>]'>


    <div class="c-card__info">
        <a class="u-no-link" href="/blog/post.php?id=<perch:blog id="postID" type="hidden" />">
            <h2 class="c-card__title"><perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" /></h2>
        </a>
        <perch:if exists="postSubTitle">
            <p class="c-card__subtitle">
                <perch:blog id="postSubTitle" type="text" label="Subitle" size="xl autowidth" order="2" />
            </p>
        </perch:if>
        <div class="c-card__icons">
            <!-- SVG coolness -->
        </div>
    </div>



    <perch:blog id="postDateTime" type="date" label="Date" time="true" format="Y-m-d H:i:s" divider-before="Publishing" order="6" suppress="true" />
    <!--* <perch:categories id="cardType" set="type" label="Card type" required="true" order="3" />*-->


    <perch:blog id="excerpt" type="textarea" label="Excerpt" markdown="true" suppress="true" size="s" order="7" />

    <perch:template path="content/global_blocks.html" rescope="parent" />

    <perch:blog id="isFeatured" type="checkbox" label="Featured in home page" suppress="true" />


    <!--* Fields to use elsewhere *-->

    <perch:blog id="authorGivenName" type="hidden" suppress="true" />
    <perch:blog id="authorFamilyName" type="hidden" suppress="true" />

Diagnostics report:

Perch: 3.1.2, PHP: 7.2.1, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.1.2), assets (3.1.2), categories (3.1.2), perch_blog (5.6.1)
App runtimes: <?php $apps_list = [ 'perch_blog', ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/Juan/Library/Mobile Documents/com~apple~CloudDocs/condimen /lib.condimen.com/perch
PERCH_CORE: /Users/Juan/Library/Mobile Documents/com~apple~CloudDocs/condimen /lib.condimen.com/perch/core
PERCH_RESFILEPATH: /Users/Juan/Library/Mobile Documents/com~apple~CloudDocs/condimen /lib.condimen.com/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 64M, Memory: 128M, Total max file upload: 32M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: condimen.local:5757
DOCUMENT_ROOT: /Users/Juan/Library/Mobile Documents/com~apple~CloudDocs/condimen /lib.condimen.com
REQUEST_URI: /perch/core/settings/diagnostics/?ckcachecontrol=1534012098
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Thank you!

Juan Ortiz Zaforas

Juan Ortiz Zaforas 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_blog_post_categories() works with the default Blog category set that Blog uses. If you have multiple category sets, use the standard perch_categories() functions and filtering.

Oh I see. But I still don't know how to filter to show only categories applied to a post.

I'm doing this but —unsurprisingly— is not working.

<?php perch_categories([
            'set' => 'family',
            'template' => 'family-menu',
            'filter' => 'postID',
            'value' => perch_get('id'),
        ]); ?>

How should I set the filter?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use the <perch:categories> tags in the post template to do this.

This tag is correct I think one tag is missing. By the way, if you are QuickBooks user then try to visit Quickbooks online support and get the best support from them for more detail visit at https://247quickbooks.us/quickbooks-support/

Thanks Drew!