我正在使用下面的代码来显示帖子,但我需要用li或div包装每个帖子。目前全部都是ul。我怎么能这样做?
THX!
<?php global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<h3 class="naslovostalih">Ostali članci iz ove kategorije:</h3>
<ul class="clanciostalih">
<?php
$posts = get_posts('numberposts=15&category='. $category->term_id);
foreach($posts as $post) :
$title = get_the_title($ID);
$link = get_permalink();
printf('<a class="linkpost" title="%s" href="%s">%s</a>', $title, $link, $title);
the_post_thumbnail('thumb-232');
the_excerpt();
?>
<p class="more-link-wrapper2"><a href="<?php the_permalink(); ?>" class="read-more button"><?php _e( 'Opširnije »', 'fearless' ); ?></a></p>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
我试过这个: Ostaličlanciizove kategorije:
<?php
$posts = get_posts('numberposts=15&category='. $category->term_id);
foreach($posts as $post) :
echo ('<div class="onepost">');
$title = get_the_title($ID);
$link = get_permalink();
printf('<a class="linkpost" title="%s" href="%s">%s</a>', $title, $link, $title);
the_post_thumbnail('thumb-232');
the_excerpt();
?>
<p class="more-link-wrapper2"><a href="<?php the_permalink(); ?>" class="read-more button"><?php _e( 'Opširnije »', 'fearless' ); ?></a></p>
echo ('</div>');
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
答案 0 :(得分:1)
`
<?php global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<h3 class="naslovostalih">Ostali clanci iz ove kategorije:</h3>
<ul class="clanciostalih">
<?php
$posts = get_posts('numberposts=15&category='. $category->term_id);
foreach($posts as $post) :
?>
<li>
<?php
$title = get_the_title($ID);
$link = get_permalink();
printf('<a class="linkpost" title="%s" href="%s">%s</a>', $title, $link, $title);
the_post_thumbnail('thumb-232');
the_excerpt();
?>
<p class="more-link-wrapper2"><a href="<?php the_permalink(); ?>" class="read-more button"><?php _e( 'Opširnije »', 'fearless' ); ?></a></p>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
`
我认为您的代码有标记打开和关闭问题。试试这个代码。 :)