如何按id隐藏博客WordPress多站点列表

时间:2017-01-05 作者:MSI

我想知道

如何在多站点博客列表中按id隐藏博客?这是我的代码示例,它列出了3篇最新的博客文章和3篇不同的博客

    <?php 
     $blogs = get_last_updated(\' \', 0, 3); 

     foreach ($blogs AS $blog) {;
     switch_to_blog($blog["blog_id"]);

     $lastposts = get_posts(\'numberposts=1&orderby=date\');
     foreach($lastposts as $post) : setup_postdata($post);
    ?>

<div class="col-sm-4 blog-newest">

    <!-- blog name -->
    <h3><?php echo $blog_title = get_bloginfo( \'name\' ); ?></h3>

    <!-- Link to blog -->
    <a href="<?php echo get_page_link($post->ID); ?>"> 
        <?php echo $post->post_title; ?>
    </a>

</div>

<?php               
    endforeach;
    restore_current_blog();
    }
 ?> 
感谢您的回答

1 个回复
SO网友:James Valeii

if语句怎么样?

<?php 
    $blogs = get_last_updated(\' \', 0, 3); 

    foreach ($blogs AS $blog) {;
    switch_to_blog($blog["blog_id"]);

    $lastposts = get_posts(\'numberposts=1&orderby=date\');
    foreach($lastposts as $post) : setup_postdata($post);
?>

<?php if $blog["blog_id"] != 1 { ?> // Run the Output if the ID is not X

    <div class="col-sm-4 blog-newest">

    <!-- blog name -->
    <h3><?php echo $blog_title = get_bloginfo( \'name\' ); ?></h3>

    <!-- Link to blog -->
    <a href="<?php echo get_page_link($post->ID); ?>"> 
        <?php echo $post->post_title; ?>
    </a>

    </div>

    <?php               
        endforeach;
        restore_current_blog();
    }
    ?> 

<?php } ?>