• Resolved staceyzav

    (@staceyzav)


    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)
  • 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?

    It can be used to grabbing any .php script that sites inside the theme folder itself. No real limits.

    @ 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

    (@staceyzav)

    So @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?

    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.

    Thanks for that esmi.

    @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)

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