Forum

Thread tagged as: Problem, Installation, Addons

Problem with Categories after updating to Perch

Hi, I updated Perch to last version, as the blog app, I copied the categories folder, add categories to config apps.php, and upgrade my post template to:

<perch:categories id="categories" set="blog" label="Kind" required="true" help="Choose just one" />

Everything works fine except all my old perch_blog_post_categories calls.

<?php
    $current_post = perch_blog_custom(array(
    'filter' => 'postSlug',
    'match' => 'eq',
    'value' => perch_get('s'),
    'skip-template' => true,
    ));

    $cats = perch_blog_post_categories(perch_get('s'), array('skip-template'=>true));
    $cats = array_map(function($item){return $item['categorySlug'];}, $cats);

    perch_blog_custom(array(
    'category' => $cats,
    'template' => 'post_in_side-nav2.html',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    ));
?>

Any idea whats going on?

Raul Serrano

Raul Serrano 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You haven't explained what is happening, what is the actual problem you are seeing?

The debug output from that page would probably also be useful.

Excuse me Rachel, before updating, my sidebar displayed a list of posts. Now it just don't print any thing, as it something was going wrong.

Debug queries:

SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='c1b3dcd7cba024e55dec5e3f6638577a' LIMIT 1

UPDATE perch2_users SET userHash='4901538c02ec94af18853ab874d0421e' WHERE userID=1

SELECT p.privKey FROM perch2_user_privileges p

SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0

ORDER BY userID DESC) AS settings GROUP BY settingID

SELECT *, REPLACE(pagePath, '/index.php', '') as sortPath FROM perch2_pages WHERE pageNew=1 ORDER BY LENGTH(sortPath)-LENGTH(REPLACE(sortPath, '/', '')) ASC

SELECT p.*, (SELECT COUNT(*) FROM perch2_pages WHERE pageParentID=p.pageID) AS subpages FROM perch2_pages p WHERE p.pageParentID IN (0) ORDER BY p.pageTreePosition ASC

SELECT * FROM perch2_content_regions ORDER BY regionOrder ASC

SELECT * FROM perch2_content_regions WHERE regionPage='*'

SELECT DISTINCT regionTemplate FROM perch2_content_regions ORDER BY regionTemplate ASC

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does $cats contain?

This sidebar apears in a post page, and it displays a list of posts within the same category of the current post. $cats displays that category.

Thats what you mean Drew?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, that's not what I mean. What is the value of $cats ?

echo $cats;

prints Array

In the sidebar I was using this code to add a current class, It do not work either:

  <h2 class="proyectosH2<?php perch_blog_post_categories(perch_get('s'), 'current-proyectos.html'); ?>"><a href="proyectos.html"> proyectos</a></h2>

Template:

<perch:if id="categoryTitle" match="eq" value="proyectos">
 current
</perch:if>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Did you build the site?

Yes. No templates.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. I'm not sure why you'd do echo $cats; if you understood what your code was doing.

Can you let me know what this outputs?

print_r($cats);

Excuse my php, I am a frontender.

It displays:

Array ( [0] => )

Drew McLellan

Drew McLellan 2638 points
Perch Support

Change:

$cats = array_map(function($item){return $item['categorySlug'];}, $cats);

to:

$cats = array_map(function($item){return $item['catSlug'];}, $cats);

It works for that Drew! :)

Not working this part:

<h2 class="proyectosH2<?php perch_blog_post_categories(perch_get('s'), 'current-proyectos.html'); ?>"><a href="proyectos.html"> proyectos</a></h2>

template

<perch:if id="categoryTitle" match="eq" value="proyectos">
 current
</perch:if>

In the template I have changed categoryTitle into catTitle and it works. That was the key, maybe you can put that on the upgrade page.

Thank you Drew