How to get rid of 404 Page not Found message when there are no blog posts
Following the tutorial blog, I wanted to see what happens when there are no blog posts to display.
What happens is you get a 404 Page not Found message on the home page. Not very nice.
I've tried a few ways to change this, none work:
1.
In my home page I wrote this code:
if(!empty($posts)): ?>
<?php foreach($posts as $post) : ?>
-
<?php echo $post->get_excerpt(200, 'Read More'); ?>
<?php endforeach; ?>
<?php else: echo "There are currently no posts to display."; ?>
<?php endif;
That didn't change anything, still get 404
2.
In the blog.php controller I changed:
function post($permalink = null)
{
if (empty($permalink)) show_404();
to: if(empty($permalink)) echo "There are currently no posts to display.";
That didn't change anything, still get 404
3.
In the blog.php controller I changed:
function pjost($permalink = null)
{
Line 210:
From: else
{
show_404();
}
To:
else
{
echo "There are currently no posts to display.";
}
That just removed the whole content of the home page and displayed: There are currently no posts to display.
So, how can I change this behaviour?
Can someone please help?
Comments
It is a site I am playing with on my local machine, trying to learn how to use fuelcms
In there I instaelld Fuelcms.
When I go to localhost/fueldemo
I see the link to the blog's post: "A long, long time ago, in a galaxy far, far away"
although the post is 'Unplublished'. I am not logged on to the site.
When I click on the link I go to: http://localhost/fueldemo/blog/2010/11/06/a-long-long-time-ago-in-a-galaxy-far-far-away
And I get the error page not found.
So now the problem is, why do I see the link to the blog on the home page, when the post is unpublished.
call $CI->fuel_blog->recent(3)
add published = "yes" to the fuel_model where condition
Also, you say: "The blog_posts_model doesn't call the parent _common_query" if I look at the blog_posts_model I see this function:
function _common_query()
{ ...some code in here...
}
Is that not calling the parent _common_query?
Thank you
The blog_posts_model's _common_query is missing a call to it's parent model like so:
function _common_query(){ parent::_common_query(); .... }