2012-08-27 62 views
-3

可能重複:
Wordpress array to show post from certain category and show post excerpt and feature ingWordPress的查詢職位與職位縮略圖,摘錄

大家好編碼了WP主題的過程。我在主頁上有一個滑塊來顯示來自「新聞」類別的最新帖子,我已經制定了如何顯示來自貓的滑塊中的帖子,但我不知道如何包括帖子功能圖像和除。可有人請告知。

這是我在進步WP網站的工作。它的「最新新聞」滑塊。

http://www.garyrevell.co.uk/student-i-wp/

三江源

回答

0

您可以通過包括該添加的功能圖片你想要圖像出現在你的循環內的一段代碼:

<?php if (has_post_thumbnail()) : ?><?php the_post_thumbnail(); ?><?php endif; ?> 

您可以通過the_exerpt()更換the_content()功能添加exerpt。

可以說你有這樣的一段代碼,你的循環中:

<?php the_content(); ?> 

你將與此替換它:

<?php the_exerpt(); ?> 

還有很多事情需要這個,然後只需添加和取代,但我認爲這可以讓你開始。

希望這有助於=]。

你被要求將所有東西放在循環中。

這是一個完整的循環與標題,略圖,並在您的部分使用的內容...

<?php $my_query = new WP_Query('category_name=news&posts_per_page=1'); 
while ($my_query->have_posts()) : $my_query->the_post(); 
$do_not_duplicate = $post->ID; ?> 

<h2 id="yourTitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2> 
<div id="yourImage"> 
<?php if (has_post_thumbnail()) : ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> 
</div> 
<p id="yourContent"><?php the_exerpt(); ?></p> 

<?php endwhile;?> 

在這裏,我們告訴查詢,以顯示你的新聞類職位,只顯示1 post ('category_name=news&posts_per_page=1')

+0

我現在有這個,我知道它不起作用,但你能看到我想要做什麼? ' \t \t \t \t \t \t \t <如果PHP(has_post_thumbnail()):?> <?php endif; //查詢 query_posts(array('category_name'=>'news','posts_per_page'=> -1)); // The Loop while(have_posts()):the_post(); \t echo'

  • '; \t the_title(); \t echo'
  • '; end; //重置查詢 wp_reset_query(); ?>' –

    +0

    我會延長答案......希望它有幫助。 – MrHOG

    +0

    Thankyou .. PHP導致錯誤壽。阿爾曼 –