Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My index page look like this...

    <div id="ad-id">google ad code goes here </div><br />
    <div id="post-id">My posts are goes here</div>

I use

    get_template_part('index') 

in another page template. But I want index's posts only NOT google ads.

Help me..

Thanks in advance..)

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

In your index template, you'll want to add a conditional around your Google ad. The subject of that conditional is up to you, and will depend on your exact needs. For instance, if you want it to show on the homepage but not other pages, you can check if is_home(). If your needs are more abstract, you can define a global variable and set it as appropriate before your get_template_part call, e.g. $GLOBALS['show_ad'] = true; and then only display the Google ad if that's true.

Edit: Examples

Say you want to show this only on your homepage. Here's what your index page should look like...

<?php if ( is_home() ) : ?>
<div id="ad-id">google ad code goes here </div><br />
<?php endif ?>
<div id="post-id">My posts are goes here</div>

Or, say your needs are more abstract. Here are both pages with a global variable.

index page:

<?php if ( isset( $GLOBALS['show_ad'] ) && true == $GLOBALS['show_ad'] ) : ?>
<div id="ad-id">google ad code goes here </div><br />
<?php endif ?>
<div id="post-id">My posts are goes here</div>

Calling template:

# Show the ad
$GLOBALS['show_ad'] = true;
get_template_part( 'index' );

... or...

# Don't show the ad
$GLOBALS['show_ad'] = false;
get_template_part( 'index' );
share|improve this answer
    
Thanks for your answer. I can understand little because am not php familiar more. So kindly give some example codes. It will help me.. Thanx –  Venkat Feb 24 '13 at 4:51
    
Kindly see this link.. wordpress.stackexchange.com/questions/88171/… you can understand my exact issue.. Thanks Mr.Matthew –  Venkat Feb 24 '13 at 14:47
    
@Venkat see edits. Good luck, I hope this helps! –  Matthew Boynes Feb 25 '13 at 0:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.