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

Forum

Thread tagged as: Problem, Error, Blog

Filtering the blog app by section

Hi,

I am having issues filtering the blog by two sections: Latest News and Case Studies.

I am able to filter both sections on their respective index/post in list pages, but when I try to go into a post I get a 404 error with the case studies section. I've changed 'Blog post page path' to be just {postSlug} which works fine for Latest News but not for Case Studies.

Here is my index.php page for Case Studies:

<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/header.php'); ?>
<div class="full-post" id="case-studies">
<?php
perch_blog_custom( array(
    'count' => 1,
    'template' => '_latest_post.html',
    'sort' => 'postDateTime',
    'sort-order' => 'DESC',
    'section' => 'case-studies',
) );
?>
</div>
<!-- /div.full-post -->
<div class="post-list" id="case-studies">
<h2>Case Studies</h2>
<?php  
perch_blog_custom(array(
  'count'      => 8,
  'template'   => '_other_posts.html',
  'sort'       => 'postDateTime',
  'sort-order' => 'DESC',
  'section' => 'case-studies',
));
?>
</div>
<!-- /div.post-list -->
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/footer.php'); ?>

And here is my post.php template for case studies:

<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/header.php'); ?>

<?php
$slug = perch_get('s'); // sets slug to equal postSlug
$html = perch_blog_post($slug, True);  // stores post in variable to use later
$data = perch_blog_custom(array(
    'filter'=>'postSlug',
    'match'=>'eq',
    'value'=>$slug,
    'skip-template'=>true, 
)); // grabs data of current post
$data = $data[0]; 
$date = $data['postDateTime']; 
?>
<div class="full-post" id="case-studies">
<?php 
    perch_blog_custom(array(
        'template' => 'post.html',
        'filter'=>'postSlug',
        'match'=>'eq',
        'value'=>$slug,
        'section' => 'case-studies',
    true ));
?>
</div>
<!-- /div.full-post -->

<div class="post-list" id="case-studies">
<h2>Case Studies</h2>
<?php  
perch_blog_custom(array(
  'count'      => 8,
  'template'   => '_other_posts.html',
  'sort'       => 'postDateTime',
  'sort-order' => 'DESC',
  'section' => 'case-studies',
));
?>
</div>
<!-- /div.post-list -->
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/footer.php'); ?>

Perch debug on the case studies post.php page:

Debug Message - Perch 3.0.1
[1] SELECT * FROM perch3_pages WHERE pagePath='/case-studies/post.php' LIMIT 1
[7] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/case-studies/post.php' LIMIT 1
[3] Using template: /templates/navigation/item.html
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2017-05-18 09:39:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[23] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
Using template: /templates/blog/post.html
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE (postStatus='Published' AND postDateTime<='2017-05-18 09:39:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/post.html
[1] SELECT * FROM perch3_blog_sections WHERE sectionSlug='case-studies' LIMIT 1
[nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE ( sectionID='2' AND postStatus='Published' AND postDateTime<='2017-05-18 09:39:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/post.html
[1] SELECT * FROM perch3_blog_sections WHERE sectionSlug='case-studies' LIMIT 1
[2] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_blog_index idx JOIN perch3_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch3_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, postID ) as tbl WHERE ( sectionID='2' AND postStatus='Published' AND postDateTime<='2017-05-18 09:39:00' ) GROUP BY itemID, sortval ORDER BY sortval DESC LIMIT 0, 8
[1] SELECT FOUND_ROWS() AS `count`
[2] Using template: /templates/blog/_other_posts.html
[3] SELECT * FROM perch3_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch3_blogs ORDER BY blogTitle ASC
Missing variant.
Missing variant.
Array
(
    [type] => 8
    [message] => Undefined offset: 0
    [file] => /var/www/vhosts/thirdfloordigital.net/stellamannering.thirdfloordigital.net/case-studies/post.php
    [line] => 15
)

Diagnostics report:

Perch: 3.0.1, PHP: 5.4.13, MySQL: 5.5.30, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.1), assets (3.0.1), categories (3.0.1), perch_blog (5.5.1), perch_forms (1.9)
App runtimes: <?php $apps_list = [ perch_blog, perch_forms ];
PERCH_LOGINPATH: /cms
PERCH_PATH: /var/www/vhosts/thirdfloordigital.net/stellamannering.thirdfloordigital.net/cms
PERCH_CORE: /var/www/vhosts/thirdfloordigital.net/stellamannering.thirdfloordigital.net/cms/core
PERCH_RESFILEPATH: /var/www/vhosts/thirdfloordigital.net/stellamannering.thirdfloordigital.net/cms/resources
Image manipulation: GD Imagick
PHP limits: Max upload 128M, Max POST 8M, Memory: 128M, Total max file upload: 8M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
REQUEST_URI: /cms/core/settings/diagnostics/
DOCUMENT_ROOT: /var/www/vhosts/thirdfloordigital.net/stellamannering.thirdfloordigital.net
HTTP_HOST: stellamannering.thirdfloordigital.net

Thanks in advance for your help and apologies if I haven't provided enough information! J

Darren Cusdin

Darren Cusdin 0 points

  • 2 years ago

What is your path set to in your "_other_posts.html" template?

What's your 404 URL and whats the working URL? Basically have you remembered to work from root.

Do you have any .htaccess running?

Hi Stephen,

I've just added the following to my .htaccess file:

RewriteRule ^case-studies/([a-zA-Z0-9-/]+)$ /case-studies/post.php?s=$1 [L]

Where both sections of the blog are working fine, thank you!

You're Welcome... fresh eyes always helps