Solved

wordpress home page question

Posted on 2011-09-19
7
331 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
Comment Utility
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
Comment Utility
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
Comment Utility
FYI it's WP 3
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 23

Accepted Solution

by:
jeremyjared74 earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility

is_front_page()  is the condition.
0
 

Author Closing Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do disable only TLSv1.0 in Oracle Sun One 7.1 Server 9 33
WP WooCom Prob 7 25
css question 1 31
Help cleaning out CSS 2 22
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

771 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

11 Experts available now in Live!

Get 1:1 Help Now