x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

Show or Hide Comments

Be careful when utilizing these instructions, as this can be fairly intensive on your hosting, and can substantially slow down your page load time.

To just include the comments, without the javascript, is much easier, see Comments on Index

How to show or hide comments on the main entry page

Put this into the head portion of your templates:

<script language="javascript">

function
showMoreAnything(blocknum, isOpen) {
hid
= ('hide' + (blocknum));
unhid = ('click' + (blocknum));
if(
document.getElementById ) {
if( document.getElementById(hid).style.display ) {
if( isOpen != 0 ) {
document
.getElementById(hid).style.display = "block";
document.getElementById(unhid).style.display = "none";
} else {
document
.getElementById(hid).style.display = "none";
document.getElementById(unhid).style.display = "block";
}
}
else {
location
.href = isOpen;
return
true;
}
}
else {
location
.href = isOpen;
return
true;
}
}
</script>
<?
$layernum
= 100;
?>

Set up the comments template:

<div id="blog">
[code] {exp:comment:entries}
<div id="comments-on-index-page">
{comment}
<div class="posted">Posted by {url_or_email_as_author}   

on  {comment_date format
='%m/%d'}  at  {comment_date format= '%h:%i %A'}</div>
</
div>
<
br/>
{/exp:comment:entries}
</div>

Pur this into your index:

<!-- PROVIDE OPTION TO SHOW COMMENTS RIGHT ON THE INDEX PAGE -->
{if {comment_total} > 0}
<div class="posted">
<?php
$layernum
++;
if (!isset(
$jsenabled)) {
?>

<!-- provide "show comments" link -->
<
span id="click<? echo $layernum; ?>"><a href="#?

jsenabled=no"
onclick="showMoreAnything(<? echo $layernum; ?>,'#? jsenabled=no');return false;">
<
i>show comments right here...</i>
</
a></span>
<!--
end of code to provide "show comments" link -->

<?php } ?>

<!-- Above is layer that is shown when not open -->
<!-- if
users click on the link and it doesn't work - the page
will be refreshed with the block below showing -->
<!-- Below is layer that is shown when open -->
<div id="hide<? echo $layernum; ?>" <? if
(!isset($jsenabled)) { ?> style="display: none" <? } ?>>
<!-- provide "hide comments" link -->
<a href="#" onclick="showMoreAnything(<? echo $layernum;

?>,0);return false;"> <i>hide comments...</i>
</a>
<!-- end of code to provide "hide comments" link -->

<br/><br/>

<?php @include("{comment_path=weblog/comments_for_index_page}"); ?>

<!-- provide "hide comments" link -->
<a href="#" onclick="showMoreAnything(<? echo $layernum;
?>,0);return false;">
<i>hide comments...</i>
</a>
<!-- end of code to provide "hide comments" link -->
</div>
</div>
{/if}
<!-- END OF PROVIDING OPTION TO SHOW COMMENTS RIGHT ON THE INDEX PAGE -->

Note, as stated in that post, that PHP parsing must be set to parse on output for the main template.

Category:Comments Category:Templates

Categories: