When calling an excerpt in Wordpress, is there a way to stop the excerpt carrying over it's own 'p' styling? Ending up with 2 conflicting styles.
This is my PHP code;
<h2 class="blog"><?php
global $post;
$args = array( 'numberposts' => 1, 'offset' => 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?></h2>
<p class="blog"><?php
global $post;
$args = array( 'numberposts' => 1, 'offset' => 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php the_excerpt(); ?>
<?php endforeach; ?></p>
</div>
This is how it appears in source code;
<div id="blog">
<h2 class="blog"><a href="http://kelvinwinscom.fatcow.com/kelvinwins/test-2/">Test 2</a>
</h2>
<p class="blog"><p>This is what an excerpt is. Interesting, isn’t it? <a href="http://kelvinwinscom.fa开发者_JS百科tcow.com/kelvinwins/test-2/">Continue reading <span class="meta-nav">→</span></a></p>
</p>
</div>
See, there is now two 'p' styles - the 'blog' class which I've created but also the other one that the excerpt is carrying over.
Any help would be brilliant. Thanks!
I would just remove the <p class="blog">
from your php
<p class="blog">// REMOVE THE PROCEEDING <?php
global $post;
$args = array( 'numberposts' => 1, 'offset' => 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php the_excerpt(); ?>
<?php endforeach; ?></p> //REMOVE THE </p>
and then style that <p>
in your stylesheet as an adjacent sibling:
h2.blog + p {//whatever your styles are}
try this in your theme function
remove_filter( 'the_excerpt', 'wpautop' );
精彩评论