2012-08-26 126 views
-3

大家好,尋找一個WordPress的幫助。我需要把一個簡單的查詢/陣列顯示從一定貓例如,「新聞,其中將包括崗位特色圖片帖。Wordpress數組顯示來自某個類別的帖子,並顯示帖子摘錄和功能

任何人都可以請幫助?

加里

+0

只是一個簡單的...

+0

但我想包括帖子功能img作爲拇指不知道如何短語PHP .. –

+0

請不要將無關的新問題添加到現有的問題。謝謝。 – Kev

回答

1

試試這個

<?php 
    $query = new WP_Query('category_name=News&posts_per_page=4'); 
    if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); 
    if (has_post_thumbnail()) { 
     ?> 
      <a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> 
     <?php 
    } 
    ?> 
    <h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> 
    <?php 
    the_excerpt(); // or the_content(); for full post content 
    endwhile;endif; 
?> 
+0

它的作品非常漂亮。但我將如何保留它,以便每個帖子都將滑動添加到頁面,因爲在當前沒有滑動操作只是簡單的帖子列表。 –

+0

不知道你是什麼意思的滑塊。 –

+0

對不起。請參閱http://garyrevell.co.uk/student-i/如果你看看它說「最新消息」的地方,我已經輸入了一個簡單的html內容滑塊。我希望一旦該網站進入WP,可以滾動瀏覽5個最新新聞帖子。這有意義嗎? –

1

不要使用query_posts(),它的目的是修改默認的WordPress的循環,不應該被用於一般的查詢。使用WP QueryGet Posts代替。

以下是Post Thumbnails的一些文檔

下面是一個基於您向我展示的可能工作的小示例。請注意,「showposts」已改爲「posts_per_page」,爲「showposts」被棄用的2.1版本:

<?php 
$q = new WP_Query(array('cat'=>8, 'posts_per_page'=>4)); 
if($q->have_posts()) : while($q->have_posts()) : $q->the_post(); 
    the_excerpt(); 
    if(has_post_thumbnail()) 
     the_post_thumbnail('thumbnail'); 
endwhile;endif; 
?> 

UPDATE:

基於你給我的例子,這應該讓你開始:

<div id="slider2"> 
<div class="viewport"> 
    <?php 
    $q = new WP_Query(array('cat'=>8, 'posts_per_page'=>4)); 
    if($q->have_posts()) : while($q->have_posts()) : $q->the_post(); 
    ?> 
    <div class="newsPost"> 
     <div class="news-date"><?php the_date(); ?></div> 
     <div class="newstitle"><?php the_title(); ?></div> 
     <div class="news-des"><?php the_excerpt(); ?></div> 
     <?php if(has_post_thumbnail()){ ?> 
     <div class="newsimg"><?php the_post_thumbnail(); ?></div> 
     <?php } ?> 
     <p><a href="<?php the_permalink(); ?>">Read More...</a></p> 
    </div> 
    <?php endwhile;endif; ?> 
</div> 
</div>​ 
+0

謝謝這麼多... 在我的網站所有新聞帖子將顯示在主頁上的迷你滑塊中。 可以將上面的代碼分開嗎?例如 「

8, 'posts_per_page'=>4)); if($q->have_posts()) : while($q->have_posts()) : $q->the_post(); the_excerpt(); (someting to close)
」 - 爲後摘錄,然後財產以後這樣的拇指/功能IMG
if(has_post_thumbnail()) the_post_thumbnail('thumbnail'); endwhile;endif; ?>

+0

當然,這樣的事情可以做。但我會親自爲循環中的每個相應帖子保留開始和結束標籤。您也可以在循環之前打開一個「包裝器」div,並在之後立即關閉,以包含您的所有帖子div。 – maiorano84

+0

好吧。這是我的HTML到我的滑塊與虛擬內容。 –

相關問題