3

这是一个带有主题的小部件,它不排除侧边栏中的列表项。这会从同一区域提取 3 个房地产列表。它无法排除当前项目。

一定有问题,post__not_in()但我没有看到问题。有谁知道这个功能?

function listingsInSameAreaWidget() { ?>

<aside id="other-listings-in-same-area" class="widget left">
<h4><?php _e('Other Listings in Same Area', 'theme_textdomain'); ?></h4>
<ul id="newlistings">
<?php
$author = get_the_author_meta('ID');
$city = get_the_term_list(ID, 'city');
$post_id = get_post($post->ID)->ID;
$args = array(
    'post_type' => 'listings',
    'city' => $city,
    'post__not_in' =>$post->ID,
    'posts_per_page' => 3
);

//query_posts($args);
query_posts( array(
    'post_type' => 'listings',
    'city' => $city,
    'post__not_in' =>$post->ID,
    'posts_per_page' => 3, )

);  
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 
    <li>
        <?php ct_status_sm(); ?>
        <?php ct_first_image_tn_left(); ?>
        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
        <p class="location"><?php city_and_state(); ?></p>
        <p class="propinfo"><?php beds(); ?> <?php _e('Bed', 'theme_textdomain'); ?>, <?php baths(); ?> <?php _e('Bath', 'theme_textdomain'); ?></p>
        <div class="clear"></div>
    </li> 
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</ul>
</aside>

<?php
}

register_sidebar_widget('Other Listings in Same Area', 'listingsInSameAreaWidget');
4

2 回答 2

20

好的,我找到了解决方案。id 没有传递给小部件:

'post__not_in' => array (get_the_ID()),
于 2013-07-12T17:52:43.983 回答
11

它应该是一个array

'post__not_in' => array($post->ID)
于 2013-07-10T17:55:03.447 回答