admin管理员组文章数量:1291102
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?
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 asked May 21, 2011 at 20:41 swordfish81swordfish81 5663 gold badges12 silver badges32 bronze badges 1- 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. – swordfish81 Commented May 21, 2011 at 20:57
3 Answers
Reset to default 2You 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;
}
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.
Using the example to add classes to p tag & h2 tag.
<?php
function replace_content($text_content)
{
if (is_page()) {
$text = array(
'<p>' => '<p class="text-danger">',
'<h2>' => '<h2 class="h2">',
);
}
$text_content = str_ireplace(array_keys($text), $text, $text_content);
return $text_content;
}
add_filter('the_content', 'replace_content');
?>
本文标签: postsAdding a div class or id inside thecontent()
版权声明:本文标题:posts - Adding a div class or id inside the_content() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741513687a2382757.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论