好吧,请耐心听我说,我是wordpress的新手。我正在使用下面的代码来获取帖子的标题,但它不起作用,我做错了什么?
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?
the_title();
} // end while
} // end if
?>发布于 2016-09-14 22:39:57
你混合了两种不同的php语法。
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
// inside the loop here
<?php the_title(); ?>
<?php endwhile; ?> // end while
<?php endif; ?> // endif您可以使用alternative syntax,而不是对控制结构使用大括号。这有助于在混合使用php和HTML的模板中提高代码的可读性
发布于 2016-09-14 22:45:36
看看你的循环,它看起来格式不正确。它可能看起来像这样
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_title();
} // end while
} // end if
?>有关the_loop https://codex.wordpress.org/The_Loop的更多信息,请查看文档
https://stackoverflow.com/questions/39493017
复制相似问题