Friday, November 29, 2013

Customize 404 Page for Concrete5

key word: Concrete5, CMS
On the surface, one of the draw backs of Concrete5 (or any CMS for that matter) is that there are portions of your site that seem untouchable. Specifically in Concrete5 the 'Login' page the 'Register' page and the '404 - Page Not Found' are glaring examples of when the CMS seems to take over your design and returns pages that are based off the native dashboard theme of Concrete5 and not your own stylish layout.
In this blog what want to take you step by step on how to change your "404 - Page Not Found" page. The benefit of doing this is twofold:

1st - If, God Forbid, someone should find a broken link on your site or simply type the wrong URL the result is a page that looks like it came from your website and not some misplaced step-child that the developer forgot about.
Below is a picture of what the out-of-the-box 404 page looks like:

basic404.PNG

2nd - According to the Google SEO Manuel, having a well thought out 404 page can actually help increase your search ranking and your user's experience:

SEO404.PNG



Step 1: locate site_theme_paths.php

To change the 404 page to reflect your custom theme you will need to open the root/config/site_theme_paths.php file. Make sure you DO NOT open root/concrete/config location. In Concrete5, all customizaton should be done in the top level:

root.PNG

Step 2: edit the site_theme_paths.php

When you open the file you should see this:
  1. <?php
  2. defined('C5_EXECUTE') or die(_("Access Denied."));
  3. //possible themes: default, core, greensalad, dark_chocolate, dashboard, greek_yogurt.
  4. /*
  5. you can override system layouts here - but we're not going to by default
  6. For example: if you would like to theme your login page with the Green Salad theme,
  7. you would uncomment the lines below and change the second argument of setThemeByPath
  8. to be the handle of the the Green Salad theme "greensalad"
  9. */
  10. /*
  11. $v = View::getInstance();
  12. $v->setThemeByPath('/login', "yourtheme");
  13. // $v->setThemeByPath('/403', "yourtheme");
  14. // $v->setThemeByPath('/register', "yourtheme");
  15. */

Some examples have been given to help you but it can be kind of confusing. So you will need to 'un-comment' line 15 and then add a condition for the 404 page. You your .php file should look like this:

  1. <?php
  2. defined('C5_EXECUTE') or die(_("Access Denied."));
  3. $v = View::getInstance();
  4. $v->setThemeByPath('/page_not_found', "retro_ryno");
  5. /*
  6. you can override system layouts here - but we're not going to by default
  7. For example: if you would like to theme your login page with the Green Salad theme,
  8. you would uncomment the lines below and change the second argument of setThemeByPath
  9. to be the handle of the the Green Salad theme "greensalad"
  10. */
  11. /*
  12. $v->setThemeByPath('/login', "yourtheme");
  13.  // $v->setThemeByPath('/403', "yourtheme");
  14.  // $v->setThemeByPath('/register', "yourtheme");
  15.  // $v->setThemeByPath('/dashboard', "yourtheme");
  16. //
  17. */
NOTE:
the examples indicate that you should put your theme's 'handle' in place of 'yourtheme'. But not all themes are built the same. The handle for our custom theme is: theme_retro_ryno but when we packaged up the theme we put the files in a folder named 'retro_ryno'. What's necessary for this little trick to work is to use your theme's actual folder name which may or may not be your theme's handle. E.G. our themes path looks like this:
root/packages/theme_retro_ryno/themes/retro_ryno/ . So we used the theme's actual folder name instead of it's handle.

Your 404 - page not found is now styled according to your theme! But, it would be nice to add some features to this to help your users out. a good idea would be to add a sitemap as well as a search function. Good news is that google now offers a 404 search bar that works with your site and the url error to try and offer other solutions. And, adding a SiteMap is pretty simple:

Step 3: customize the 404 - page not found.

  1. you will first need to copy and paste the , root/concrete/single_pages/page_not_found.php' into your root/single_pages/page_not_found.php. notice we are putting this page in the top level because we want to avoid making changes to concrete5.s core.
  2. open the new page_not_found.php file that you just created in the top level single_pages folder. and make it look like this:


  1. <?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
  2. <h1 class="error"><?php echo t('Page Not Found')?></h1>
  3. <?php echo t('No page could be found at this address.')?>
  4. <?php if (is_object($c)) { ?>
  5. <br/><br/>
  6. <?php $a = new Area("Main"); $a->display($c); ?>
  7. <?php } ?>
  8. <br/><br/>
  9. <?php
  10. $bt = BlockType::getByHandle('autonav');
  11. $bt->controller->orderBy = 'display_asc';
  12. $bt->controller->displayPages = 'top';
  13. $bt->controller->displaySubPages = 'all';
  14. $bt->controller->displaySubPageLevels = 'all';
  15. $bt->render('view');
  16. ?>
  17. <br/><br/>
  18. <a href="<?php echo DIR_REL?>/"><?php echo t('Back to Home')?></a>.

You should now have a 404 page not found for your site that is nicely styled and has a hard-coded sitemap that will automatically grow as your site grows.
If you would like to take this a step further...

Step 4: add google 404 help.

this will require you to have some kind of google account. Google offers a 404 widget which can be found in your Webmaster Tools portion of your account. Check to picture below to see the instructions and what's being offered:

google 404 widget

now, the choice is yours but it would be nice to add the widget above your Sitemap. The end result is really nice. click this link to see it in action:
http://www.rynomediaonline.com/contict/
what I did was mispell 'contact'. the Google 404 Widget detects that what I really wanted was the contact page and so automatically adds 'contact' to the search bar. Below this we have our sitemap in case the user would rather see the site that way.

ryno404.PNG

 Enjoy!

No comments:

Post a Comment