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 6 replies - 31 through 36 (of 36 total)

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

 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541959)
 * Thanks, esmi. From the codex description I was lead to beleive “template_part”
   was for getting “part” of another template, but not all of it, which didn’t make
   sence to me so I never tried it.
    I assume template_part works the same? And 
   no reason for include?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541963)
 * It can be used to grabbing any .php script that sites inside the theme folder
   itself. No real limits.
 *  [MickeyRoush](https://wordpress.org/support/users/mickeyroush/)
 * (@mickeyroush)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541965)
 * @ esmi. I don’t mean to derail or hijack this thread. Could you please explain
   why using ‘include’ is a bad idea?
 * Thanks.
 *  Thread Starter [staceyzav](https://wordpress.org/support/users/staceyzav/)
 * (@staceyzav)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541969)
 * So [@esmi](https://wordpress.org/support/users/esmi/) – I should add this to 
   the top of my archive.php page
 *     ```
       <?php
       $post = $wp_query->post;
       if (is_page('home')) {
       	get_template_part( 'slideshow' );
       	return;
       }
       get_header(); ?>
       ```
   
 * Along with this on my index.php page
 *     ```
       <?php
          if(is_home() || is_front_page()) include ('slideshow.php');
          else include ('archive.php');
       ?>
       ```
   
 * is that what you are saying? Would I need to add anything to my slideshow.php
   file too?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541973)
 * > Could you please explain why using ‘include’ is a bad idea?
 * Because to use an include you have to rely on some sort of path – which means
   either using a hard-coded path or using something like `TEMPLATEPATH`. The latter
   is an internal variable that should never be used in a theme. The former totally
   wrecks any theme portability, so again, is bad practice in theme development 
   terms.
 *  [deepbevel](https://wordpress.org/support/users/deepbevel/)
 * (@deepbevel)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-conditional-statement/page/3/#post-2541982)
 * Thanks for that esmi.
 * [@mickey](https://wordpress.org/support/users/mickey/)
 * In the first code,you’re telling wp to direct any page named “home” which trys
   to use archive.php to use slideshow.php instead.
 * In the second code, let me test my undstanding here:
    I’m not so sure that can
   appy in a main loop, as pages don’t reference your main loop or index, as individual
   posts do. A page can’t be a post taxonomy. So that 2nd code won’t do anything,
   unless I’m confused about this.(esmi?)
 * If you add anything to slideshow.php it would redirect any pages which try to
   use it, but if I understand, no page is using it by default, so that shouldn’t
   be a concern.

Viewing 6 replies - 31 through 36 (of 36 total)

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

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
