I have the site navigation menu in the left sidebar set to be displayed on all pages. However, if a user navigates to an invalid page, he'll get a "Page not found" page with no menu or sidebar - just the message itself, along with the site title and footer. How do I make the navigation menu/sidebar display on the "page not found" page?

Thanks.

Comments

nitro322’s picture

Well, I gave up on looking for an option to make this work correctly and started digging through the source code instead. I found the function that controls this page display in includes/common.inc:
function drupal_not_found()

The bottom of the function includes this line:
print theme('page', $return, FALSE);

Removing FALSE from that line makes it display the blocks properly. Easy fix, but it'd really be nice to have a proper option for this instead of requiring code modification. Now I need to remember to change this every time I upgrade Drupal.

isaac77’s picture

Thanks for posting this; I noticed the same problem.

My workaround:

- create a node that includes a "page not found" message AND the links you want. I just added links to /search/node and to the front page, but I'm guessing you could print your entire navigation menu as well. print menu_tree(); (Or something like that. Obviously one would have to supply parameters to indicate which menu, what depth, etc.)

- at admin/settings/error-reporting tell drupal to use this node as the "page not found" message

BTW, the "access denied" (403 error page) DOES print the navigation menu by default. Hmmmm. Maybe you should report the lack of menus on the 404 page as a potential bug?

Ole Martin’s picture

The bottom of the function includes this line:
print theme('page', $return, FALSE);

Removing FALSE from that line and writhe TRUE insted. If not it woudn work out for me.

regards
Ole Martin
http://www.drupal.no
http://www.drupal1.no

ronan’s picture

To do this without modifying core. Add the following to your template.php file

function NAMEOFYOURTHEME_page($content, $show_blocks = TRUE) {
  return phptemplate_page($content, TRUE);
}

replace NAMEOFYOURTHEME with the actual name of your theme.

This will make sure blocks are never turned off.
------------------------------------
Ronan - Gorton Studios - http://www.gortonstudios.com/

------------------------------------
Ronan
Founder - NodeSquirrel - https://www.nodesquirrel.com/
Agency Tools Lead - Pantheon - https://www.pantheon.io/

Christopher Herberte’s picture

Perfect, this did the trick. I have been wanting a fix for this one for ages!

Stomper’s picture

Very new to Drupal and PHP. I am having the same issue. I attempted to insert this code fragment into a "custom" Zen theme.

I am trying to insert a forum into one my menu primary links.

I just copy and pasted it into the end of the template.php, changed NAMEOFYOUTHEME to my Zen theme and saved it. This is the only change/edit I've made to the template.php file.

Upon refreshing my Drupal site this error was thrown up

"Parse error: parse error in C:\xampp\htdocs\drupal515\themes\zen\zen_stomper\template.php on line 309"

Advice?

rolodmonkey’s picture

If you want a workaround that does not require modifying the core, try this. In your page.tpl.php file, replace:

print $sidebar_left;

with:

print theme('blocks', 'left');

Still, I agree that this should be a setting somewhere.

--

Read more at iRolo.net

rolodmonkey’s picture

After thinking about it over the weekend, I realized that the code above will cause theme('blocks', 'left') to be called twice on normal pages. It would be better to do something like this:


if (isset($sidebar_left) && $sidebar_left != "") {
  print $sidebar_left;
} else {
  print theme('blocks', 'left');
}

--

Read more at iRolo.net

robbertnl’s picture

Is a Drupal 6 solution available as well?
Same issue..

vivianspencer’s picture

yes, there's a solution here: http://drupal.org/node/129762#comment-1013470

- Vivian