如何将wordpress帖子评论拉到外部页面

发布于 2024-10-14 08:25:35 字数 841 浏览 3 评论 0原文

您好,我想知道是否有一种方法可以将帖子上的评论内容从 WordPress 拉到单独的页面。目前这就是我所拥有的,我想用一个函数来替换以拉出评论,而不是拉出评论的链接。

<?php
// Include Wordpress 
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
?>
<div>
<p style="font-size:18px;color:white;font-wieght:700;">Recently Asked Questions</p>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()): the_post(); ?>
<div id="faq">
<a href="<?php the_permalink() ?>"><?php the_title() ?></a><br />
<?php the_time('F jS, Y') ?>
<?php the_excerpt(); ?>
<?php comments_popup_link(); ?>
To see the answer to the question click <a href="<?php the_permalink() ?>">here</a>.<br /><br />
</div>
<?php endwhile; ?>
</div>

如有任何帮助,我们将不胜感激,谢谢。

Hello I would like to know if there is a way to pull the contents of comments on a post to a separate page from wordpress. currently this is what i have, i'd like to replace with a function to pull the comments instead of pulling the link to the comments.

<?php
// Include Wordpress 
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
?>
<div>
<p style="font-size:18px;color:white;font-wieght:700;">Recently Asked Questions</p>
<?php query_posts('showposts=3'); ?>
<?php while (have_posts()): the_post(); ?>
<div id="faq">
<a href="<?php the_permalink() ?>"><?php the_title() ?></a><br />
<?php the_time('F jS, Y') ?>
<?php the_excerpt(); ?>
<?php comments_popup_link(); ?>
To see the answer to the question click <a href="<?php the_permalink() ?>">here</a>.<br /><br />
</div>
<?php endwhile; ?>
</div>

Any help is appreciated, thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-10-21 08:25:35

由于您正在运行循环,因此您应该能够使用 comments.php 主题文件中的代码。这是一个非常通用的。只需确保将代码放入循环内即可。

<div id="comments">


<?php if ( have_comments() ) : ?>
            <h3 id="comments-title"><?php
            printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number()),
            number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' );
            ?></h3>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
            <div class="navigation">
                <div class="nav-previous"><?php previous_comments_link('<span class="meta-nav">←</span> Older Comments'); ?></div>
                <div class="nav-next"><?php next_comments_link('Newer Comments <span class="meta-nav">→</span>'); ?></div>
            </div> <!-- .navigation -->
<?php endif; // check for comment navigation ?>

            <ol class="commentlist">
                <?php
                    wp_list_comments(array(
                        'type' => 'comment',
                        'avatar_size' => '35',
                        'style' => 'div',
                        'reverse_top_level' => true
                    ));
                ?>
            </ol>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
            <div class="navigation">
                <div class="nav-previous"><?php previous_comments_link('<span class="meta-nav">←</span> Older Comments'); ?></div>
                <div class="nav-next"><?php next_comments_link('Newer Comments <span class="meta-nav">→</span>'); ?></div>
            </div><!-- .navigation -->
<?php endif; // check for comment navigation ?>

<?php else : // or, if we don't have comments:

    /* If there are no comments and comments are closed,
     * let's leave a little note, shall we?
     */
    if ( ! comments_open() ) :   ?>

    <!--<p class="nocomments">Comments are closed.</p>-->

<?php endif; // end ! comments_open()
endif; // end have_comments()

comment_form(array(
    'comment_notes_after' => '<p style="margin: 0 0 10px 50px;color:gray;"><b> <i> and <strike> only</p>',
    'fields' => array(
        'author' => '<p class="comment-form-author">' . '<label for="author">Name</label> ' . ( $req ? '<span class="required">*</span> ' : '' ) .
                    '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span> ' : '' ) .
                    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>'

    )

  )
);
?>

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

Since you are running a loop, you should simply be able to use the code from your comments.php theme file. Here's a pretty generic one. Just make sure you put the code inside the loop.

<div id="comments">


<?php if ( have_comments() ) : ?>
            <h3 id="comments-title"><?php
            printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number()),
            number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' );
            ?></h3>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
            <div class="navigation">
                <div class="nav-previous"><?php previous_comments_link('<span class="meta-nav">←</span> Older Comments'); ?></div>
                <div class="nav-next"><?php next_comments_link('Newer Comments <span class="meta-nav">→</span>'); ?></div>
            </div> <!-- .navigation -->
<?php endif; // check for comment navigation ?>

            <ol class="commentlist">
                <?php
                    wp_list_comments(array(
                        'type' => 'comment',
                        'avatar_size' => '35',
                        'style' => 'div',
                        'reverse_top_level' => true
                    ));
                ?>
            </ol>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
            <div class="navigation">
                <div class="nav-previous"><?php previous_comments_link('<span class="meta-nav">←</span> Older Comments'); ?></div>
                <div class="nav-next"><?php next_comments_link('Newer Comments <span class="meta-nav">→</span>'); ?></div>
            </div><!-- .navigation -->
<?php endif; // check for comment navigation ?>

<?php else : // or, if we don't have comments:

    /* If there are no comments and comments are closed,
     * let's leave a little note, shall we?
     */
    if ( ! comments_open() ) :   ?>

    <!--<p class="nocomments">Comments are closed.</p>-->

<?php endif; // end ! comments_open()
endif; // end have_comments()

comment_form(array(
    'comment_notes_after' => '<p style="margin: 0 0 10px 50px;color:gray;"><b> <i> and <strike> only</p>',
    'fields' => array(
        'author' => '<p class="comment-form-author">' . '<label for="author">Name</label> ' . ( $req ? '<span class="required">*</span> ' : '' ) .
                    '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span> ' : '' ) .
                    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>'

    )

  )
);
?>

</div><!-- #comments -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文