[英]Wordpress outside loop sort by category and time
在博客之外需要一些Wordpress的幫助(我不是博客作者。)
因此,我需要從我的Wordpress博客中獲取帖子。 我已設法獲得該職位,但需要按類別和時間進行排序。 這是我的代碼的一部分:
<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()等)獲取發布數據要容易得多。
試試看作為凝視點:
<?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(); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.