2012-05-21 68 views
0

這裏是我的自定義代碼,這將列出來自特定父級的所有頁面,但現在,如何顯示每行只有4結果,最後一行將有類'最後'。WordPress的 - 循環一行只顯示4結果

<?php 

     //this is custom query for show page from specific parent page in different page   

     $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '11' AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); 
     if ($child_pages) : foreach ($child_pages as $pageChild) : setup_postdata($pageChild); ?>   

     <div class="child-thumb_home looping"> 

      <div class="property_thumb"><a href="<?php echo get_permalink($pageChild->ID); ?>"><?php echo get_the_post_thumbnail($pageChild->ID, array(222,123)); ?></a></div> 

      <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" class="property_name" title="<?php echo $pageChild->post_title; ?>"> 
      <?php echo $pageChild->post_title; ?> 
      </a> 

      <div class="some_desc"><?php the_advanced_excerpt('length=50&use_words=0&no_custom=1&ellipsis=%26hellip;&exclude_tags=img,p,strong'); ?></div> 

      <div class="read_more"><a href="<?php echo get_permalink($pageChild->ID); ?>">MORE INFO...</a></div> 

     </div> 

     <?php endforeach; endif; ?> 

謝謝。

回答

0

改變這一行:

$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '11' AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); 

要:

$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '11' AND post_type = 'page' ORDER BY menu_order LIMIT 4", 'OBJECT'); 

而且這些線路:

if ($child_pages) : foreach ($child_pages as $pageChild) : setup_postdata($pageChild); ?>   
    <div class="child-thumb_home looping"> 

要:

$num_child_pages = count($child_pages); 
if ($num_child_pages) : for ($i = 0; $i < $num_child_pages; $i++): 
    $pageChild = $child_pages[$i]; 
    setup_postdata($pageChild); ?> 

    <div class="child-thumb_home looping <?php if ($i == $num_child_pages - 1): ?>last<?php endif; ?>"> 
+0

我有不知道你在說什麼。嘗試改寫。 –

+0

抱歉有困惑,但現在是工作,再次感謝。 – ruslyrossi