Answer the question
In order to leave comments, you need to log in
Correct cycle in wordpress?
Please let me know if this code is correct. This is single.php: here is the usual post output + a block for the output of the latest posts has been added at the bottom. Question: how well is everything built here?
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : $count = 0; ?>
<?php while (have_posts()) : the_post(); $count++; ?>
<div <?php post_class(); ?>>
<h1><?php the_title(); ?></h1>
<div class="entry">
<?php the_content(); ?>
</div>
</div><!-- .post -->
<div id="post-entries">
<div class="nav-prev fl"><?php previous_post_link( '%link', '<span class="meta-nav">←</span> %title' ) ?></div>
<div class="nav-next fr"><?php next_post_link( '%link', '%title <span class="meta-nav">→</span>' ) ?></div>
</div><!-- #post-entries -->
<?php comments_template('', true); ?>
<?php endwhile; else: ?>
<div>
<p><?php _e('Sorry, no posts matched your criteria.') ?></p>
</div>
<?php endif; ?>
<?php get_sidebar(); ?>
</div><!-- #content -->
<h2>Здесь выводятся последние записи</h2>
<ul>
<?php $random_posts = get_posts('numberposts=6&orderby=date'); ?>
<?php foreach ( (array) $random_posts as $post ) : ?>
<li>
<a href="<?php echo get_permalink($postid); ?>">
<?php the_post_thumbnail(array(300, 300, true)); ?>
</a>
<h2><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></h2>
</li>
<?php endforeach; ?>
</ul>
<?php get_footer(); ?>
Answer the question
In order to leave comments, you need to log in
In the first cycle, I did not quite understand why there was a counter in the cycle. In the second cycle, everything is somehow strange, but it will work.
For some reason, you use <?php echo get_permalink($postid); ?>
, although you can get by with standard functions. Why crutches?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question