Forum

Thread tagged as: Question, Api, Blog

Blog post custom template

This function call returns nothing. Please may you confirm if this is well formed

<?php perch_blog_post(perch_get('s'), [
'template' => 'post_single.html']); ?>
Fred Stidston

Fred Stidston 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

That doesn't give us enough information to help you. We need your code, template plus Diagnostics Report with each post to the forum.

You also have some tools that will help you diagnose problems for yourself.

Have you enabled debug? https://docs.grabaperch.com/docs/installing-perch/configuration/debug/

If not, that would be a good start, the output will indicate whether or not your query is returning anything.

Have you checked that your rewrite rules are working if you are rewriting URLs?

The debug indicates the default template is being used. My URLs are working fine elsewhere for example the custom template I'm using for search is getting the right code

          <?php perch_search_form([
            'template' => 'search-compact',
          ]); ?>
SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_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='institute-of-certified-bookkeepers')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-07-18 08:45:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[22] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/blog/meta_head.html
[1] SELECT * FROM perch2_blog_authors ORDER BY authorFamilyName, authorGivenName ASC
[1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
[22] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[2] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/portfolio/blog/post.php' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/search/search-compact.html
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_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='institute-of-certified-bookkeepers')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-07-18 08:45:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /templates/blog/post.html
[1] SELECT * FROM perch2_categories ORDER BY catTreePosition ASC
Rachel Andrew

Rachel Andrew 394 points
Perch Support

We need your code, template plus Diagnostics Report with each post to the forum.

Your search code is irrelevant. Is this page returning the correct data?

We will try and help you, despite these issues not being an issue with our software but you do need to do some debugging yourself to get to a point where you can tell us where the problem lies. At the moment we are unable to help.

Here is my template

<?php include('../perch/runtime.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <?php perch_blog_post_meta(perch_get('s')); ?>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />
    <?php perch_get_css(); ?>
    <link rel="stylesheet" href="blog.css" type="text/css" />
</head>
<body>
    <header>
    <div class="content">
      <div class="cols-3 responsive">
        <div class="col">
          <h1><?php perch_content('Main heading'); ?></h1>
          <p><?php perch_content('Main description'); ?></p>
        </div>
        <div class="col">
        </div>
        <div class="col">
          <?php perch_search_form([
            'template' => 'search-compact',
          ]); ?>
        </div>
      </div>
    </div>
  </header>
    <main>
    <?php perch_blog_post(perch_get('s'), [
            'template' => 'post_single'
        ]); ?>
    </main>
    <footer>
    <div class="content">
      <p>&copy; MCV 2016</p>
    </div>
  </footer>
    <?php perch_get_javascript(); ?>
</body>
<?php PerchUtil::output_debug(); ?>
</html>
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can you post your Diagnostics Report please? We need this with each post to the forum.

I still need some information about the debugging steps you have followed, what can you tell us?

  • I have used template names with and without .html
  • I have used the array() notation and the square bracket [] notation
  • I have tried passing the template argument without any array around it
  • I have tried passing in the the template url for the post.html template
Debug Message
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_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='institute-of-certified-bookkeepers')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-07-18 17:23:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[22] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/blog/meta_head.html
[1] SELECT * FROM perch2_blog_authors ORDER BY authorFamilyName, authorGivenName ASC
[1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
[1] SELECT * FROM perch2_blogs ORDER BY blogTitle ASC
[22] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[2] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/portfolio/blog/post.php' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/search/search-compact.html
[1] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_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='institute-of-certified-bookkeepers')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (postStatus='Published' AND postDateTime<='2016-07-18 17:23:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 10
[1] SELECT FOUND_ROWS() AS `count`
[1] Using template: /templates/blog/post.html
[1] SELECT * FROM perch2_categories ORDER BY catTreePosition ASC