我正在努力尋找一種在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