Solved

wordpress home page question

Posted on 2011-09-19
7
333 Views
Last Modified: 2012-05-12
Hi Experts,

I'd like a banner to appear only on the page that is set as the home page.  It looks like I can add a line to the page.php file. I have no idea what the correct syntax is.... how do I test for the homepage?

ie:
<?php if (pageisdefault/homepage) : ?>
  <div id="coolHomePageBanner><img src="" /></div>

<?php endif; ?>

Thanks,

HNM
0
Comment
Question by:HelpNearMe
  • 3
  • 3
7 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36559988
I think you're trying for something like this:
<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
  <div id="coolHomePageBanner"><img src="<?php bloginfo('template_url'); ?>/images/something.jpg" /></div>
<?php } ?>

Open in new window

0
 

Author Comment

by:HelpNearMe
ID: 36562776
Thanks jeremyhared74,

It doesn't seem to work.  I've attached the code from page.php... maybe you can spot the problem?

thanks

HNM
<?php get_header(); ?>

<div id="main">

	<div id="content">
							
		<div id="contentArticleBody">
		
			<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
			
  				<div id="contentTopBanner"><img src="<?php bloginfo('template_directory'); ?>/images/contentTopBanner.jpg" alt="adf" title="asdfasdf"></div><!-- #contentTopBanner -->

			<?php } ?>
			
			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
		
				<div class="post" id="post-<?php the_ID(); ?>">

					<h2><?php the_title(); ?></h2>
			
					<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
			
					<div class="entry">

						<?php the_content(); ?>
			
						<?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
			
					</div>

					<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

				</div>
	
			<?php // comments_template(); ?>

			<?php endwhile; endif; ?>
	
		</div><!-- contentArticleBody -->
										
		<div id="contentRightColumn">
			
			<div id="contentRightColumnPromoA"></div><!-- #contentRightColumnPromoA -->
			
			<div id="contentRightColumnPromoB"></div><!-- #contentRightColumnPromoB -->
		
		</div><!-- #contentRightColumn -->
						
	</div><!-- #content -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Open in new window

0
 

Author Comment

by:HelpNearMe
ID: 36562779
FYI it's WP 3
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 23

Accepted Solution

by:
jeremyjared74 earned 250 total points
ID: 36563055
OK, this will work.

Add this just before <?php wp_head(); ?>, in the header.php file:
<?php if (is_home()) { ?>
<div id="contentTopBanner">
  <img src="<?php bloginfo('template_url'); ?>/images/wrapper_bg.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
</div><!-- #contentTopBanner -->
<?php } ?>

Open in new window


You'll need to change it to you image. You had an error on the closing image tag on your code. I'm not sure if that was it or not.

If you need to add it somewhere else, if you can't get the image to go where you want using CSS, you'll need to add a custom page template and assign a page that will be your home page to that template in the page editor. Next you'll need to go to Settings>Reading> Front Page Displays.... and choose your page which you assigned to the custom template.
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36563074
You won't actually need to add a custom template, just be sure the page you assign as the home page actually uses the page template that you are adding the code to. You should be able to add it to the header as I suggested without any problems though. If not let me know and I'll try to help you out.
0
 
LVL 3

Assisted Solution

by:ovi_mihai
ovi_mihai earned 250 total points
ID: 36565287

is_front_page()  is the condition.
0
 

Author Closing Comment

by:HelpNearMe
ID: 36566175
ovi mihai, you are right, when I added that condition it worked!  THanks to both of you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Read about why website design really matters in today's demanding market.
The viewer will learn how to count occurrences of each item in an array.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now