Forums

making comments display on main page (3 posts)

  1. larsbear947
    Member
    Posted 2 years ago #

    So, what I'm trying to do is make it so that comments that have been made display on the main page of the blog site, so you don't have to click on the link to be able to see them before making a new comment. Frankly I think it's kind of silly that themes aren't inherently built this way, but that's just me.

    So I've found a lot of resources on here about how to do this, and I've even gotten it to work on some themes, but right now I'm trying to get it to work in Mystique, but when I add

    <?php $withcomments = 1; ?>
    <?php comments_template(); ?>

    to it, it sort of works, in that it displays a comments field that shows previous comments on the posts, but the problem is that it displays the last comment made on the site on all of the posts that have comments instead of displaying the comments particular to that post. That may sound weird, so here's an example:

    On the next-to-latest post on my blog, my wife commented, "awesome – let me see your rough draft." When I add the above code to the index.php, it adds a comment display field under all of the posts on the site, and under each one that people have commented on, it shows THIS comment, "awesome – let me see your rough draft." rather than the comments actually made on that particular post. Below is the code from the index.php page for mystique, if anyone can help me, I would be very appreciative.

    <?php
    /* Mystique/digitalnature */
    get_header();
    ?>

    <!-- main content: primary + sidebar(s) -->
    <div id="main">
    <div id="main-inside" class="clearfix">
    <!-- primary content -->
    <div id="primary-content">

    <?php if (have_posts()): ?>
    <?php while (have_posts()): the_post();
    $post_preview = get_mystique_option('post_preview');
    $category = get_the_category();
    $category_name = $category[0]->cat_name;
    if(!empty($category_name)) $category_link = 'cat_ID).'">'.strip_string(34,$category_name).'';
    else $category_link = "[...]";
    if(function_exists('the_post_image'))
    if (has_post_image()) $post_thumb = true; else $post_thumb = false;
    ?>
    <!-- post -->
    <div id="post-<?php the_ID(); ?>" <?php post_class('clearfix preview-'.$post_preview); ?>>

    <?php if($post_thumb): ?>
    "><?php the_post_image('thumbnail'); ?>
    <?php endif; ?>

    <h2 class="title">" rel="bookmark" title="<?php _e('Permanent Link:','mystique'); echo ' '; the_title_attribute(); ?>"><?php the_title(); ?></h2>

    <div class="post-date">
    <p class="day"><?php the_time(__('M jS','mystique')); ?></p>
    </div>

    <div class="post-info clearfix <?php if ($post_thumb) echo 'with-thumbs' ?>">
    <p class="author alignleft"><?php printf(__('Posted by %1$s in %2$s','mystique'),'<a href="'. get_author_posts_url(get_the_author_ID()) .'" title="'. sprintf(__("Posts by %s","mystique"), attribute
    _escape(get_the_author())).' ">'. get_the_author() .'',$category_link);
    ?>
    <?php if(function_exists('the_views')): ?><span class="postviews">| <?php the_views(); ?></span><?php endif; ?>
    <?php edit_post_link(__('Edit','mystique'),' | '); ?>
    </p>
    <?php
    global $id, $comment;
    $number = get_comments_number($id);
    if (comments_open() || $comments): ?>
    <p class="comments alignright">#comments" class="<?php if ($number<1) echo "no"; ?> comments"><?php comments_number(__('No comments', 'mystique'), __('1 comment', '
    mystique'), __('% comments', 'mystique')); ?>
    </p>
    <?php endif; ?>
    </div>

    <?php if($post_preview<>'title'): ?>
    <div class="post-content clearfix">
    <?php if($post_preview=='excerpt') the_excerpt(); else the_content(__('Read the rest of this entry »', 'mystique')); ?>
    </div>
    <?php if($post_preview<>'title'): ?>
    <div class="post-content clearfix">
    <?php if($post_preview=='excerpt') the_excerpt(); else the_content(__('Read the rest of this entry »', 'mystique')); ?>
    </div>
    <?php if(function_exists('the_ratings')) the_ratings(); ?>

    <?php
    $post_tags = get_the_tags();
    if ($post_tags): ?>
    <div class="post-tags">
    <?php
    $tags = array();
    $i = 0;
    foreach($post_tags as $tag):
    $tags[$i] .= 'term_id).'" rel="tag" title="'.sprintf(__('%1$s (%2$s topics)'),$tag->name,$tag->count).'">'.$tag->name.'';
    $i++;
    endforeach;
    echo implode(', ',$tags); ?>
    </div>
    <?php endif; ?>

    <?php endif; ?>
    <?php $withcomments = 1; ?>
    <?php comments_template(); ?>
    </div>
    <!-- /post -->
    <?php endwhile; ?>

    <div class="page-navigation clearfix">
    <?php if(function_exists('wp_pagenavi')): wp_pagenavi(); else: ?>
    <div class="alignleft"><?php next_posts_link(__('« Older Entries','mystique')) ?></div>
    <div class="alignright"><?php previous_posts_link(__('Newer Entries »','mystique')) ?></div>
    <?php endif; ?>
    </div>
    <?php else : ?>

    <h1 class="title error"><?php _e("No posts found","mystique"); ?></h1>
    <p><?php _e("Sorry, but you are looking for something that isn't here.","mystique"); ?></p>

    <?php endif; ?>

    </div>
    <!-- /primary content -->

    <?php get_sidebar(); ?>

    </div>
    </div>
    <!-- /main content -->

    <?php get_footer(); ?>
    (END)

  2. fuentism
    Member
    Posted 2 years ago #

    Hi larsbear947,

    I was having this same problem using:

    <?php $withcomments = "1"; ?>
    <?php comments_template(); ?>

    but it worked when changed to:

    <?php $withcomments = "1"; ?>
    <?php comments_template(TEMPLATEPATH . '/comments.php'); ?>

    Give it a try?

  3. The Cordoba
    Member
    Posted 1 year ago #

    Fuentism: Thanks for the code... It Worked! :D

Topic Closed

This topic has been closed to new replies.

About this Topic