Wordpress +按类别发布

时间:2013-01-08 06:26:08

标签: php wordpress

我是wordpress的新手,所以这可能是一个非常明显的问题。

我如何才能获得特定类别的帖子。

5 个答案:

答案 0 :(得分:3)

您还可以尝试使用其他方法

<?php
    $post = query_posts( array ( 'category_name' => 'uncategorized') );
    $post = query_posts( array ( 'category_slug' => 'uncategorized') );
    $post = query_posts( array ( 'category' => 1) );
?>

答案 1 :(得分:0)

试试这个:

 <?php
   $posts = get_posts(array('category' => 1));
 ?>

答案 2 :(得分:0)

我鼓励你使用WP_Query:

<?php
    // The Query
    $the_query = new WP_Query( 
        'category_name' => 'slug-of-category',
    );

    // The Loop
    while ( $the_query->have_posts() ) :
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    endwhile;

    // Restore original Query & Post Data
    wp_reset_query();
    wp_reset_postdata();
?>

答案 3 :(得分:0)

<?php
    //here 1 is category id
    $args = array( 'cat' => 1);
    query_posts( $args );
    while ( have_posts() ) : the_post();
        the_title();
        the_content();
    endwhile;
    wp_reset_query();
?>

答案 4 :(得分:0)

    <?php 
          $args = array( 
           'posts_per_page' => -1, 
           'offset'=> 1, 
           'category' => 5, 
           'orderby' => 'ID',
           'order' => 'ASC'
          );
          $posts = get_posts($args);
          foreach ( $posts as $post ) : setup_postdata( $post ); ?>
               the_title(); 
               the_excerpt(); 
               the_permalink(); 
               the_content(); 
          endforeach; 
          wp_reset_postdata();
    ?>
相关问题