2012-05-25 31 views
0
<ul> 
<?php 
global $post; 
$args = array('numberposts' => 12, 'orderby' => 'date', 'year' => '2012', 'order' => 'ASC', 'document_language' => 'english'); 
$myposts = get_documents($args); 
foreach($myposts as $post) : setup_postdata($post); ?> 
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
<?php endforeach; 
?> 
</ul> 

如何讓我把如果有帖子查詢?這基本上是自定義帖子類型查詢,但它使用文檔修訂插件(所以get_posts是get_documents)?修復wordpress查詢(如果有,請加)

非常感謝!

回答

0

如果你只是想檢查查詢是否返回任何帖子。你仍然可以用你的代碼來做到這一點。

這裏是例如:

<?php 

    global $post; 

    // This is your query 
    $args = array('numberposts' => 12, 'orderby' => 'date', 'year' => '2012', 'order' => 'ASC', 'document_language' => 'english'); 
    $myposts = get_documents($args); 

    if (count($myposts) > 0) : // If the query returned results 

    ?> 

    <ul> 

     <?php foreach($myposts as $post) : setup_postdata($post); // for each post in array ?> 
      <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
     <?php endforeach; ?> 

    </ul> 

    <?php endif; ?>