Wordpress外部循环按类别和时间排序 [英] Wordpress outside loop sort by category and time
本文介绍了Wordpress外部循环按类别和时间排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要博客以外的某些WordPress的帮助(我不是博客..)
Need help with some Wordpress outside the blog(Im not a blogger..)
所以我需要从我的WordPress博客发布信息。我设法找到帖子,但需要按类别和时间进行排序。这里是我的代码的一部分:
So I need to get post from my Wordpress blog. I have manage to get the post, but need to sort by category and by time. here is part of my code:
<div class="8u skel-cell-mainContent" id="newsfeed">
<!-- Main Content -->
<?php if ($_GET['id']) {
$id = $_GET['id'];
$post = get_post($id);
echo "<section>";
echo "<a href='javascript:history.back();'>←Tilbake</a>";
echo "<header style='font-size: 30px;'>";
echo "<h2>".$post->post_title."</h2>";
echo "</header>";
echo "<p>".$post->post_content;
echo "</section>";
} else {
while (have_posts()):
the_post();
echo "<section>";
echo "<header style='font-size: 30px;'> ";
echo the_title('<h2>', '</h2>');
echo "</header>";
the_excerpt('<h3>', '</h3>');
$id = get_the_ID();
echo "<p><a href='nyheter.php?id=".$id."#newsfeed'>Les mer...</a></p>";
echo "</section>";
endwhile;
} ?>
</div>
<div class="4u">
<!-- Right Sidebar -->
<section>
<header>
<h2> <?php the_widget( WP_Widget_Archives, 'title=Arkiv' ); ?> </h2>
</header>
</section>
<section>
<header>
<h2> <?php the_widget( 'WP_Widget_Categories', 'dropdown=1&count=1', 'title=Kategori' ); ?> </h2>
</header>
</section>
</div>
推荐答案
我会开始一个新的循环,使用循环函数(the_content(),the_title()等)获得发布数据。
I would start a new loop, as it's much easier to get post data using the functions made for the Loop ( the_content(), the_title(), etc.)
试试这个作为一个起点:
Try this as a staring point:
<?php
$new_loop = new WP_Query( array(
'post_type' => 'post',
'orderby' => 'category'
) );
?>
<?php if ( $new_loop->have_posts() ) : while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?>
<section>
<a href='javascript:history.back();'>←Tilbake</a>
<header style='font-size: 30px;'>
<h2><?php the_title();?></h2>
</header>
<p><?php the_content();?></p>
</section>
<?php endwhile; else: ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
这篇关于Wordpress外部循环按类别和时间排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文