在 Wordpress 中调用摘录时,有没有办法阻止摘录继承它自己的“p”样式?以 2 种相互冲突的样式结束。
这是我的 PHP 代码;
<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>
这是它在源代码中的样子;
<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.fatcow.com/kelvinwins/test-2/">Continue reading <span class="meta-nav">→</span></a></p>
</p>
</div>
看,现在有两种“p”样式 - 我创建的“博客”类以及摘录中继承的另一种。
任何帮助都会很棒。谢谢!
最佳答案
我只想删除 <p class="blog">
从你的 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>
然后设置 <p>
的样式在你的样式表中作为 adjacent sibling :
h2.blog + p {//whatever your styles are}
关于php - 冲突的 'p' 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6883571/