Custom Page Templates Causes Errors
-
I have worked with wordpress before with never a problem. The codex is wonderful at solving most of my problems. But alas, I have come across something that leaves me completely baffled.
I read and re-read and re-read the information on how to create a custom template. So I did that but then when I set my front page to use the template, one of two things happen.
I either get strings of odd code in the header and /par/par /tab/tab showing up in the middle of the content OR it tells me that there is an error in the template on line 2.
Here is what I’m trying to do. The front page has content then a slider shows 5 featured blog posts. The posts are on another page (blog).
However, I don’t want the slider showing the featured posts on every single page, which is what happens when I change the
page.php
template.So I tried to create a template named “Slider” based on the instructions given here: https://codex.www.ads-software.com/Pages#Creating_Your_Own_Page_Templates for the front page, leaving
page.php
with it’s original code in the custom theme to handle the other pages. I’ve even tried making a “noslider” template for the other pages instead, but I get the same result – the error telling me there is something wrong with line 2.If I go with creating a file named
front-page.php
then the funky code shows up all over the place.Is there something I’m missing? This is really driving me nuts, because I know it works!
Here is the code for
page.php
(with the slider)<?php get_header(); ?> <div id="content"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="single" id="post-<?php the_ID(); ?>"> <div class="title"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> </div> <div class="cover"> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> <div class="clear"></div> <?php wp_link_pages(array('before' => '<p><strong>Pages: </strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> </div> </div> </div> <?php endwhile; endif; ?> <div class="slidercontent"> <?php include (TEMPLATEPATH . '/slide.php'); ?> <?php include (TEMPLATEPATH . '/ad1.php'); ?> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
But when I try to make a template for the other pages using this code:
<?php /* Template Name: NoSlider */ ?> <?php get_header(); ?> <div id="content"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="single" id="post-<?php the_ID(); ?>"> <div class="title"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> </div> <div class="cover"> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> <div class="clear"></div> <?php wp_link_pages(array('before' => '<p><strong>Pages: </strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> </div> </div> </div> <?php endwhile; endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
everything is messed up. Is it because I’m copying the exact same loop code over again?
Thanks in advance for any help with this.
- The topic ‘Custom Page Templates Causes Errors’ is closed to new replies.