Support » How-To and Troubleshooting » Can 404 page use a different page template?

Can 404 page use a different page template?

  • I have a 404 page that uses the layout on 404.php, but I would like the page to be displayed using the page template specified in the page editor.

    For example:

    mysite.com/404 displays the the layout from the selected page template in the page editor

    mysite.com/wrongurl displays the layout from the 404.php file

    I need both to display the layout from the selected page template, therefore overriding what is in the 404.php file. How do I go about this? Our page editor also has a custom sidebar option and I need to be able to retain that as well, not just the layout.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Thanks Tara, but it’s not quite what I needed (though I had already checked there before posting here). What I want to do in the 404.php file is say “if this page template is being used for the 404 page, then do this”.

    I tried this function but it’s still not working: http://codex.wordpress.org/Function_Reference/is_page_template

    I just want to change the class name of a div if a certain template is being used. I’ve done this with the code:

    <!--- Use Page Templates -->
    <?php $pt_class = ''; ?>
    <?php if($is_page_template['page.php'] ): ?>
    <?php $pt_class = 'span12'; ?>
    <?php elseif($is_page_template['template-leftsidebar.php'] ): ?>
    <?php $pt_class = 'pull-right'; ?>
    <?php elseif($is_page_template['template-rightsidebar.php'] ): ?>
    <?php $pt_class = 'pull-left'; ?>
    <?php endif; ?>
    <?php $sb_float = ''; ?>
    <?php if($is_page_template['page.php'] ): ?>
    <?php $sb_float = 'hidden'; ?>
    <?php elseif($is_page_template['template-leftsidebar.php'] ): ?>
    <?php $sb_float = 'pull-left'; ?>
    <?php elseif($is_page_template['template-rightsidebar.php'] ): ?>
    <?php $sb_float = 'pull-right'; ?>
    <?php endif; ?>
    <div class="<?php echo $content_span_class; ?> <?php echo $pt_class; ?>">
    <div class="bs-docs-sidebar <?php echo $sb_span_class; ?> <?php echo $sb_float; ?> <?php echo $sb_class; ?>">

    The $sb_float and $pt_class info doesn’t show up on the front end, so I’m not sure what’s wrong. It’s driving me a little insane staring at this code trying to figure it out, especially considering I’m no PHP expert by any stretch.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can 404 page use a different page template?’ is closed to new replies.