简体   繁体   中英

Show posts by only one category in page template in WordPress

I managed to find several threads for this but wouldn't work. I use a theme that has custom posts 'Our Team'. I have managed to add categories for them by adding the following code:

/*TAXONOMIES*/
    add_action( 'init', 'ourteam_taxonomies', 0 );
    function ourteam_taxonomies() {
        register_taxonomy( 'ourteam_categories', 'ourteam', array( 'hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true ) );
    }

I am trying now to modify the page template in order to only display posts of one category. I have tried the following but I cannot get it to work:

<?php 
 if ( have_posts() ) :
  while (have_posts()) : the_post(); 
  the_content();                                
   endwhile; 
   endif;
   ?>

<?php
  $member_order = get_option('source_member_order');
   $member_orderby = get_option('source_member_orderby');

  $args = array( 'post_type' => 'ourteam', 'ourteam_category' => 92, 'orderby' => $member_orderby, 'order' => $member_order, 'posts_per_page' => get_option('source_num_member') );
   $wp_query = new WP_Query( $args );   

    if ( $wp_query->have_posts() ) :                        
    while ($wp_query->have_posts()) : $wp_query->the_post(); 
    ?>

I am not familiar with PHP so I am having trouble figuring out what the problem is.

Thank you in advance for any help!

Try

query_posts("cat=92&orderby=".$member_orderby."&order=".$member_order."&posts_per_page=". get_option("source_num_member") );

So

query_posts("cat=92&orderby=".$member_orderby."&order=".$member_order."&posts_per_page=". get_option("source_num_member"));


while ( have_posts() ) : the_post();
    // Your Output
endwhile;

// Reset Query
wp_reset_query();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM