gpt4 book ai didi

php - 从 wordpress 帖子中排除类别

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:00 24 4
gpt4 key购买 nike

我想从显示我的博文中排除类别。我的类别 ID 是 62。类别名称是perfect_work

这是我的 wordpress 博客模板代码:

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

我已经尝试过使用

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

它不起作用。我也放了

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

它的工作,但页面导航不工作,也不显示其他帖子。仅 1 日 5 后展示。

有什么解决办法吗?

最佳答案

获取页码

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

那么你可以使用

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

或者使用

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

然后循环

if($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post();
// ...
endwhile;
endif;

关于php - 从 wordpress 帖子中排除类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19482011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com