2011-01-27 80 views
0

您好,我想知道是否有办法将帖子上的评论内容从wordpress中提取到单独的页面。目前这就是我所拥有的,我想用一个函数来替代拉取评论而不是拉链接到评论。如何将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> 

任何帮助表示赞赏,谢谢。

+0

你也可以尝试你的问题上wordpress.stackexchange.com – JakeParis 2011-01-27 19:22:47

回答

1

既然你正在运行一个循环,你应该简单地能够从你的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">&larr;</span> Older Comments'); ?></div> 
       <div class="nav-next"><?php next_comments_link('Newer Comments <span class="meta-nav">&rarr;</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">&larr;</span> Older Comments'); ?></div> 
       <div class="nav-next"><?php next_comments_link('Newer Comments <span class="meta-nav">&rarr;</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;">&lt;b&gt; &lt;i&gt; and &lt;strike&gt; 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 --> 
+1

主查询对象不包含的意见,直到comments_template后`()`是所谓的(奇,我知道),但是上面将无法正常工作正如你所期望的那样(因为评论没有被提取)。按照你的建议,你可以用为`comments_template()`调用替换所有的代码,虽然它可能不希望在所有的评论模板的标记来拉。 – t31os 2011-01-28 16:20:17