1

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..)

1 Answer 1

1

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' );
3
  • 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
    Commented Feb 24, 2013 at 4:51
  • Kindly see this link.. wordpress.stackexchange.com/questions/88171/… you can understand my exact issue.. Thanks Mr.Matthew
    – Venkat
    Commented Feb 24, 2013 at 14:47
  • @Venkat see edits. Good luck, I hope this helps! Commented Feb 25, 2013 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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