• Hi
    I have a site using a theme that has a slider on every page based on featured posts (Papyrus theme). I just want the slider on the home page. Could someone help me write the conditional statement.

    In the theme’s header.php file there is the following:

    <!– Featured section starts here –>
    <div id=”featured_section”>
    <?php get_template_part( ‘featured’, ‘posts’ ); ?>
    </div>
    <!– Featured section ends here –>

    Would I put:

    if is_front_page()
    <div id=”featured_section”>
    <?php get_template_part( ‘featured’, ‘posts’ ); ?>
    </div>
    ….

    How would the else… statement go if I don’t want anything there in that space on all other pages. Slider only on home page.
    Using WP 3.5

    Thank you for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Kristad,

    If you want to apply the slider only on the home page you could do something like this:

    <?php
    	if(is_home()){
     ?>
     <!-- Featured section starts here -->
    <div id="featured_section">
    <?php get_template_part( 'featured', 'posts' ); ?>
    </div>
    <!-- Featured section ends here -->
    <?php } ?>

    Simply leave the else empty if the theme doesn’t break.
    Otherwise, you could do this:

    <?php
    	if(is_home()){
     ?>
     <!-- Featured section starts here -->
    <div id="featured_section">
    <?php get_template_part( 'featured', 'posts' ); ?>
    </div>
    <!-- Featured section ends here -->
    <?php }else{ ?>
    <div id="featured_section" style="visibility:hidden;">
    &nbsp;
    </div>
    <?php } ?>

    I hope this help,

    Julien

    Thread Starter Kristad

    (@kristad)

    Thanks Julien7
    I tried both… First option – there was no featured section at all on any page.
    The second option, left an black empty feature section.
    Here is a link to the start of the site…
    http://sierramarketing.ca/apples/

    I noticed there is a featured-posts.php

    <?php global $papyrus_option; ?>
    <!– Featured slider starts here –>
    <?php query_posts(‘ignore_sticky_posts=1&post_type=post&meta_key=_slider&meta_value=yes&showposts=’.$papyrus_option[‘main’][‘number_posts’]); ?>
    <?php if (have_posts()) : ?>
    <div id=”featured_slider”>
    <div id=”slides”>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”item”>
    <div class=”pic”>
    <?php if ( has_post_thumbnail()) : ?>
    ” title=”<?php the_title_attribute(); ?>”><?php the_post_thumbnail(‘papyrus’); ?>
    <?php endif; ?>
    </div>

    <div class=”featuredesc”>
    <h2>” title=”<?php the_title_attribute(); ?>”><?php echo papyrus_get_limited_string(get_the_title(), 40, ‘…’) ?></h2>
    <p><?php echo papyrus_get_limited_string(get_the_excerpt(), 150, ‘…’) ?></p>
    <p>” class=”btn_more”><span><?php _e(‘Read More’,’papyrus_wdl’); ?></span></p>
    </div>

    </div>
    <?php endwhile; ?>
    </div>
    <div id=”nav”><div></div></div>

    </div>
    <?php endif; wp_reset_query(); ?>
    <!– Featured slider ends here –>

    Not sure if this helps…
    Thanks again.
    K.

    Hi,

    I think that this should do the trick:

    <?php
    	if( is_page( 'apples' ) ){
     ?>
     <!-- Featured section starts here -->
    <div id="featured_section">
    <?php get_template_part( 'featured', 'posts' ); ?>
    </div>
    <!-- Featured section ends here -->
    <?php }?>

    Julien

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘conditional statement for home page’ is closed to new replies.