• Resolved staud

    (@staud)


    Hi,

    I have an extra static page named “news” with the blog-template.php of my theme (Pinboard from onedesigns).

    Can somebody tell how to edit the following code in the blog-template.php to only show one specific category (ID 5 in my case)?

    I know that simiplar problems have appeared 100+ times but in every search result I found the code was different from the code in the template I use!

    <?php global $wp_query, $wp_the_query; ?>
    <?php $wp_query = new WP_Query( $args ); ?>
    <?php if( $wp_query->have_posts() ) : ?>
    <div class="entries">
    <?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>
    </div>

    I’ve tested several “hide”-plugins and stuff for hours and I’m really despair about this problem.

    Can you help me, please?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Where are $args defined n your template? Have you reviewed a page of posts?

    Thread Starter staud

    (@staud)

    Do you mean this? It comes directly before the code quoted in the opening post.
    <?php $args = array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => max( 1, get_query_var( 'paged' ) ) ); ?>

    No, I haven’t read “a page of posts”. Unfortunately I don’t understand PHP the least, so every code that is different from what I see is immediately confusing for me.

    Try:

    <?php $args = array(
    	'posts_per_page' => get_option( 'posts_per_page' ),
    	'cat' => 5,
    	'paged' => max( 1, get_query_var( 'paged' ) )
    ); ?>

    Thread Starter staud

    (@staud)

    That worked! Thank you very much!!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Show only one category in specific wp-query code’ is closed to new replies.