Title: Adding conditional statement
Last modified: August 20, 2016

---

# Adding conditional statement

 *  Resolved [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/)
 * I am creating a theme and I need my index.php to behave in the following manner:
 * >> If you are on the home or front page the file: slideshow.php is used.
    >> 
   If it is not the home or front page, the file: archive.php is used.
 * Basically, I would like the user to be able to designate a “posts” page in the
   settings (in this case, I chose a page named “blog”) without having to designate
   a home page, so that they may use the home page template w/o having to create
   a page and assign a home page template. I would like this to happen automatically.
   The only thing they will need to do is assign a “posts” page.
 * Here is the code I came up with on the index.php page. It behaves as I wish for
   the homepage, but I cannot get my desired results for the “blog” page. Currently
   this code is producing the slideshow.php template on both the home page and the“
   blog” page that I have selected.
 * <?php if ( is_home() || is_front_page()) { include (‘slideshow.php’); }
    elseif(
   is_page()) { include (‘archive.php’); }
 * ?>
 * Please let me know if you need more explanation.

Viewing 15 replies - 16 through 30 (of 36 total)

[←](https://wordpress.org/support/topic/adding-conditional-statement/?output_format=md)
[1](https://wordpress.org/support/topic/adding-conditional-statement/?output_format=md)
2 [3](https://wordpress.org/support/topic/adding-conditional-statement/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-conditional-statement/page/3/?output_format=md)

 *  Thread Starter [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541894)
 * I was thinking of going that route if I couldn’t get the conditional to work –
   I just thought the conditional statement would have been easier for the end user.
   But, really – I guess they have would have had to declare settings in either 
   case!
 * Thank you anyway for your help! I appreciate your time!
 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541895)
 * Trust me… I get it. That’s all we do where I work… try to make things easier 
   for the end user. In fact, the easier it is for them to use the system, the more
   coding it is on our end!
 * Good luck and let me know if there’s anything else I can help with.
 *  Thread Starter [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541896)
 * Thanks again!
 * Actually, now I remember why I didn’t want to go the page template route – when
   I declare the slideshow.php as a a page template and selected that for the front
   page, it doesn’t pull in the latest posts anymore on the bottom of the page, 
   as I intended. Now it pulls in the info from that page.
 * What I want is a the slideshow as you see, with the widgets as you see them and
   then below that the 2 latest “posts”
 * Any ideas on how to achieve this and still have a way to have the blog page as
   it is now?
 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541897)
 * Can you post the code for slideshow.php?
 *  Thread Starter [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541899)
 * It’s really long but here is the loop – basically the same loop.
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>  
   
              <div class="exerptpost">
   
        <?php the_post_thumbnail(array(230,230), array('class' => 'archimg')); ?>
        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1><div class="entrydate"><?php the_time('l, F jS, Y') ?> </div>
            <p><?php echo excerpt(145); ?></p></div>
   
           <?php endwhile; ?>  
   
          <div class="navigation">
               <?php posts_nav_link(); ?>
   
               <?php endif; ?>
       ```
   
 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541901)
 * Gotcha… so here’s the deal… you’ll need a second loop, outside the main loop,
   where you want these top posts to go… So where ever you want it to show, add:
 *     ```
       <?php
       $args=array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 2
       );
       $my_query = null;
       $my_query = new WP_Query($args);
       if($my_query->have_posts()) :
          while($my_query->have_posts()) :
             $my_query->the_post();
             { Your code here }
          endwhile;
       endif;
       ?>
       ```
   
 * Your first loop will pull the content from the page itself… this second loop 
   with get the latest 2 posts. Not tested, but should be closer to what you are
   looking for…
 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541902)
 * Or since you aren’t showing any “page” content on the homepage (looks like just
   a slideshow) you could probably replace the one loop with my code… or just this:
 * [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 * to get just the top two posts… many options!
 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541903)
 * i did my best to follow this thread, if I follow correctly, you might try this
   in slideshow.php
 *     ```
       <?php	 	
   
       $post = $wp_query->post;
       if (!is_page('home')) {
       	include (TEMPLATEPATH.'/archives.php');
       	return;
       }
   
       get_header(); ?>
       ```
   
 * As for the two latest posts, just use query_posts in a static home page with 
   the slider, you can still exclude the page from using archive.php in the conditional.
 *  Thread Starter [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541905)
 * I think I’m following you – just not sure what to put in the { Your code here}
   part.
 * I also think I need some sleep! Thanks again – I’ll let you know tomorrow if 
   I get it working !
 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541906)
 * Get to bed. When you wake up, replace get_header in slideshow.php with that code.
   I have a feeling you’re due much joy.
 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541907)
 * Looks like, according to your posted code, you’d add something like this in the{
   Your Code Here }:
 *     ```
       <div class="exerptpost">
        <?php the_post_thumbnail(array(230,230), array('class' => 'archimg')); ?>
        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
        <div class="entrydate"><?php the_time('l, F jS, Y') ?></div>
        <p><?php echo excerpt(145); ?></p></div>
       ```
   
 * Good luck and let me know… check out that get_posts() link I sent you… might 
   be easier than what I’m suggesting. It’s late and now I’m over complicating things
   🙂
 *  Thread Starter [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541947)
 * YESSSS! IT WORKS!!!!
 * Thank you both so much for your help.
 * I tried all three suggestions and here is what happened:
 * [@deepbevel](https://wordpress.org/support/users/deepbevel/) – it still pulled
   in the archive.php for both pages. Again – I’m baffled by this, b/c the logic
   seems spot on. I must have something else going on that is messing with it!
 * @wpismypuppet – I couldn’t figure out the more complicated one that you gave 
   me but the get_posts() link you sent worked like a charm! I now have the 2 latest
   posts and being pulled into the home page via the slideshow script (that I turned
   into a page template) and the blog page is using the archive.php
 * THANK YOU AGAIN!
 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541952)
 * You are welcome… see, when you work too long at a particular issue things start
   to get blurry. The code I sent you was one that I used for a much more complex
   issue… but it was so late I forgot about the simple get_posts() function. Glad
   it worked out! From now on we’ll all get more sleep 🙂
 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541955)
 * Glad to hear you made progrss.
    If the page template is still an issue, you might
   try the opposite, put similar code in archives.php instead of slideshow.php. 
   it should say “if it’s home, use slideshow.php” Like this:
 * At the very top of archives.php:
 *     ```
       <?php	 	
   
       $post = $wp_query->post;
       if (is_page('home')) {
       	include (TEMPLATEPATH.'/slideshow.php');
       	return;
       }
   
       get_header(); ?>
       ```
   
 * also, two ways to specify, might try both.
 *     ```
       (is_page('home'))
       ```
   
 * or
 *     ```
       if (is_home())
       ```
   
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/2/#post-2541958)
 * Don’t use `TEMPLATEPATH`. Using `include` is also a bad idea.
 *     ```
       <?php
       $post = $wp_query->post;
       if (is_page('home')) {
       	get_template_part( 'slideshow' );
       	return;
       }
       get_header(); ?>
       ```
   
 * [http://codex.wordpress.org/Function_Reference/get_template_part](http://codex.wordpress.org/Function_Reference/get_template_part)

Viewing 15 replies - 16 through 30 (of 36 total)

[←](https://wordpress.org/support/topic/adding-conditional-statement/?output_format=md)
[1](https://wordpress.org/support/topic/adding-conditional-statement/?output_format=md)
2 [3](https://wordpress.org/support/topic/adding-conditional-statement/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-conditional-statement/page/3/?output_format=md)

The topic ‘Adding conditional statement’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 36 replies
 * 5 participants
 * Last reply from: [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541982)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
