How to get rid of 404 Page not Found message when there are no blog posts

edited May 2012 in News & Announcements
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 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

  • edited 3:39PM
    What's the URI path of where you are getting a 404 page?
  • edited 3:39PM
    Hi admin,

    It is a site I am playing with on my local machine, trying to learn how to use fuelcms
  • edited 3:39PM
    On your local machine, is it something like http://localhost/blog/ ?
  • edited 3:39PM
    ok, on my www folder I have a folder called: fueldemo.

    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.
  • edited June 2012
    That is a bug in the demo. The blog_posts_model doesn't call the parent _common_query and so it doesn't filter out unpublished content. You can alternatively call $CI->fuel_blog->get_recent_posts(3). Or, if you add published = "yes" to the fuel_model where condition, that will fix the issue.
  • edited 3:39PM
    Sorry, can you tell me where do I add these lines? Which file?
    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
  • edited 3:39PM
    You can add that to the home.php view file around line 17. And it's actually "get_recent_posts" (I changed it in my previous post too to avoid further confusion).

    The blog_posts_model's _common_query is missing a call to it's parent model like so:
    function _common_query(){ parent::_common_query(); .... }
Sign In or Register to comment.