2017-09-21 116 views
0

對於這樣的新手問題,我剛剛開始學習php。我試圖創建一個從自定義帖子類型中提取數據的表格,並重復使用來自相同帖子類型的其他帖子。我用一些PHP創建了第一部分,但我希望重複這個自定義帖子類型。Wordpress顯示帖子標題,表格中的自定義字段

<table> 
    <tr> 
    <td><?php the_title(); ?></td> 
    <td><?php echo get_the_term_list($post->ID, 'degrees', 'Degrees Offered: ', ', '); ?></td> 
    <td><?php echo get_the_term_list($post->ID, 'program_location', 'Program Location(s): ', ', '); ?></td> 
    <td><?php echo get_the_term_list($post->ID, 'institution_type', 'Institution Type: ', ', '); ?></td> 
    </tr> 
    <tr> 
    <td>Post 2 Title</td> 
    <td>Post 2 Degrees Offered</td> 
    <td>Post 2 Program Locations</td> 
    <td>Post 2 Institution Type</td> 
    </tr> 
    <tr> 
    <td>Post 3 Title</td> 
    <td>Post 3 Degrees Offered</td> 
    <td>Post 3 Program Locations</td> 
    <td>Post 3 Institution Type</td> 
    </tr> 
</table> 

回答

0

您可以查看wordpress CODEX中的wp_query,它可以讓您具體獲取post_types並遍歷它們。

Ref。 https://codex.wordpress.org/Class_Reference/WP_Query

示例代碼:

<?php 

// The Query 
$the_query = new WP_Query($args); 

// The Loop 
if ($the_query->have_posts()) { 
    while ($the_query->have_posts()) { 
     $the_query->the_post(); 
     echo get_the_title(); 
     // --------------------- 
     // YOUR TABLE LOGIC HERE 
     // --------------------- 
    } 
    echo '</ul>'; 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
} else { 
    // no posts found 
} 
+0

謝謝迭戈!我認爲我最大的困惑是如何重複一個html表格,並將wordpress內容拉出來。 –

相關問題