php 和循环过程的新手。循环内有 html 标记可以吗?我也经常在其他主题中看到类似<?php get_template_part( 'content', get_post_format() ); ?>
或更复杂的版本。我应该将循环放在一个单独的 php 文件中并在我的帖子页面中调用它吗?
我只是想确保我的循环遵循“wordpress 规则”并且不会超出规范。这是我当前运行正常的循环代码:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<p>
Published on <?php the_time('M j, Y'); ?> <br>
</p>
<p><em>
by <?php the_author(', '); ?> in <?php the_category(', '); ?> | <?php comments_number(); ?><br>
</em></p>
<?php echo get_the_post_thumbnail($page->ID, 'home-thumb'); ?>
<br>
<p><?php the_content(); ?></p>
<hr>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div class="alignright"><?php next_posts_link('Next Entries »','') ?></div>
</div>
<?php else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>