We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum
Struggling to retrieve blogSlug from post
I am new to Perch. I am building a site which has two separate blogs (knowledge and perspective). The posts from these blogs utilise the same template, post.php and the design includes a next and previous navigation to loop through posts of the same blog.
I am therefore facing the challenge of retrieving the current blogSlug such that I can pass it into the perch_blog_custom function when retrieving the next and previous links.
My code is as below:
<?php $post = perch_blog_custom(array( 'filter'=>'postSlug', 'match'=>'eq', 'value'=>perch_get('s'), 'skip-template'=>true, )); //echo var_dump($post); $date = $post['postDateTime']; $blog = perch_blogs(array( 'filter'=>'blogID', 'match'=>'eq', 'value'=>'6', 'skip-template'=>true )); //echo $blog['blogSlug']; $prev = perch_blog_custom(array( 'count'=>1, 'filter'=>'postDateTime', 'match'=>'lt', 'sort'=>'postDateTime', 'sort-order'=>'DESC', 'blog' => 'knowledge', 'value'=>$date, 'template'=>'blog/post_prev.html' ), true); $next = perch_blog_custom(array( 'count'=>1, 'filter'=>'postDateTime', 'match'=>'gt', 'sort'=>'postDateTime', 'sort-order'=>'DESC', 'blog'=> 'knowledge', 'value'=>$date, 'template'=>'blog/post_next.html' ), true); ?>
The problems I have appear to be the following:
- My ability to var_dump the output of queries seem to execute once and then due to caching potentially just return "String" or "Array" or even just "A" and not the object contents itself meaning that debugging this issue is very difficult, even after discovering define('PERCH_DEBUG', true);. How do people inspect returned objects like this in Perch?
- I'd have expected to be able to take the blogSlug either from the current context or the current post but neither seem to hold this information. Am I right in trying to make another query to the actual blog of the post?
- I can't seem to return the slug from the perch_blogs function, as expected $blog['blogSlug'] does not return the string "knowledge". Am I missing something in the code here?
Perch Runway: 3.1.2, PHP: 7.2.8, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $, 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), perch_events (1.9.5) App runtimes: <?php $apps_list = [ 'perch_blog', 'perch_events', ]; PERCH_LOGINPATH: /perch PERCH_PATH: /Users/bmozza/Projects/quaich/perch PERCH_CORE: /Users/bmozza/Projects/quaich/perch/core PERCH_RESFILEPATH: /Users/bmozza/Projects/quaich/perch/resources Image manipulation: GD PHP limits: Max upload 32M, Max POST 8M, Memory: 128M, Total max file upload: 8M F1: 3b606135b33e6a102526838f4152a807 Resource folder writeable: Yes HTTP_HOST: me.local:5757 DOCUMENT_ROOT: /Users/bmozza/Projects/quaich REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Want to reply to this thread?Login with Perch