WordPress.org

Ready to get started?Download WordPress

Forums

Problem with Conditional Tags on Home Page (5 posts)

  1. ALTexasGirl
    Member
    Posted 5 years ago #

    I'm having some minor trouble with my theme.

    I made some modifications to the loop on the home page, but for some reason, I can't get any conditional tags to display text just on the home page. I don't know if I've got some type of incorrect code in the loop, but after installing some sample php code in the far right sidebar, I'm not getting it to display.

    This is what my index file is using:

    <?php get_header(); ?>
    
    	<div id="page">
    
    		<div id="contentleft">
    
    <?php if ( is_home()) { // Do stuff specific to first page?>
    
    <?php include (TEMPLATEPATH . '/features.php'); ?>
    
    			<div id="content">
    
    <h2 class="darkgreen">CONTENT</h2>
    <div class="homep">
    CONTENT
    </div>
    
      <h2 class="black">FIRST LOOP SECTION</h2>
    <div class="homep">
        <?php
        	$otherPosts = new WP_Query();
        	$otherPosts->query('showposts=3&cat=199');
        	while($otherPosts->have_posts()) : $otherPosts->the_post();
        ?>
    <strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></strong><?php the_excerpt(); ?>
    
        <?php endwhile; ?></div>
    
    <h2 class="lightgreen">SECOND LOOP SECTION</h2>
    <div class="related">
        <?php $temp_query = $wp_query; ?>
        <?php query_posts('category_name=wta-tennis&showposts=1'); ?>
        <?php while (have_posts()) : the_post(); ?>
    <?php if (get_post_meta($post->ID, post_thumbnail)) { ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, post_thumbnail, true); ?>" class="post-thum" alt="post thumbnail" /></a>
    <?php } ?><font size="+1"><strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></strong></font>
    <?php the_excerpt(); ?><?php endwhile; ?>
    
            <strong>More Stories:</strong>
    <?php $posts = get_posts('category=83&numberposts=15&offset=1');
        foreach ($posts as $post) : start_wp(); ?>
            <ul><li><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></li></ul>
            <?php endforeach; ?>
      </div>
    
    					<h2 class="lightgreen">CONTENT</h2>
    				<div class="related">
    CONTENT
    </div>
    
    <?php } else { // Do stuff specific to non-first page ?>
    
    			<div id="content">
    
    				<h2 class="sectionhead">Recent Articles</h2>
    
    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    
    				<div class="post" id="post-<?php the_ID(); ?>">
    
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    <?php if (get_post_meta($post->ID, post_thumbnail)) { ?>
    							<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, post_thumbnail, true); ?>" class="post-thum" alt="post thumbnail" /></a>
    <?php } ?>
    
    					<div class="entry">
    							<?php the_excerpt(); ?>
    
    					</div>
    
    				<div class="navigation">
    
    					<div class="alignleft">
    						<?php next_posts_link('&laquo; Previous Entries') ?>
    					</div>
    
    					<div class="alignright">
    						<?php previous_posts_link('Next Entries &raquo;') ?>
    					</div>
    
                    		</div>
    				</div>
    
    <?php endwhile; endif; ?>
    
    <?php } ?>
    
    			</div>
    
    <?php include (TEMPLATEPATH . "/sidebar1.php"); ?>
    
    		</div>
    
    <?php get_sidebar(); ?>
    
    	</div>
    
    <?php get_footer(); ?>

    Also this is the test code in the sidebar which is not displaying:

    <?php if (is_home()) { ?>
    test
    
    <?php } ?>

    If someone could help me out, I would really appreciate it! Although I've been playing around with WordPress for several years, I'm very much a newbie when it comes to custom loops.

    THANK YOU!

  2. stvwlf
    Member
    Posted 5 years ago #

    hi

    the test for the homepage is if(is_front_page())

    is_home() refers to the blog page even if its not the home page

    Once you declare a static homepage use is_front_page()

    Yes, its confusing

  3. ALTexasGirl
    Member
    Posted 5 years ago #

    stvwlf,

    Thanks for your help!

    How would I declare a static home page? I checked in the WP dashboard and it currently says that the front page displays the latest posts.

  4. stvwlf
    Member
    Posted 5 years ago #

    Admin / Settings / Reading declare static page as home page, can also set another page (that you create) up as the posts page.

  5. ALTexasGirl
    Member
    Posted 5 years ago #

    When I looked at the static page, all I saw listed under the dropdown menu was my WordPress pages. I didn't select any, as I still want the latest posts to display.

    Is there something else that I need to change? Or a way that I can still show the latest posts while still declaring the index php file as the front page?

Topic Closed

This topic has been closed to new replies.

About this Topic