x
 
Create New Page
 View Previous Changes    ( Last updated by Sue Crocker )

Blog Stats

Here is a quick trick to place Blog Stats in a sidebar, that present the data grammatically correct (one user, no users, etc).

The problem is that you cannot use a conditional (if total_guests > 1) with these tags, so you need to use PHP in your templates to accomplish this.

* Enable PHP Output in your template(s) that will hold the code below.
* Place the following code where you would like your stats to show. I actually place this in a seperate template and use the {embed} tag to embed it where I want it. This has the added benefit of only requiring PHP to be enabled on the embeded template, not the index template for security reasons. For more information on the embed tag, see the user documentation on embedding templates.
* You may need to edit the presentation of the stats to fit your blog’s templates and design.

{exp:stats weblog="BlogShortName"}
<h2>Blog Stats</h2>
<
ul>

<?php
$members
= "{total_logged_in}";
$guests = "{total_guests}";

if (
$members > "1"){
echo "<li>There are $members members online </li>";
}elseif ($members == "1"){
echo "<li>There is one member online </li>";
}elseif ($members == "0"){
echo "<li>There are no members online </li>";
}

if ($guests == '0'){
echo "<li>There are no guests online </li>";
}elseif ($guests == '1'){
echo "<li>There is one guest online </li>";
}elseif ($guests > '1'){
echo "<li>There are $guests guests online </li>";
}
?>

<li style="color: #000"><strong>This blog contains:</strong></li>
<
ul>
<
li>{total_entries} Entries </li>
<
li>{total_comments} Comments </li>
<
li> {total_trackbacks} Trackbacks </li>
</
ul>

{if member_names}
<li style="color: #000"><strong>Logged in Members:</strong> </li>
<
ul><li>{member_names}
<a href="{member_path=member/profile}">{name backspace="6"}</a>
{/member_names}
{
/if}</li>
<
li> Most Visitors @ one time: {most_visitors} </li>
</
ul>
</
ul>

{/exp:stats}

Category:Tricks

Categories: