Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

wordpress home page question

Posted on 2011-09-19
7
Medium Priority
?
341 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
Implementing Azure Infrastructure Exam 70-533

This course is designed to familiarize and instruct students in the content that is covered by Microsoft Exam 70-533, Implementing Microsoft Azure Solutions. It focuses on all the November 2016 objective domain topics.

 
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

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 …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to dynamically set the form action using jQuery.
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.

688 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