2012-03-06 104 views
0

我想從特定類別拉最新帖子。從特定類別拉最新帖子

我目前能夠拉所有最新的帖子,並按照我想要的方式使用下面的代碼顯示它們,但我無法從特定類別做同樣的事情。

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<div id="content"><div id="circle"><div id="circle_text1"><p><?php the_time('M') ?></p></div> 
<div id="circle_text2"><p><?php the_time('dS') ?></p></div></div> 
<div id="text"><div id="title"><p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p></div> 
<div id="name"><p>By <?php the_author(); ?></p></div> 
<div id="blurb"><p><?php the_content('<br />Read More'); ?></p></div></div> 
<div id="line_rule"><p>&nbsp;</p><hr /></div></div> 
<?php endwhile; ?><?php else : ?><h2>Not Found</h2><?php endif; ?> 

在此先感謝

回答

2

如果你正在從數據庫中的職位然後通過ID遞減,將顯示在頂部的最新帖子使用順序。如果ID是自動遞增的。像

select * from posts order by ID desc 
1

這是一個基本的WP查詢,可重置自身並可在模板中多次使用。你可以添加你的html。 showposts是顯示的帖子數量; -1顯示所有帖子。

<?php $my_query = new WP_Query('category_name=mycategoryname&showposts=10'); ?> 

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?> 

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> 

<?php the_title(); ?></a> 

<?php endwhile; ?> 
0

我一直這樣做。這將起作用: 將cat = number更改爲您要使用的任何類別ID。 隨意添加html標記以及任何您想要的其他內容。

<?php query_posts('cat=4&order=ASC'); 
if (have_posts()) : while (have_posts()) : the_post(); ?> 
<?php the_content(); ?> 
<?php endwhile; ?> 
<?php endif; ?> 
<?php wp_reset_query(); ?> 

在這個例子中,我只抓住了帖子內容,但你可以把在標題,元數據等重要部分都在這裏。 試一試。

0

將這行代碼添加到您打開的IF語句上方。

<?php query_posts('cat=1'); ?> 

然後更改1以匹配您嘗試顯示的類別的ID。

:)

0

你可以通過簡單地通過增加這個第一行代碼:

<?php query_posts('category_name=slug_of_your_category&posts_per_page=10'); ?> 

替換「slug_of_your_category」與類的蛞蝓,以及「10」的金額您需要的帖子。

相關問題