Solved

wordpress home page question

Posted on 2011-09-19
7
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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.

623 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