条件标记帮助(如果没有,则不显示任何内容)

时间:2011-09-30 作者:japanworm

虽然我读了好几遍Wordpress Codex, 我很难做我想做的事。事实上,这是我博客的某些部分,所以我想一旦我知道如何做,我可以让它为所有人工作。

例如:如果没有标签,CSS编码仍然显示(背景、图像等),看起来很奇怪。最近的帖子和pingback也是如此。

我对他们的设置如下所示:

<?php if ( have_comments() ) : ?>


    <ul class="pingbacks"><h2>Pingbacks</h2>
<?php wp_list_comments(array(
  \'callback\'=>\'mytheme_comment\',
  \'type\'=>\'pings\',
)); ?>
    </ul>
 <?php else : // this is displayed if there are no comments so far ?>

    <?php if (\'open\' == $post->comment_status) : ?>
        <!-- If comments are open, but there are no comments. -->

     <?php else : // comments are closed ?>
        <!-- If comments are closed. -->
        <p class="nocomments">Comments are closed.</p>

    <?php endif; ?>
<?php endif; ?>
以及功能。注释的php代码:

function mytheme_comment($comment, $args, $depth) {
   $GLOBALS[\'comment\'] = $comment; ?>
   <li <?php comment_class(\'clearfix\'); ?> id="li-comment-<?php comment_ID() ?>">
     <?php echo get_avatar($comment,$size=\'63\'); ?>
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-meta commentmetadata clearfix">
        <?php printf(__(\'<strong>%s</strong>\'), get_comment_author_link()) ?><?php edit_comment_link(__(\'<img src="http://www.zoomingjapan.com/wp-content/themes/alltuts/images/edit.gif">\'),\'  \',\'\') ?> <span><?php printf(__(\'%1$s @ %2$s\'), get_comment_date(\'Y/n/j\'),  get_comment_time(\'G:i\')) ?>
      </span>
  <div class="text">
          <?php comment_text() ?>
      </div>
      </div>



      <?php if ($comment->comment_approved == \'0\') : ?>
         <em class="comment-awaiting-moderation"><?php _e(\'Your comment is awaiting moderation.\') ?></em>
         <br />
      <?php endif; ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array(\'depth\' => $depth, \'max_depth\' => $args[\'max_depth\']))) ?>
      </div>
     </div>
<?php }
页面链接仅在实际有多个页面时才显示,那么为什么这对标记不起作用呢?

相关岗位:

<h2>Related Posts</h2>                      


<!-- "previous page" action -->
<a class="prev browse left"></a>

<!-- root element for scrollable -->
<div class="scrollable" id=chained>   

   <!-- root element for the items -->
   <div class="items">


      <!-- 1-5 -->
      <div>

            <!-- Related Posts-->

                            <?php 
                            $backup = $post;
                            $tags = wp_get_post_tags($post->ID);
                            if ($tags) {
                                $tag_ids = array();
                                foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;

                                $args=array(
                                    \'tag__in\' => $tag_ids,
                                    \'post__not_in\' => array($post->ID),
                                    \'showposts\'=>4, // Number of related posts that will be shown.
                                    \'caller_get_posts\'=>1
                                );
                                $my_query = new wp_query($args);
                                if( $my_query->have_posts() ) {
                                    while ($my_query->have_posts()) {
                                        $my_query->the_post();
                                    ?>
<div class="relatedPosts"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(array(120,80)); ?></a>
<div class="relatedPosts_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div></div>
                                    <?php
                                    }
                                    echo \'\';
                                }
                            }
                            $post = $backup;
                            wp_reset_query();
                             ?>

                            <!-- end Related Posts-->
      </div>

      <!-- 10-15 -->
      <div>
我如何让他们只在有内容显示的情况下才显示所有内容(包括CSS)?

提前非常感谢。

1 个回复
最合适的回答,由SO网友:Jono Warren 整理而成

对于Pingbackul &;h2 你必须把它移到你的mytheme_comments 功能,应该在您的主题中functions.php 文件

标记更简单一些,您只需要在php中使用它们:

<?php the_tags(\'<div class="postTags">\',\' \',\'<br /></div>\'); ?>
因此,当没有任何标记时,它不会显示空div。

结束

相关推荐