Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Making a regular page template from Twenty Eleven Theme 404 page WordPress

  • SOLVED

If you go to this url ( a random one I selected to trigger the 404 page ) http://www.ledesmaphotography.com/?p=13272 you'll see how its displayed. I created a page template titled: Custom Archives.php which is the identical page as the 404.php but converted to a regular page template:

<strong>404.php Code</strong>
<?php
/**
* The template for displaying 404 pages (Not Found).
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/

get_header(); ?>

<div id="primary">
<div id="content" role="main">

<article id="post-0" class="post error404 not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'This is somewhat embarrassing, isn&rsquo;t it?', 'twentyeleven' ); ?></h1>
</header>

<div class="entry-content">
<p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching, or one of the links below, can help.', 'twentyeleven' ); ?></p>

<?php get_search_form(); ?>

<?php the_widget( 'WP_Widget_Recent_Posts', array( 'number' => 10 ), array( 'widget_id' => '404' ) ); ?>

<div class="widget">
<h2 class="widgettitle"><?php _e( 'Most Used Categories', 'twentyeleven' ); ?></h2>
<ul>
<?php wp_list_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'show_count' => 1, 'title_li' => '', 'number' => 10 ) ); ?>
</ul>
</div>

<?php
/* translators: %1$s: smilie */
$archive_content = '<p>' . sprintf( __( 'Try looking in the monthly archives. %1$s', 'twentyeleven' ), convert_smilies( ':)' ) ) . '</p>';
the_widget( 'WP_Widget_Archives', array('count' => 0 , 'dropdown' => 1 ), array( 'after_title' => '</h2>'.$archive_content ) );
?>

<?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>

</div><!-- .entry-content -->
</article><!-- #post-0 -->

</div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>


Here's my Custom Archive.php template's code (its identical over at this url http://www.ledesmaphotography.com/archive

<?php
/**
* Template Name: Archive Template
* Description: A Page Template that adds a custom archives
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/

get_header(); ?>

<div id="primary">
<div id="content" role="main">

<article id="post-0" class="post error404 not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'This is somewhat embarrassing, isn&rsquo;t it?', 'twentyeleven' ); ?></h1>
</header>

<div class="entry-content">
<p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching, or one of the links below, can help.', 'twentyeleven' ); ?></p>

<?php get_search_form(); ?>

<?php the_widget( 'WP_Widget_Recent_Posts', array( 'number' => 10 ), array( 'widget_id' => '404' ) ); ?>

<div class="widget">
<h2 class="widgettitle"><?php _e( 'Most Used Categories', 'twentyeleven' ); ?></h2>
<ul>
<?php wp_list_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'show_count' => 1, 'title_li' => '', 'number' => 10 ) ); ?>
</ul>
</div>

<?php
/* translators: %1$s: smilie */
$archive_content = '<p>' . sprintf( __( 'Try looking in the monthly archives. %1$s', 'twentyeleven' ), convert_smilies( ':)' ) ) . '</p>';
the_widget( 'WP_Widget_Archives', array('count' => 0 , 'dropdown' => 1 ), array( 'after_title' => '</h2>'.$archive_content ) );
?>

<?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>

</div><!-- .entry-content -->
</article><!-- #post-0 -->

</div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>


So the goal is for my custom archive.php to be displayed as the 404.php, right now its not.

Answers (2)

2012-06-19

Romel Apuya answers:

just copy the code from the 404.php to the archive.php

starting from the get_header()


<?php

/**

* Template Name: Archive Template

* Description: A Page Template that adds a custom archives

*

* @package WordPress

* @subpackage Twenty_Eleven

* @since Twenty Eleven 1.0

*/



get_header(); ?>



<div id="primary">

<div id="content" role="main">



<article id="post-0" class="post error404 not-found">

<header class="entry-header">

<h1 class="entry-title"><?php _e( 'This is somewhat embarrassing, isn&rsquo;t it?', 'twentyeleven' ); ?></h1>

</header>



<div class="entry-content">

<p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching, or one of the links below, can help.', 'twentyeleven' ); ?></p>



<?php get_search_form(); ?>



<?php the_widget( 'WP_Widget_Recent_Posts', array( 'number' => 10 ), array( 'widget_id' => '404' ) ); ?>



<div class="widget">

<h2 class="widgettitle"><?php _e( 'Most Used Categories', 'twentyeleven' ); ?></h2>

<ul>

<?php wp_list_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'show_count' => 1, 'title_li' => '', 'number' => 10 ) ); ?>

</ul>

</div>



<?php

/* translators: %1$s: smilie */

$archive_content = '<p>' . sprintf( __( 'Try looking in the monthly archives. %1$s', 'twentyeleven' ), convert_smilies( ':)' ) ) . '</p>';

the_widget( 'WP_Widget_Archives', array('count' => 0 , 'dropdown' => 1 ), array( 'after_title' => '</h2>'.$archive_content ) );

?>



<?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>



</div><!-- .entry-content -->

</article><!-- #post-0 -->



</div><!-- #content -->

</div><!-- #primary -->



<?php get_footer(); ?>


Jorge Ledesma comments:

Romel, that's exactly what I did, did you see the full text of what wrote, I simply created a page template from the actual code, yet its CSS is not displaying exactly as the 404.php page for some reason I can't quite get.


Romel Apuya comments:

add this in your header.php


find this line


<body <?php body_class(); ?>>


replace with


<body <?php if(is_page('archive')) { echo class="error404 two-column right-sidebar" ;} else { body_class(); }?> >


Jorge Ledesma comments:

Rumel, I get a white screen ( error screen ) with that code.


Romel Apuya comments:


<body <?php if(is_page('archive')) { echo 'class="error404 two-column right-sidebar"' ;} else { body_class(); }?> >


Jorge Ledesma comments:

Rumel, that did it !!! Thank You. You won !!

2012-06-19

Duncan O'Neill answers:

Save archive.php as 404.php, but WITHOUT the comments. i.e. leave out this bit;


/**

* Template Name: Archive Template

* Description: A Page Template that adds a custom archives

*

* @package WordPress

* @subpackage Twenty_Eleven

* @since Twenty Eleven 1.0

*/


Jorge Ledesma comments:

Duncan, I already have a 404.php its comes native with the Twenty Eleven theme. All I need is to copy the data from it and I created this custom archive.php so I can point it to the url of my choice ie. http://www.ledesmaphotography.com/archive/ but its not working as it should for some reason.

I tried what you said to delete the comments and that did not work either.


Duncan O'Neill comments:

I'm unclear what you're after. As I understand it, you want your 404 page to be identical to your archive page.

This should mean that [[LINK href=http://www.ledesmaportfolio.net/whatever-is-typed-here"]]http://www.ledesmaportfolio.net/whatever-is-typed-here[[/LINK]] displays the same as [[LINK href="http://www.ledesmaportfolio.net/archive/"]]http://www.ledesmaportfolio.net/archive/[[/LINK]], right?

As it is now, neither of those pages are displaying. I'm getting a real 404 not found response.

It looks as if you're using a child theme. IF this is the case, there should still be the original archive.php & 404.php in the parent theme's folder. Then you should "over-write" those with the relevant 404.php, and archive.php, as above, in the child theme folder.

hth,


Jorge Ledesma comments:

No Duncan. Twently Eleven comes with a very nice formatted 404.php. which if you click on the 1st url you'll get. I like it so much I wanted to use it as an archive page. So I created a page template with the 404.php code and I expected it to display visually the same way but its not and hence why I posted the question here. Hope the message is clear.


Duncan O'Neill comments:

I'm sorry I misunderstood.

OK, so do it the other way around. Restore your original archive.php, and save it as 404.php, but without this bit;


* Template Name: Archive Template

* Description: A Page Template that adds a custom archives

*

* @package WordPress

* @subpackage Twenty_Eleven

* @since Twenty Eleven 1.0

*/


That should do it?


Jorge Ledesma comments:

I created the template titled custom archive.php, if I save it as a 404.php how am I suppose to select it, if its not a page template ???


Duncan O'Neill comments:

Stop!!

What you have now is working. :-)

best,


Duncan O'Neill comments:

WP doesn't need the template bit. It knows it's a 404 page because of the name of the php file.