Conditional tags: Gibt es keine Pingbacks, soll auch nichts angezeigt werden

  • Hallo.
    Ich habe ein Problem mit meinen Pingbacks und den Related Posts.
    Gibt es keine, wird trotzdem das CSS angezeigt (z.B. für die Related Posts der leere Container und die Überschrift etc.).

    Mir ist zwar klar, dass ich conditional tags benutzen muss, um das in den Griff zu bekommen, allerdings weiß ich nicht genau, wie und wo ich diese implementieren soll.

    Hier der betreffende Code für die Pingbacks:

    PHP
    <?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; ?>

    Und der dazugehörige Code in der funciton.php:

    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 }


    Und hier für die Related Posts:

    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>

    Hier meine Webseite.

    Wäre toll, wenn mir hier jemand einen Tipp geben könnte, wie ich das am besten anstellen kann.

    Vielen Dank im Voraus! :)

    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

  • Sollte mit

    PHP
    if ( ! empty($comments_by_type['pings']) ) {


    lösbar sein. Guck auch mal hier: http://themetation.com/2008/12/12/sep…s-in-wordpress/

    [size=10]Bitte immer zuerst die Forensuche nutzen und erst danach Deine Fragen hier im Forum stellen, denn sehr vieles wurde schon mehrfach beantwortet. Bitte dabei auch die Forenregeln beachten.
    Kein Support per PN - Fragen gehören ins Forum.[/SIZE]
    [size=8]Wenn du eine weise Antwort verlangst, musst du vernünftig fragen. (Johann Wolfgang von Goethe)[/SIZE]

  • Hallo.
    Vielen Dank für den Tipp.
    Ich hab mal versucht, den von dir verlinkten Code in meinen einzubauen.
    Das sieht dann so aus:

    Problem: Es zeigt nun weder die Kommentare, noch die Pingbacks an, es sei denn ich nehme das "if empty" wieder heraus.

    Woran könnte das liegen?

    Ich verwende momentan Wordpress 3.2 - falls das eine Rolle spielt.
    Danke im Voraus :)

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!