[英]get_post() with a specific class only - Wordpress
我正在将Wordpress用作我正在构建的网站的CMS。
页面模板:
<?php get_header(); ?>
<!-- Class here -->
<div id="wrap">
<div id="content" class="column">
<?php if( have_posts() ): while( have_posts() ): the_post(); ?>
<div class="post">
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>
</div>
<div id="sidebar" class="column">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</div>
<div>
<?php get_footer(); ?>
我需要在#wrap (Class here)
为#wrap (Class here)
之前调用具有“ theslide
”类的div,而不要由随后的php再次调用。
可以按照“ get_post if class=theslide
”的方式进行操作吗?
谢谢。
您可以使用此插件将自定义字段添加到您的帖子中http://wordpress.org/extend/plugins/advanced-custom-fields/
然后在循环中,您可以添加一个条件,例如
<?php
if(get_field('your_field_name' )){
//add class
}
?>
感谢您的所有投入,我的一个朋友帮助了我。
如果其他人有同样的问题:
<?php if( have_posts() ): while( have_posts() ): the_post();
$post_content = get_the_content();
preg_match('/(<div.*?class="theslide".*?<\/div>)(.*)/ism', $post_content, $content);
if( isset($content[1]) )
{
echo $content[1]; //print the "theslide" div
$page_content = $content[2];
}
else
{
$page_content = $post_content;
}
?>
<div id="wrap">
<div id="content" class="column">
<div class="post">
<?php echo $page_content; ?>
</div>
</div>
<div id="sidebar" class="column">
<?php get_sidebar(); ?>
</div>
</div>
<?php endwhile; endif; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.