<?php
$the_query = new WP_Query(array(
'post_type' => 'needs',
'orderby' => 'date',
'category_name' => 'volunteers', //name of category by slug
'order' => 'DESC',
'posts_per_page' => '5')); // how many posts to show
// Put into the loop
while ($the_query->have_posts()) :
$the_query->the_post();
echo '<tr><td>' . get_the_date() . '</td>';
echo '<td>' . get_the_title() . '</a></td></tr>';
endwhile;
// Restore original Post Data if needed
wp_reset_postdata(); ?>
我使用此代碼正確顯示志願者類別下的需求標題和日期。 我需要標題鏈接到帖子本身,但我無法獲得固定鏈接來處理此代碼。 有什麼建議嗎?使標題可點擊進入帖子本身。 (WordPress的)
這是正確的。另一種同樣適用的方法是: echo'' . get_the_title() . ''; 你和這個之間有什麼區別?他們都工作。 – 4ndy
很高興爲你效勞! 沒有區別,因爲get_the_ID()只是一個從$ post變量中獲取ID的函數。 $ post-> ID是獲得相同ID的更正確和直接的方式,您可能會更頻繁地看到它。 – jrobson153