Forums

[resolved] How to link comments link to comments only page? (9 posts)

  1. johnnyjp
    Member
    Posted 2 years ago #

    Hi

    I dont want to use the default behaviour of comments for posts.

    After user clicks on "View comments" I want to direct him to the page that would contain only Post title and that would list all the comments for that post.

    I have put this in my theme:

    <a href="<?php comments_link(); ?>"><?php comments_number('No comments', 'One comment', '% comments' );?></a>

    But comments_link() is not what I need. I guess I'll have to create a new template for that, which is okay, but how can I link to this template dynamically without doing this:

    <a href="my-comments-only-template.php"><?php comments_number('No comments', 'One comment', '% comments' );?></a>

  2. johnnyjp
    Member
    Posted 2 years ago #

    okay so i figured out that i just have to make another template, but how do i link to it?

  3. johnnyjp
    Member
    Posted 2 years ago #

    anyone?

  4. johnnyjp
    Member
    Posted 2 years ago #

    guys?

  5. johnnyjp
    Member
    Posted 2 years ago #

    anyone?

  6. johnnyjp
    Member
    Posted 2 years ago #

    oh, come on...!

  7. johnnyjp
    Member
    Posted 2 years ago #

    guys?

  8. johnnyjp
    Member
    Posted 2 years ago #

    people! help me!

  9. johnnyjp
    Member
    Posted 2 years ago #

    okay so you are mega lazy and thats just sad.

    but

    ive come with a solution, but although it works for me right now, it's not very reliable.

    so to have my posts organized in following way:

    list posts > go to and read post > click on comments and go to post title only and comments template

    ive created an extra category called "comments", then i obviously applied it to all the posts that i want to use separate comments template with and i've added this in my category.php template file:

    <?php
    foreach((get_the_category()) as $category) {
    	if($category->cat_name != 'comments'){
    		$link = get_category_link($category);
    		echo '<a href="' . $link . '">' . $category->cat_name . '</a> ';
    	}
    	else{
    
    		$permalink_array = explode('/', get_permalink());
    		$permalink_elements = count($permalink_array);
    
    		$post_url = $permalink_elements - 1;
    
    		$link_to_comments = $permalink_array[$post_url];
    	}
    }
    ?>
    <?php edit_post_link('Edit', '', ' | '); ?>
    
    <a href="<?php echo get_category_link($category); ?>/<?php echo $link_to_comments; ?>"><?php comments_number('No comments', 'One comment', '% comments' );?></a>

    so right now i have two permalinks to one post, one is the regular one:

    http://mysite.com/news/economics/post_title.html

    and the second one that i use for displaying comments is:

    http://mysite.com/comments/post_title.html

    and ive put this in my single.php file:

    <?php
    
    if (in_category($comments_category)) {
         // post-title and comments only template
    }
    else{
         // single post template that shows post title and content and a link to comments
    }
    
    ?>

    as i mentioned its not the ebst way to do it because i have to make sure that i posted this post in "comments" category as well, which is a bit annoying but since no one wanted to help me out thats what ive come up with

Topic Closed

This topic has been closed to new replies.

About this Topic