Support » Fixing WordPress » div class showing up in main page and on posts

  • Can I make a <div class> show up on posts and not on the main page?

    I added this to my CSS file:

    .adsense {

    display: block;

    float: left;

    padding: 10px;

    I added this to my posts:

    <div class=”adsense”><!–adsense#post–></div>

    This is to wrap the text around an adsense block.

    How can I get the div class to only show up when someone clicks a title to view the post?

    I get an empty 10px box of white space on the main page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Any ideas on how I can get the main page to ignore that <div>? Thanks!

    If you want it only in the single post view… why don’t you insert your code in the single.php template file?
    Explanation: Template_Hierarchy.

    Moshu, if I did it that way then I can’t control where the ad is placed in my post. Editing the single.php file would only allow my to place it between the title and the content. I can’t control where it goes in the content.

    I just want the main page to ignore a div tag that shows up in the post.

    Depending on your theme, assign a body id to single.php such as <body id="single-page"> and then in your css, use a very specific CSS such as

    body .adsense {display: none; }
    #single-page .adsense { display: block; float: left; padding: 10px; }

    That way when someone clicks on a specific post, it will trigger your adsense code.

    I agree with Moshu BTW. Just put the code directly in between the title and post and use margins to put it where you want. Remember when you float an element, you’re removing it from the normal flow of things which means you can change its position via margins.

    I’m new to CSS as you can tell, your solution worked like a charm, thanks.

    Just a question, what’s the purpose of this line?

    body .adsense {display: none; }

    I understand the second it means use the adsense class only on a page that has body id=”single-page” is that right?

    Thanks for the solution.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘div class showing up in main page and on posts’ is closed to new replies.