0

カスタムページに2つのループがあります。2番目のループから、最初のループから投稿IDを持つ投稿を省略します(もちろん、カテゴリ36の他のすべての投稿を表示します)。

編集:これはphpファイルのコード全体です:

<?php
global $udesign_options;

// construct an array of portfolio categories
$portfolio_categories_array = explode( ',', $udesign_options['portfolio_categories'] );

if ( $portfolio_categories_array != "" && post_is_in_category_or_descendants( $portfolio_categories_array ) ) :
// Test if this Post is assigned to the Portfolio category or any descendant and switch the single's template accordingly
include 'single-Portfolio.php';
else : // Continue with normal Loop (Blog category)

get_header();

$content_position = ( $udesign_options['blog_sidebar'] == 'left' ) ? 'grid_16 push_8' : 'grid_16';
if ( $udesign_options['remove_single_sidebar'] == 'yes' ) $content_position = 'grid_24';
?>
<div id="content-container" class="container_24">
<div id="main-content" class="<?php echo $content_position; ?>">
    <div class="main-content-padding">
<?php if (have_posts()) :
        while (have_posts()) : the_post(); ?>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            <div class="entry" style="margin:-30px 0 00px 0;">
<?php                           // Post Image
                            if( $udesign_options['display_post_image_in_single_post'] == 'yes' ) display_post_image_fn( $post->ID, false );
            the_content(__('<p class="serif">Read the rest of this entry &raquo;</p>', 'udesign'));
            wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>


            </div>


<?php
$args = array( 'category' => 36, 'post_type' =>  'post' ); 
$postslist = get_posts( $args );    
foreach ($postslist as $post) :  setup_postdata($post); 
?>     
<h2><?php the_title(); ?></h2> 
<?php the_content(); ?> 
<?php echo do_shortcode('[divider_top]'); ?>
<?php endforeach; ?> 



<div><?php comments_template();
        endwhile; else: ?>
        <p><?php esc_html_e("Sorry, no posts matched your criteria.", 'udesign'); ?></p>
<?php endif; ?></div>
    </div><!-- end main-content-padding -->
</div><!-- end main-content -->

<?php
if( ( !$udesign_options['remove_single_sidebar'] == 'yes' ) && sidebar_exist('BlogSidebar') ) { get_sidebar('BlogSidebar'); }
?>

</div><!-- end content-container -->
<?php endif; // end normal Loop ?>

<div class="clear"></div>

<?php get_footer(); ?>

私はそれを理解しました、このコードは挿入される必要があります$ args = array('exclude' => theExcludedID、'category' => 36、'post_type' =>'post');

4

2 に答える 2

1

質問の更新によると、最初のループでportfolio_categoriesはカスタム クエリのすべてのカテゴリが表示され、おそらくカテゴリ 36 のカテゴリも含まれているようです。

2 番目のループで投稿を繰り返さないように考える唯一の方法は、最初のループからすべてのカテゴリ 36 の投稿を除外することです。

コードをテストすることはできませんが、これを行う方法のアイデアは次のとおりです。

次のように、ループの後に 3 行のコードを追加します。

if (have_posts()) : while (have_posts()) : the_post(); // This is the Loop
$Category =  get_the_category( $post->ID );
$CatID = $Category[0]->cat_ID ; // The 0 assumes the post has only one category. If there are more, the number must be changed accordingly.
if ($CatID == 36) continue;
于 2013-01-04T11:22:33.483 に答える
0

ループの先頭で次を使用します。

if(get_the_ID() == theExcludedID){
    continue;
}

繰り返しをスキップします。

于 2013-01-03T17:27:14.347 に答える