Wordpress:评论:提交评论打开一个相关的帖子 [英] Wordpress: Comments: Submitting a comment opens a related post

查看:579
本文介绍了Wordpress:评论:提交评论打开一个相关的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的评论表格有问题。

提交评论会导致打开相关文章。

Submitting a comment leads to open a related post.

这里是我的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; ?>

strong>更新:

Update:

我的single.php:

My 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 -->

但是为什么显示不正确?

But why is it displayed incorrectly?

推荐答案

代码中唯一可以对你的问题负责的地方是:

The only point in your code that could be responsible for your problem, as far as I can see, is at:

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

$ post-> ID 当前帖子的ID或为null。如果 $ post 有问题,它将在调用此注释模板的页面上,single.php。你可以尝试改变你当前的single.php文件二十一,看看是否解决了这个问题。或在这里发布single.php文件内容,以便我们可以检查它。

$post->ID should hold the id of the current post or be null. If there is a problem with $post, it will be on the page that calls this comments template, single.php probably. You could try changing your current single.php file for the twentyten one and see if that solves the problem. Or post here that single.php file contents so we can check it.

编辑

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

On the single.php file, you have a new query being executed to get the related posts:

$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

This code is populating the $post variable with each of the related posts found, so once that code is done you will have the $post var holding the last post of the related posts retrieved with that query.

最简单的解决方案:删除相关帖子功能的代码(相关帖子中的所有内容,包括开始和关闭div标签),然后将其粘贴到< / div><! - main - > 之前,或导航部件。

Easiest solution: cut the code for the related posts functionality (everything inside de "related-posts" div, including the opening and closing div tags) and paste it just before the </div><!-- main --> so it doesn't affect the comments or navigation parts.

这篇关于Wordpress:评论:提交评论打开一个相关的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆