0

我怎样才能显示<?php bloginfo('name'); ?>和(<?php the_author_posts(); ?>只有帖子号> 0?

因为如果我通过某个类别获得作者的最后 2 个帖子并且没有与某个作者关联的帖子,问题是当没有帖子时 php 代码还显示帖子计数 == 0 的类别标题类别/博客 ID。如何隐藏类别结果==0?

我用过这段代码:

    <?php
$original_blog_id = get_current_blog_id(); // prendi blog corrente

$bids = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); // inserisce l'ID nell'Array
foreach($bids as $bid):
       switch_to_blog($bid); //switch




       ?>  


             <h2 class="elenco"> Ultimi articoli per: <?php bloginfo('name'); ?> ( <?php the_author_posts(); ?>  )  </h2>

       <?php
       $posts = get_posts('author='.$curauth->ID.'&posts_per_page=2');
       foreach($posts as $post): setup_postdata($post);?>
4

3 回答 3

1

我认为这会起作用:

<?php
$original_blog_id = get_current_blog_id(); // prendi blog corrente
$bids = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); // inserisce l'ID nell'Array
foreach($bids as $bid):
   switch_to_blog($bid); //switch
   if($posts = get_posts('author='.$curauth->ID.'&posts_per_page=2')) {
      foreach($posts as $post): setup_postdata($post);)
      echo '<h2 class="elenco"> Ultimi articoli per: '.bloginfo('name').'('.the_author_posts().') </h2>';
   }
于 2013-10-12T17:19:47.900 回答
0

像这样的东西应该工作。替换blogcount()为您必须获取某个类别中的帖子数量的任何功能。

foreach($bids as $bid):
       switch_to_blog($bid); //switch

       if (postcount() == 0) {
          continue; // Skip to the next blog
       }


       ?>  


             <h2 class="elenco"> Ultimi articoli per: <?php bloginfo('name'); ?> ( <?php the_author_posts(); ?>  )  </h2>

       <?php
       $posts = get_posts('author='.$curauth->ID.'&posts_per_page=2');
       foreach($posts as $post): setup_postdata($post);?>
于 2013-10-12T19:20:56.380 回答
0
<?php 
  $posts_count = the_author_posts(); 
  echo $posts_count > 0 : bloginfo('name').' ( '.$posts_count.' )' : ''; 
?>

或者

<?php 
  $posts_count = the_author_posts(); 
  if($posts_count > 0) echo bloginfo('name').' ( '.$posts_count.' )'; 
?>
于 2013-10-12T17:14:32.867 回答