WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] P2 theme - Hide threads by default (13 posts)

  1. Tommy David
    Member
    Posted 4 years ago #

    Hi everyone,
    I'm using P2 theme. Is there a way to hide threads on homepage by default?

  2. chanzero
    Member
    Posted 4 years ago #

    I'm also interested in knowing how to do this.

  3. tjeastmond
    Member
    Posted 4 years ago #

    I see no default way to do this...for a quick fix just:

    In file 'index.php' change:
    <?php _e('Hide threads', 'p2'); ?>
    to
    <?php _e('Show threads', 'p2'); ?>

    In file 'inline-comments.php' change:
    echo "<ul class=\"commentlist inlinecomments\">\n";
    to
    echo "<ul class=\"commentlist inlinecomments\" style='display:none;'>\n";

    In file 'inc/p2.js' add this code at line 456:
    var hidecomments = true;

  4. Tommy David
    Member
    Posted 4 years ago #

    Great! It works. Thanks!

  5. fharper
    Member
    Posted 4 years ago #

    Thank you! It was usefull.

  6. dlopeman
    Member
    Posted 4 years ago #

    yup - will proly lose it on the first upgrade, too!

    But at least I know where to find it.

  7. thuara
    Member
    Posted 4 years ago #

    Thanks. Works great for me too.

    http://123mudah.com

  8. Luke Janicke
    Member
    Posted 4 years ago #

    I did it like this ...

    inlinecomments.php

    change

    echo "<ul class=\"commentlist inlinecomments\">\n";

    to

    echo "<ul class=\"commentlist inlinecomments\" style=\"display: none;\">\n";

    This makes comments hidden to begin with.

    index.php

    change

    <a href="#" id="togglecomments"><?php _e('Hide threads', 'p2'); ?></a>

    to

    <a href="#" id="togglecomments"><?php _e('Show threads', 'p2'); ?></a>

    This just changes the words at the top of the page.
    So it says "Hide threads" to begin with.

    p2.js

    change

    $("#togglecomments").click(function(){
    	hidecomments = !hidecomments;
    	var hideTxt = p2txt.hide_threads;
    	var showTxt = p2txt.show_threads;
    	if (hidecomments) {
    		commentLoop = false;
    		commentsLists.hide();
    		$(this).text(showTxt);
    	} else {
    		commentsLists.show();
    		$(this).text(hideTxt);
    	}
    	return false;
    });

    to

    $("#togglecomments").click(function(){
    	hidecomments = hidecomments;     // REMOVE !
    	var hideTxt = p2txt.hide_threads;
    	var showTxt = p2txt.show_threads;
    	if (hidecomments) {
    		commentLoop = false;
    		commentsLists.hide();
    		$(this).text(showTxt);
    	} else {
    		commentsLists.show();
    		$(this).text(hideTxt);
    	}
    	hidecomments = !hidecomments;     // ADD THIS LINE
    	return false;
    });

    This makes the first click action to be 'showTxt'.

    I can't find the code that actually replaces style="display: none;" with style="display: block;" but it works anyway.

  9. Luke Janicke
    Member
    Posted 4 years ago #

    I am now trying to exploit this understanding to...

    Hide comments by default in single.php and have links like on Facebook.
    e.g. Comment View Feedback (4)

    Clicking Comments shows/hides the comment form.
    Clicking View Feedback (4) shows/hides comments and includes a comment count.

    Anyway, that is what I aim to achieve.

  10. johbase
    Member
    Posted 4 years ago #

    tjeastmond..
    Great... It works..

  11. Gene53
    Member
    Posted 4 years ago #

    @Luke: Thanks for the code modifications, exactly what I was looking for.

    Cheers
    Gene

  12. vagrantradio
    Member
    Posted 4 years ago #

    This uses cookies to set a preference of open or closed, threads are closed by default. Just download the cookie plugin and link it in your header.

    $("#togglecomments").click(function(){
    	var hideTxt = p2txt.hide_threads;
    	var showTxt = p2txt.show_threads;
    	if (hidecomments) {
    		commentLoop = false;
    		commentsLists.hide();
    		$.cookie('threads', 'hidden');
    		$(this).text(showTxt);
    	} else {
    		commentsLists.show();
    		$.cookie('threads', 'shown');
    		$(this).text(hideTxt);
    	}
    	hidecomments = !hidecomments;
    	return false;
    });
    	var threads = $.cookie('threads');
    	if (threads == 'hidden') {
    		commentsLists.hide();
    		$(this).text(showTxt);
    };
  13. vagrantradio
    Member
    Posted 4 years ago #

    forgot to add a var that changes the text to the correct line.

    $("#togglecomments").click(function(){
    	var hideTxt = p2txt.hide_threads;
    	var showTxt = p2txt.show_threads;
    	if (hidecomments) {
    		commentLoop = false;
    		commentsLists.hide();
    		$.cookie('threads', 'hidden');
    		$(this).text(showTxt);
    	} else {
    		commentsLists.show();
    		$.cookie('threads', 'shown');
    		$(this).text(hideTxt);
    	}
    	hidecomments = !hidecomments;
    	return false;
    });
    	var showTxt = p2txt.show_threads; // add this
    	var threads = $.cookie('threads');
    	if (threads == 'hidden') {
    		commentsLists.hide();
    		$("#togglecomments").text(showTxt); //add this
    };

Topic Closed

This topic has been closed to new replies.

About this Topic