我正在努力寻找一种在PHP IF语句中包装HTML和PHP的方法。用PHP将PHP和PHP包装起来
<div class="preview">
<?php while (have_posts()) : the_post(); ?>
<?php if (get_post_gallery()) : ?>
<?php echo "Heres a preview of the private gallery, please login to view more."; ?>
<?php echo get_post_gallery(); ?>
<?php endif; ?>
<?php endwhile; ?>
</div>
内
<?php if (post_password_required()) {
the_content();
} else {
} ?>
所以代替the_content()的 “预览” 代码。
我试过这个,但它似乎没有工作。
<?php if (post_password_required()) {
echo '<div class="preview">'
while (have_posts()) : the_post();
if (get_post_gallery()) :
echo "Heres a preview of the private gallery, please login to view more.";
echo get_post_gallery();
endif;
endwhile;
echo '</div>'
} else {
} ?>
这几乎是PHP设计的目的。你有没有试过阅读手册? – GordonM 2014-12-06 13:02:18
好吧,你错过了一些分号,所以你的代码不会运行,谷歌PHP错误报告 – andrew 2014-12-06 13:08:13