WordPress.org

Ready to get started?Download WordPress

Forums

div class showing up in main page and on posts (6 posts)

  1. andrewso
    Member
    Posted 6 years ago #

    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.

  2. andrewso
    Member
    Posted 6 years ago #

    Any ideas on how I can get the main page to ignore that <div>? Thanks!

  3. moshu
    Member
    Posted 6 years ago #

    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.

  4. andrewso
    Member
    Posted 6 years ago #

    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.

  5. peiqinglong
    Member
    Posted 6 years ago #

    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.

  6. andrewso
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags