Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude category from wordpress post

Tags:

php

wordpress

I want to exclude category from shoowing my blog posts. My category id is 62. category name is perfect_work

Here is my wordpress blog template code:

    <div id="left" class="eleven columns">

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('paged='.$paged);
    ?>

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

        <div class="post" id="post-<?php the_ID(); ?>">

            <div class="title">

                <h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>" ><?php the_title(); ?></a></h2>

                <div class="postmeta">  <span>by <?php the_author_posts_link(); ?></span> | <span><?php the_time('l, F jS, Y') ?></span> | <span><?php the_category(', '); ?></span> </div>

            </div>

            <div class="entry">

            <?php $image_attr = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'top_feature'); ?>    

                <a href="<?php the_permalink() ?>"><img src="<?php echo $image_attr[0]; ?>" class="postim scale-with-grid" id="blog-thumb" ></a>
                <?php wpe_excerpt('wpe_excerptlength_archive', ''); ?>
                <div class="clear"></div>
            </div>
        </div>

    <?php endwhile; ?>
    <?php getpagenavi(); ?>
    <?php $wp_query = null; $wp_query = $temp;?>
</div>

I already tried using

$wp_query = new WP_Query('cat=-62');

its not work. I also put

<?php query_posts('cat=-62'); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

Its work but page navigation not work, and also not showing others post. only 1st 5 post show.

Any Solution?

like image 900
NoDiv_NoClass Avatar asked Jan 26 '26 11:01

NoDiv_NoClass


1 Answers

Get the page number

$paged = get_query_var('paged') ? get_query_var('paged') : 1;

Then you may use

$wp_query = new WP_Query('cat=-62&paged=' . $paged);

Or use

$cat_id = get_cat_ID('perfect_work');
$wp_query = new WP_Query('cat=-' . $cat_id . '&paged=' . $paged);

Then loop

if($wp_query->have_posts()) :
    while ($wp_query->have_posts()) : $wp_query->the_post();
        // ...
    endwhile;
endif;
like image 102
The Alpha Avatar answered Jan 28 '26 23:01

The Alpha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!