How do i use wpDiscuz in posts loop ?
-
Hi KevinBertrand,
How do you use it in loop? What template file is that?I have added that :
<div id="comments-wrap"> <?php global $withcomments; $withcomments = 1; comments_template( 'comments.php', true ); ?> </div>in my custom template page inside my posts loop
And “comments.php” is the default bones template comments which is override by wpDiscuz.
Hi,
I’m using $withcomments in a page that calls a post’s content. I’m using custom post types and enabled comments for each custom post type as well as ticked the boxes in the wpDiscuz settings.
<?php global $withcomments; $withcomments = true; comments_template("comments.php"); ?>I can load the normal comments.php fine but the wpDiscuz doesn’t load at all.
Any thoughts?
Thanks for your help 🙂
It works fine in a loop.
Here is an example in “twentyfifteen” theme loop.This is the code: http://screencast.com/t/ONMKlZnLcK
This is the result: http://screencast.com/t/KnSqdX9449There is not any JS error or any other problem with wpDiscuz functions.
Make sure comments are allowed on the page you’re testing. I mean these options: http://www.gvectors.com/questions/wpdiscuz-comment-form-is-missing/Hi,
Indeed it work very well in a loop, i was wrong. It was a theme’s issue.
However i try to display more posts in ajax with a load more function :// Add button more posts add_action('wp_ajax_load_more_posts', 'load_more_posts'); function load_more_posts(){ $offset = json_decode( stripslashes( $_POST['offset'] ), true ); $posts = new WP_Query( 'offset='.$offset.'&posts_per_page=5' ); $GLOBALS['wp_query'] = $posts; if( ! $posts->have_posts() ) { get_template_part( 'content', 'none' ); } else { while ( $posts->have_posts() ) { $post = the_post(); $html = ''; $html .= '<article id="post-'.get_the_ID().'" class="'; $html .= implode(' ', get_post_class( 'cf' )); $html .= '" role="article"> <div class="row ml0 mr0"> <header class="article-header"> <div class="row mr0 ml0"> '.get_avatar( get_the_author_meta( 'ID' ), 32 ).' <h3><span class="entry-author author" itemprop="author" itemscope itemptype="http://schema.org/Person">'.get_the_author_link( get_the_author_meta( 'ID' ) ).'</span></h3> <time class="updated entry-time" datetime="'.get_the_time('Y-m-d').'" itemprop="datePublished">'.get_the_time(get_option('date_format')).'</time> </div> <h3 class="h2 entry-title"><a href="#" rel="bookmark" title="'.get_the_title().'">'.get_the_title().'</a></h3> </header> <section class="entry-content cf"> '.get_the_content().' </section> <footer class="article-footer cf"> <ul class="attached-medias">'; foreach(get_attached_media( 'image' ) as $k => $v): $html .= '<li><a href="'.$v->guid.'" class="pop-img"><img src="'.$v->guid.'" alt=""/></a></li>'; endforeach; $html .= '</ul> </footer> </div> <div class="row ml0 mr0"> <div id="comments-wrap"> <!-- Need wpDiscuz comment here --> <!-- Does not work : global $withcomments; $withcomments = 1; comments_template( "comments.php", true ); --> </div> </div> </article>'; echo $html; } } die(); }And i don’t know, how to get wpDiscuz comments from my functions.php file.
Any ideas ?
Thanks for your help 😉 ( and sorry for my english, i hope it’s ok )
The topic ‘How do i use wpDiscuz in posts loop ?’ is closed to new replies.
(@kevinbertrand)
10 years, 10 months ago
Hello,
I would like displaying comments from wpDiscuz in a posts loop.
I have modify wc.php to remove :
if(is_singular()) line. 199 ( function front_end_styles_scripts() )
But it still doesn’t work.
I get a javascript error :
response.contains is not a function
And indeed the ajax request doesn’t send me the expected json object.
Thanks,
https://wordpress.org/plugins/wpdiscuz/