dtpw54085 2013-10-20 19:45
浏览 55
已采纳

从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?

  • 写回答

4条回答 默认 最新

  • duanjia8215 2013-10-20 20:27
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题