Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

wordpress home page question

Posted on 2011-09-19
7
Medium Priority
?
344 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 23

Accepted Solution

by:
jeremyjared74 earned 1000 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 1000 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses

971 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