If there are no pingbacks, don't show anything (if tags)
-
Although I’ve read several times through the WordPress Codex, I have difficulties to do what I want. Actually this is for certain parts of my blog, so I guess once I figure out how to do it I can make it work for all of them.
For example: If there are no pingbacks, the CSS coding is still shown (background, title etc.) which looks weird. Same for Recent Posts.
My setup for the them looks like this:
<?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; ?>
And the function.php code for the comments:
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="https://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 }
Related Posts:
<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>
How do I get them to display everything (including CSS) only if there actually is content to show?
Thanks a lot in advance.
- The topic ‘If there are no pingbacks, don't show anything (if tags)’ is closed to new replies.