Pretty date and comments bars in sNews CMS

At the request of one of my readers, I will do my best to explain this little hack for sNews CMS to move the date and comments from the standard "infoline" location below the article to the top, and format them with pretty icons.

So let's get started by backing up your snews.php file and hacking on a copy.

We want the date & comments to go between the article title (if there is one) and the actual article text, so find the function articles, now locate the following code;

if ($r['displaytitle'] == 'YES') {
	if (!$_ID)  {
		echo '<h2 class="big">'.$link.$uri.'/'.$r['asef'].'/">'.$title.'</a></h2>';
	} else {
		echo '<h2>'.$title.'</h2>';
	}
}

and insert the following code below it;

if ($infoline == true) {
    echo '<div class="post_date">'.$a_date_format.'</div>';
    if ($r['commentable'] == 'YES' || $r['commentable'] == 'FREEZ') { //let's show the comments bar only if comments are enabled or frozen
        echo '<div class="post_comments">'.$link.$uri.'/'.$r['asef'].'/#'.l('comment').'1">'.l('comments').' ('.$comments_num.')</a></div>';
    }
    echo '<br class="clearer" />';                                
}

OK, that code adds the date and comment divs up top below the title and before the main article text, so now let's remove the calls from the infoline below the articles, unless you want the old style date and comments below as well. Find and following and comment out (don't delete any lines of code, we want to keep things for future reference or to return to original) as highlighted below;

switch (true) {
	case ($tag == 'date'):
		//echo $a_date_format;
		break;
	case ($tag == 'readmore' && strlen($r['text']) > $shorten):
		echo $link.$uri.'/'.$r['asef'].'/">'.l('read_more').'</a> ';
		break;
	case ($tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ')):
		//echo $link.$uri.'/'.$r['asef'].'/#'.l('comment').'1">
			//'.l('comments').' ('.$comments_num.')</a> ';
		break;
	case ($tag == 'edit' && _ADMIN):
		echo ' '.$edit_link;
		break;
	case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'):
		echo $tag;
		break;
}

Now find the next switch statement below it and comment out as follows;

switch ($tag) {
	case 'date':
		//echo $a_date_format;
		break;
	case 'readmore':
	case 'comments': ;
		break;
	case 'edit':
		if (_ADMIN) {
			echo ' '.$edit_link;
		}
		break;
	default:
		echo $tag;
}

That should do it for the code in the snews.php file. Now we need to add the appropriate styles to your stylesheet so the divs don't stack on each other and look hideous. You can use whatever images you like, these are the two I use (from pinvoke)... date icon    comment icon... save them to your public_html/images folder, and then add these styles to your stylesheet;

.post_date { 
    float: left;
    width: 49%;
    color: #444;
    height: 16px;
    margin: 10px 0; 
    padding-left: 20px;
    background-image: url('../images/date.png');
    background-repeat: no-repeat;
    background-position: center left; 
}
.post_comments { 
    float: right;
    width: 49%;
    color: #444;
    height: 16px;
    margin: 10px 0; 
    padding-right: 20px;
    text-align: right;
    background-image: url('../images/comment.png');
    background-repeat: no-repeat;
    background-position: center right; 
}
.clearer {
    clear: both;
}

As always, feel free to change the styles to suit your specific needs, and don't hesitate to let me know if there's anything missing or if you get any errors.

Share this post:
Share of Facebook Tweet this post Share this post on Google+ Email this post


Comments

RSS Comments Feed


jesth's Avatar

jesth

Just a heads up, the icons are missing for the .css

Matt's Avatar

Matt

Thanks Jesth! Fixed.

Boz's Avatar

Boz

Matt,

For some reason when I apply this mod I "Comments (X)" overlaps the comment image which is displayed twice.

Any ideas what I might be doing wrong?

Matt's Avatar

Matt

Hi Boz,

I'd guess it's likely a CSS styling issue.

Play around with the widths, if your main content box is a fixed width, try adding fixed widths for the date and comment divs, or change the 49% to 47% or something smaller to allow for the padding, etc.

If you can't get it working, you can send me the URL to an example on your site and I'll see if I can figure it out.



(optional, not publicly displayed) (optional)

Site News

About Matt

Privacy Policy | About Me
Copyright © 2002 - 2012 Matt Jones
HTML5/CSS3
Back to Top Back to top