我知道我可以通过CSS或javaScript来做到这一点,但我想知道Wordpress是否有一种原生的方式来做到这一点。
我有这样的代码:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>但是假设,我只想显示包含在所有这些帖子中的特定id或类。例如:#heading或.heading
我该怎么做呢?
发布于 2017-01-14 21:27:49
首先,使用PHP只获取包含id=“标题”的帖子:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
$post_content = get_the_content();
$find_this = 'id="heading"';
$find_this_single_quote = "id='heading'";
if (strpos($post_content, $find_this) !== false || strpos($post_content, $find_this_single_quote ) !== false) {
the_content();
}然后,用jQuery过滤结果,只得到#heading的内容:
var content = $('#heading').html();
if (content != '') {
$('#real-content').html(content);
}https://stackoverflow.com/questions/41650142
复制相似问题