Thread tagged as: Problem, Addons, Blog

Blog index.php is not outputting any posts.


I am new to perch and I have been following the blog tutorial but I am stuck trying to output my blog post list to my blog index page. I'm calling the perch_blog_recent_posts function but it doesn't seem to be working.

I've downloaded the tutorial source files from github and adapted the post.php page to and I am able to preview my blog posts from the back end but I can't see any posts listed on the index page.

I've included a stripped version of my page code below along with my diagnostic report.

Does anybody have any suggestions as I'm really stuck.

<?php include('../perch/runtime.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <body> <!--Open container--> <div id="container"> <div id="main"> <div class="header"> <div id="header-gradient-image-blog"> <nav id="desktop-menu"> </nav> <nav id="mobile-menu"> </nav> <!--Close header--> <section class="main-text"> <h1>Blog</h1> <?php perch_blog_recent_posts(10); ?> <br> </section> <hr> <div id="footer"> <!--Close footer--> </div> </div> <!--Close container--> </div> </body> </html>

Summary information Perch: 3.1.1, PHP: 7.1.8, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO Server OS: Darwin, apache2handler Installed apps: content (3.1.1), assets (3.1.1), categories (3.1.1), perch_blog (5.6.1), perch_forms (1.11) App runtimes: <?php $apps_list = ['perch_forms','perch_blog' ]; PERCH_LOGINPATH: /perch PERCH_PATH: /Users/jimmyp757/Desktop/Web Projects/Sites/perch PERCH_CORE: /Users/jimmyp757/Desktop/Web Projects/Sites/perch/core PERCH_RESFILEPATH: /Users/jimmyp757/Desktop/Web Projects/Sites/perch/resources Image manipulation: GD PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M F1: 3b606135b33e6a102526838f4152a807 Resource folder writeable: Yes HTTP_HOST: localhost DOCUMENT_ROOT: /Users/jimmyp757/Desktop/Web Projects/Sites REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Jamie Price

Jamie Price 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Jamie,

I am able to preview my blog posts from the back end but I can't see any posts listed on the index page

Have you published any posts? perch_blog_recent_posts() doesn't display drafts.

Hello Hussein,

That's got it! Thank you so much!


hello, Let's take these one at a time.

First error is that I do not receive ANY output by using this code.

Not sure about this one. I thought I found an error in your code, but it wasn't so...

Second error is that I want to avoid that the DIV tag is being shown if there is no data from the database. By this I mean if I have less than 10 blog posts. Is there a statement to avoid this?

Change your database code to:


$query = "SELECT id, title, post, date_add, url, pictures_url FROM posts ORDER BY id desc LIMIT 10"; $count_query = "SELECT COUNT(*) FROM ($query) as Count";

// GET NUMBER OF BLOG POSTS $sth = $db->query($count_query); $count = $sth->fetchColumn();

// FETCH posts CONTENT $fetchblog = $db->prepare($query); $fetchblog->execute(); Then in your HTML use:

<?php if ($count >= 10) { $contentone = $fetchblog->fetchColumn(2); echo "<div id=\"blogpostcontent\">$contentone</div>" } ?> Is is better to store the DIV tags in the table upon the creation than having them on the frontpage index.php file?

No. That would result in less flexibility. For example, at some point you may want to use the data in a different way other rather than just dumping it to HTML and this would cause serious problems.

Also, is this the correct way to pass variables through URL?