2017-04-05 84 views

回答

1

你想獲得樁的陣列,僅限於您的自定義後的類型。我會使用get_posts()

$args = array(
    'posts_per_page' => -1, // -1 here will return all posts 
    'post_type'  => 'project', //your custom post type 
    'post_status'  => 'publish', 
); 
$projects = get_posts($args); 

foreach ($projects as $project) { 
    printf('<div><a href="%s">%s</a></div>', 
      get_permalink($project->ID), 
      $project->post_title); 
} 
+0

可以得到特定的項目通過提及Id,Like Where條件。? – Developer

1

我會用'WP_Query「做一個查詢並顯示結果:

<?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //pagination 
    $args = array(
     'paged'   => $paged, 
     'posts_per_page' => 12, //or any other number 
     'post_type'  => 'Projects' //your custom post type 
     ); 

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

    if ($the_query->have_posts()) { // The Loop 

     echo '<ul>'; 
     while ($the_query->have_posts()) { 
      $the_query->the_post(); 

      echo '<li>' . get_the_title() . '</li>'; //shows the title of the post (Project) 
     } 
     echo '</ul>'; 

     /* Restore original Post Data */ 
      wp_reset_postdata(); 

    } else { 
     // no posts found 
    } 

此代碼顯示在「項目」中的一個無序列表,但你可以使用任何其他HTML(DIV ,ol,article ...)

相關問題