1

在首页和博客页面上 - 侧边栏显示了最近的帖子,我发现与主页上展开的同一篇文章相比,它看起来不太好。

这是我的侧边栏代码:

<div class="blog-sidebar">
<?php query_posts('showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
    <div class="blog-sidebar-feature">
        <?php if ( has_post_thumbnail() ) { ?>
            <div class="blog-sidebar-image"><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_post_thumbnail('medium'); ?></a></div>
        <?php
        }
        ?>
        <div class="blog-sidebar-content">
            <p class="date"><?php the_time('F j, Y') ?></p>
            <h3 <strong><?php

    foreach((get_the_category()) as $category) { 
echo $category->cat_name . ' '; 
    } 
    ?></strong></h3>
    <h2 <p><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title();         
    ?></a></p></h2><?php echo get_excerpt(166); ?>
        </div>
    </div>
<?php endwhile;?>
<br />
<?php wp_pagenavi(); ?>
</div>

以及博客在主页上的显示方式的相关代码:

<div class="blog-sidebar">
    <div class="blog-sidebar-feature">
        <?php query_posts('orderby=date&order=DESC&showposts=2'); ?>
            <?php while (have_posts()) : the_post(); ?>
            <?php if ( has_post_thumbnail() ) { ?>
                <div class="blog-sidebar-image"><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_post_thumbnail('medium'); ?></a></div>
            <?php
            }
            ?>
            <div class="blog-sidebar-content">
                <p class="date"><?php the_time('F j, Y') ?></p>
            <h3 <strong><?php
    foreach((get_the_category()) as $category) { 
echo $category->cat_name . ' '; 
    } 
    ?></strong></h3>
                <h2 <p><a href="<?php the_permalink() ?>"    
    rel="bookmark" title=""><?php the_title(); ?></a></p></h2><?php echo get_excerpt(166); ?>
            </div>
        <?php endwhile;?>
    </div>

</div>
<div id="connect">
    <?php query_posts('page_id=1');
      while (have_posts()): the_post();
      the_content();
  endwhile;
  wp_reset_query(); ?>
</div>

有没有什么方法可以只从侧边栏中删除最新的帖子,当它完整显示在主容器上时?提前感谢您的帮助。

4

2 回答 2

1
<?php query_posts('posts_per_page=5&offset=1'); ?>

感谢 850010 的所有帮助,我回去查看了偏移规则,不需要“数组”。看似简单。

于 2013-05-15T14:59:27.153 回答
1

更新 V2

所以你确实想要最近的帖子,而不是当前显示在主要内容中的帖子。

更新 V3:

现在应该可以了。我不得不将参数更改query_posts为数组以使其工作。

现在就试试:

<?
global $wp_query;
$skip_posts=array();
if (is_single()) //only exclude posts when single post is shown
$skip_posts[]=$wp_query->post->ID;
?>
<?php query_posts( array( 'showposts'=>5,'post__not_in'=>$skip_posts)); ?>
于 2013-05-14T13:38:39.380 回答