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条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法