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.

I'm trying to create an advertisement block to be placed on a single post (single.php) such that the div class or id is left aligned and the post content wrapped around it. I checked the single.php and this is the only piece of code I notice is what displays the post.

<div class="entry entry-content">
                <?php the_content(); ?>
                <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'themejunkie' ), 'after' => '</div>' ) ); ?>

I tried adding the code both above the 'entry-content' div and also after the_content, but with both methods it either displays the div either at the beginning or at the end of the post content.

Can someone tell me which files to look into in order to add this?

share|improve this question
    
Figured it out. It was a problem with the share post plugin. Had to disable the automatically add to post and use the manual insert option. –  Sledge81 May 21 '11 at 20:57
add comment

2 Answers

up vote 1 down vote accepted

You have to put your advertisement block just before <?php the_content(); ?> in a separate div-layer and add some css to it. E.g.

single.php

<div class="entry entry-content">
    <div class="advertisement">
        <p>Your advertisement</p>
    </div>

    <?php the_content(); ?>
</div>

CSS

div.advertisement {
    float: left;
    width: 150px;
    padding: 0px 10px 10px 0px;
}
share|improve this answer
    
Thanks roman. now I have a new problem. The div block shows left aligned at the beginning of the <p> tags in the post. Is there a way to push this block to say 200px below and have the wordpress post to wrap around this ad? If I use margin-top: 200px, it leaves a whitespace. –  Sledge81 May 21 '11 at 21:11
    
Well this time, css isn't enough. If you want to put an advertisement inside your actual content, you have to a) include the ad inside your post during edit with a shortcode or b) add a filter for the_content() which will explode the content in parts, add your ad and output the new content. –  rofflox May 21 '11 at 21:20
    
@Sledge81 A new problem doesn’t belong into a comment. Please use Ask Question for this. Otherwise nobody else will find the solution. Pure CSS questions belong to StackOverflow tough … –  toscho May 21 '11 at 22:01
    
ünsche Prepend the div.advertisement with another div.spacing and add .spacing{float:left;width:1px;height:200px}. div.advertisement needs clear:left then. I hesitate to change your answer so much. –  toscho May 21 '11 at 22:05
    
Thanks toscho.. Your code worked. Will bear that in mind next time onwards. –  Sledge81 May 22 '11 at 7:00
add comment

Why not just hook into the the_content filter hook, and append your code to the_content()? e.g.:

function mytheme_content_ad( $content ) {
    $myadcode = '<div class="someclas">';
    $myadcode .= 'some string with the ad code';
    $myadcode .= '</div>';

    $filteredcontent = $myadcode . $content;

    return $filteredcontent;
}
add_filter( 'the_content', 'mytheme_content_ad' );

You may need to make the function a bit fancier than this, but this should convey the general idea.

share|improve this answer
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.