WordPress的:评论:提交评论打开相关的职位(Wordpress: Comments: Sub

2019-10-29 02:40发布

我有我的意见形式的问题。

提交评论导致打开一个相关的帖子。

这里是我的comments.php:

<?php
    if ( post_password_required() ) :
        echo '<h3 class="comments-header">' . __('Password Protected', 'buddypress') . '</h3>';
        echo '<p class="alert password-protected">' . __('Enter the password to view comments.', 'buddypress') . '</p>';
        return;
    endif;

    if ( is_page() && !have_comments() && !comments_open() && !pings_open() )
        return;
?>

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

    <div id="comments">

        <?php
            // Only include comments
            $numTrackBacks = 0; $numComments = 0;
            foreach ( (array)$comments as $comment )
                if ( 'comment' != get_comment_type() )
                    $numTrackBacks++;
                else
                    $numComments++;
        ?>

        <h3 id="comments">
            <?php
                printf( _n( '1 Kommentar', '%1$s Kommentare', $numComments, 'buddypress' ),
                number_format_i18n( $numComments ), '<em>' . get_the_title() . '</em>' );
            ?>
        </h3>

        <?php do_action( 'bp_before_blog_comment_list' ) ?>

        <ol class="commentlist">
            <?php wp_list_comments() ; ?>
        </ol><!-- .comment-list -->

        <?php do_action( 'bp_after_blog_comment_list' ) ?>

        <?php if ( get_option( 'page_comments' ) ) : ?>

            <div class="comment-navigation paged-navigation">

                <?php paginate_comments_links(); ?>

            </div>

        <?php endif; ?>

    </div><!-- #comments -->

<?php else : ?>

    <?php if ( pings_open() && !comments_open() && is_single() ) : ?>

        <p class="comments-closed pings-open">
            <?php printf( __('Comments are closed, but <a href="%1$s" title="Trackback URL for this post">trackbacks</a> and pingbacks are open.', 'buddypress'), trackback_url( '0' ) ); ?>
        </p>

    <?php elseif ( !comments_open() && is_single() ) : ?>

        <p class="comments-closed">
            <?php _e('Keine Kommentare erlaubt.', 'buddypress'); ?>
        </p>

    <?php endif; ?>

<?php endif; ?>

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

    <div id="respond">

        <div class="comment-avatar-box">
            <div class="avb">
                <?php if ( bp_loggedin_user_id() ) : ?>
                    <a href="<?php echo bp_loggedin_user_domain() ?>">
                        <?php echo get_avatar( bp_loggedin_user_id(), 50 ); ?>
                    </a>
                <?php else : ?>
                    <?php echo get_avatar( 0, 50 ); ?>
                <?php endif; ?>
            </div>
        </div>

        <div class="comment-content">

            <h3 id="reply" class="comments-header">
                <?php comment_form_title( __( 'Leave a Reply', 'buddypress' ), __( 'Leave a Reply to %s', 'buddypress' ), true ); ?>
            </h3>

            <p id="cancel-comment-reply">
                <?php cancel_comment_reply_link( __( 'Click here to cancel reply.', 'buddypress' ) ); ?>
            </p>

            <?php if ( get_option( 'comment_registration' ) && !$user_ID ) : ?>

                <p class="alert">
                    <?php printf( __('You must be <a href="%1$s" title="Log in">logged in</a> to post a comment.', 'buddypress'), wp_login_url( get_permalink() ) ); ?>
                </p>

            <?php else : ?>

                <?php do_action( 'bp_before_blog_comment_form' ) ?>

                <form action="<?php echo site_url( 'wp-comments-post.php' ) ?>" method="post" id="commentform" class="standard-form">

                    <?php if ( $user_ID ) : ?>

                        <p class="log-in-out">
                            <?php printf( __('Logged in as <a href="%1$s" title="%2$s">%2$s</a>.', 'buddypress'), bp_loggedin_user_domain(), $user_identity ); ?> <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php _e('Log out of this account', 'buddypress'); ?>"><?php _e('Log out &rarr;', 'buddypress'); ?></a>
                        </p>

                    <?php else : ?>

                        <?php $req = get_option( 'require_name_email' ); ?>

                        <p class="form-author">
                            <label for="author"><?php _e('Name', 'buddypress'); ?> <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
                            <input type="text" class="text-input" name="author" id="author" value="<?php echo $comment_author; ?>" size="40" tabindex="1" />
                        </p>

                        <p class="form-email">
                            <label for="email"><?php _e('Email', 'buddypress'); ?>  <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
                            <input type="text" class="text-input" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="40" tabindex="2" />
                        </p>

                        <p class="form-url">
                            <label for="url"><?php _e('Website', 'buddypress'); ?></label>
                            <input type="text" class="text-input" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="40" tabindex="3" />
                        </p>

                    <?php endif; ?>

                    <p class="form-textarea">
                        <label for="comment"><?php _e('Comment', 'buddypress'); ?></label>
                        <textarea name="comment" id="comment" cols="60" rows="10" tabindex="4"></textarea>
                    </p>

                    <?php do_action( 'bp_blog_comment_form' ) ?>

                    <p class="form-submit">
                        <input class="submit-comment button" name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit', 'buddypress'); ?>" />
                        <?php comment_id_fields(); ?>
                    </p>

                    <div class="comment-action">
                        <?php do_action( 'comment_form', $post->ID ); ?>
                    </div>

                </form>

                <?php do_action( 'bp_after_blog_comment_form' ) ?>

            <?php endif; ?>

        </div><!-- .comment-content -->
    </div><!-- #respond -->

    <?php endif; ?>

    <?php if ( $numTrackBacks ) : ?>
        <div id="trackbacks">

            <span class="title"><?php the_title() ?></span>

            <?php if ( 1 == $numTrackBacks ) : ?>
                <h3><?php printf( __( '%d Trackback', 'buddypress' ), $numTrackBacks ) ?></h3>
            <?php else : ?>
                <h3><?php printf( __( '%d Trackbacks', 'buddypress' ), $numTrackBacks ) ?></h3>
            <?php endif; ?>

            <ul id="trackbacklist">
                <?php foreach ( (array)$comments as $comment ) : ?>

                    <?php if ( get_comment_type() != 'comment' ) : ?>
                        <li><h5><?php comment_author_link() ?></h5><em>on <?php comment_date() ?></em></li>
                    <?php endif; ?>
                <?php endforeach; ?>
            </ul>
        </div>
    <?php endif; ?>

答案将不胜感激

更新:

我的single.php:

<?php get_header(); ?>
<!-- LAESST DEN HEADER ERSCHEINEN -->

    <div id="main">

    <!-- DAS IST DER LOOP! HIER WIRD DER BEFEHL GEGEBEN, DEN INHALT ANZUZEIGEN (ARTIKEL ETC) -->

        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
           <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>   <!-- DIESER BEFEHL ZEIGT UND VERLINKT DIE ARTIKEL UEBERSCHRIFT -->
           <div class="entry">
               <?php the_content(); ?>
           </div>
        <?php endwhile; ?>

   <div class="author-box">

                        <p><?php echo get_avatar( get_the_author_meta( 'user_email' ), '50' ); ?></p>
                        <p><?php printf( __( 'Geschrieben von %s', 'buddypress' ), bp_core_get_userlink( $post->post_author ) ) ?>  am <?php the_time('j. F Y'); ?> um <?php the_time(); ?></p>
                        <p> Kategorie(n): <?php the_category(', '); ?> </p>
                    </div>

 <div id="related-posts"
    <?php
$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'=>3, // Number of related posts that will be shown.
        'caller_get_posts'=>1
    );
    $my_query = new wp_query($args);
    if( $my_query->have_posts() ) {
        echo '<h3>Das k&ouml;nnte dich auch interessieren</h3><ul>';
        while ($my_query->have_posts()) {
            $my_query->the_post();
        ?>
            <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
        <?php
        }
        echo '</ul>';
    }
}
?>
</div>

<!--"NEXT POST" BZW "PREVIOUS POST" NAVIGATION -->

         <p align="center"><?php next_posts_link('&laquo; &Auml;ltere Eintr&auml;ge') ?>  <?php previous_posts_link('Neuere Eintr&auml;ge &raquo;') ?></p>

    <?php endif; ?>

    <?php comments_template(); ?> <!-- LAESST DAS KOMMENTARFELD ERSCHEINEN -->

    </div><!-- main -->

    <div id="sidebar">

        <?php get_sidebar(); ?>
        <!-- LAESST DIE SIDEBAR ERSCHEINEN -->

    </div><!-- sidebar -->

<?php get_footer(); ?>
<!-- DIESER BEFEHL LAESST DEN FOOTER ERSCHEINEN -->

但为什么显示不正确?

Answer 1:

在你的代码的唯一一点,可能是负责您的问题,据我所看到的,是:

 <div class="comment-action">
      <?php do_action( 'comment_form', $post->ID ); ?>
</div>

$post->ID应保持当前帖子的ID或为空。 如果有一个问题$post ,这将是可能调用此评论模板,single.php中的页面上。 你可以试着改变你目前的single.php文件的twentyten,看看是否能解决问题。 或张贴这里的single.php文件的内容,所以我们可以检查。

编辑:

在single.php中的文件,你有一个新的查询被执行,以获得相关的帖子:

$args=array(
        'tag__in' => $tag_ids,
        'post__not_in' => array($post->ID),
        'showposts'=>3, // Number of related posts that will be shown.
        'caller_get_posts'=>1
    );
    $my_query = new wp_query($args);
if( $my_query->have_posts() ) {

此代码填充$post每发现相关帖子的变量,所以一旦代码完成,您将有$post VAR控股与查询检索到的相关帖子的最后一个职位。

最简单的方法:切断了代号为相关帖子的功能(里面的东西去“相关的短柱”分区,包括打开和关闭div标签),并粘贴之前只是</div><!-- main -->所以不影响意见或导航部分。



文章来源: Wordpress: Comments: Submitting a comment opens a related post