【问题标题】:Same Comment box in wordpress across multiple pages跨多个页面的wordpress中的相同评论框
【发布时间】:2012-11-22 12:43:52
【问题描述】:

快速提问:

是否可以在 Wordpress 的多个页面中使用相同的评论框?

我想在 4-5 个不同的页面上显示完全相同的 cmets。

有可能吗?

提前致谢!

编辑:我添加了下面的代码(它是葡萄牙语),我尝试在每个帖子的基础上插入,但我相信我搞砸了为哪个帖子设置正确的帖子 ID评论应该与其他页面相关,然后在其他页面上解析它

<?php
// Do not delete these lines
    if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
        die ('Please do not load this page directly. Thanks!');

    if ( post_password_required() ) { ?>
        <p class="nocomments">Este artigo está protegido por password. Insira-a para ver os comentários.</p>
    <?php
        return;
    }
?>

<div id="comments">
    <h3><?php comments_number('0 Comentários', '1 Comentário', '% Comentários' );?></h3>

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

        <ol class="commentlist">
            <?php
                //Gather comments for a specific page/post 
                $comments = get_comments(array(
                    'post_id' => 156,
                    'status' => 'approve' //Change this to the type of comments to be displayed
                ));

                //Display the list of comments
                wp_list_comments(array(
                    'per_page' => 10, //Allow comment pagination
                    'reverse_top_level' => false //Show the latest comments at the top of the list
                ), $comments);
            ?>
        </ol>

    </div>

    <?php endif; ?>

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

    <div id="respond">
            <h3>Deixe o seu comentário!</h3>

            <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
            <fieldset>
                <?php if ( $user_ID ) : ?>

                <p>Autentificado como <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(); ?>" title="Sair desta conta">Sair desta conta &raquo;</a></p>

                <?php else : ?>

                <label for="author">Nome:</label>
                <input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" />

                <label for="email">Email:</label>
                <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" />

                <label for="url">Website:</label>
                <input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" />

                <?php endif; ?>

                <label for="comment">Mensagem:</label>
                <textarea name="comment" id="comment" rows="" cols=""></textarea>

                <input type="submit" class="commentsubmit" value="Enviar Comentário" />

                <?php comment_id_fields(); ?>
                <?php do_action('comment_form', $post->ID); ?>
            </fieldset>
        </form>
        <p class="cancel"><?php cancel_comment_reply_link('Cancelar Resposta'); ?></p>
        </div>
     <?php else : ?>
        <h3>Os comentários estão fechados.</h3>
<?php endif; ?>
</div>

【问题讨论】:

  • 到目前为止你尝试过什么?你甚至搜索过谷歌?!一个简单的“Wordpress show cmets”搜索将this page 列为第一个结果,该页面会告诉您确切的操作方法。
  • 我有......但由于我的知识有限,我无法让它按照我想要的方式工作。我应该更具体地回答我的问题,为此我深表歉意。我将在下面进一步解释。谢谢你的回答伙伴:)

标签: wordpress comments


【解决方案1】:

是的,这是可能的。请参阅 wp_list_comments() 的 Codex -

<ol class="commentlist">
    <?php
        //Gather comments for a specific page/post 
        $comments = get_comments(array(
            'post_id' => XXX,
            'status' => 'approve' //Change this to the type of comments to be displayed
        ));

        //Display the list of comments
        wp_list_comments(array(
            'per_page' => 10, //Allow comment pagination
            'reverse_top_level' => false //Show the latest comments at the top of the list
        ), $comments);
    ?>
</ol>

【讨论】:

  • 嘿,伙计,谢谢你唯一的问题,正如我上面所说的,我的问题并不清楚。我真正想要的是在所有页面上显示 cmets 和带有名称、电子邮件、网站和答案的评论框,但我无法让它工作。除了您在上面发布的内容之外,我还尝试了 this page 的代码。问题是我无法以正确的方式在所有页面上显示 cmets 和评论框。可能是 stg 与 post_id 的东西,但我真的不知道如何正确编码 =/
猜你喜欢
  • 1970-01-01
  • 2012-02-10
  • 1970-01-01
  • 2013-03-18
  • 2015-09-08
  • 2011-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多