WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Recent Posts Exclude Category (4 posts)

  1. pecado
    Member
    Posted 1 year ago #

    Hello,

    I'm making own theme to my website. I'm in trouble with codes.

    I want to recent 4 or 5 posts in all posts exclude one category.

    My code is;

    <?php
    $id = get_cat_id('portfolyo');
    $q = "cat=-".$id;
    query_posts($query_string . $q); ?>

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

    <?php endwhile; ?>

    I put some code below, above my code, nothing is happen;

    <?php
    $args = array( 'numberposts' => '2' );
    $recent_posts = wp_get_recent_posts( $args );
    ?>

    Thanks in advance.

  2. pecado
    Member
    Posted 1 year ago #

    I'd tried $recent_posts codes couldn't merge with my codes.

    Any help please?

  3. pecado
    Member
    Posted 1 year ago #

    I'd tried to page them except recent 4-5 posts showing.

    I couldn't have the right view.

    Is there any help, please?

  4. pecado
    Member
    Posted 1 year ago #

    At last, I solved the question. This is the answer.

    <?php

    $recentPosts = new WP_Query();

    $id = get_cat_id('portfolyo');
    $q = "cat=-".$id;

    $recentPosts->query('showposts=5&cat=' .$q);

    while ($recentPosts->have_posts()) : $recentPosts->the_post();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic