我正在使用一个显示/隐藏脚本来显示/隐藏文本,但是当我尝试放置一些 php(显示最近帖子的脚本 [WordPress])时它不起作用。实际上,文本仍然显示/隐藏,但 php 始终显示(在页面上的操作下方)。
我怀疑这可能与使用 <span>
有关s,这在一般情况下表现得很奇怪,至少在这个显示/隐藏中是这样。如果我尝试将其放入 <p>
中,例如,它破坏了功能。
这是代码。也许有人可以告诉我如何将 php 放入其中,或者我需要一个新的起点?目标只是在基本的灯光秀/隐藏中展示各种东西。
HTML:
<span class="span3">Hide</span>
<span class="span2">Show</span>
<p class="alert" >Some text inside the show/hide</p>
我想在显示/隐藏里面放什么:
<div class="featured-articles">
<?php
$args=array(
'tag' => 'feature-left',
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'Today';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} //if ($my_query)
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</div>
CSS:
body {
display: block;
}
.span3:focus ~ .alert {
display: none;
}
.span2:focus ~ .alert {
display: block;
}
.alert{display:none;}
(源码作者:Vector)
最佳答案
如果我理解你的问题,这就是你想要做的:
body {
display: block;
}
.span3:focus ~ .alert {
display: none;
}
.span2:focus ~ .alert {
display: block;
}
.alert {
display: none;
}
.span2,
.span3 {
outline: none;
}
<span tabindex="0" class="span3">Hide</span>
<span tabindex="0" class="span2">Show</span>
<p class="alert">Some text inside the show/hide</p>
要插入 php,您当然应该执行以下操作:
<p class="alert" ><?php echo 'Some text inside the show/hide'; ?></p>
当然,还要确保您回显的文本具有正确编码的 html 实体。
编辑:
经过你的补充说明,你的问题是布局结构,你不能把div
放在p
里面。 p
标签不能包含 block 元素。将 p
替换为 div
就可以了:
<div class="alert">Your featured articles html here</div>
关于php - 修改显示/隐藏以包含 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30613711/