Recent Topics

How to Find the Count of Published Posts?

Started by on Jan 10, 2015 – Contents updated: Feb 14, 2015

Jan 10, 2015 20:08    

Hi I have been trying to find a variable that will give me the total number of posts per blog. After many hours I did find something that gave me the total for the database but that included all post from all blogs.

So despite my reticence I decided to have a go at an SQL query and came up with this, although I'm sure there is some way of using SQL COUNT.

Something odd: On one of my domains the count is out by 1

Is there a simple inbuilt variable?


// getting postcount
        mysql_connect("localhost""userName""passWord") or die(mysql_error());
        mysql_select_db("dataBaseName") or die(mysql_error());
        $row_query "
            SELECT evo_items__item.post_main_cat_ID,
            FROM evo_items__item
            JOIN evo_categories
            ON evo_items__item.post_main_cat_ID = evo_categories.cat_ID
            AND evo_categories.cat_blog_ID = $Blog->ID
            AND evo_items__item.post_ptyp_ID = 1
            AND evo_items__item.post_status = 'published'
        $row_result mysql_query($row_query) or die(mysql_error());
        $postcount 1;
         while($evo_items_item_row mysql_fetch_array($row_result) )
        $listplots $postcount;
echo '<a href="http://' $_SERVER['HTTP_HOST'] . '/' $Blog->name '.php?disp=postidx">Paged Index of All <b>' $listplots '</b> Posts</a>';

And I have css styling (not included above) for the echo

You can see it working at

The count per page number was set in [/skin/_postidx.disp.php]
LIne 28: 'limit' => 10,
and copied to [/skin/]

See also

11 Jan 2015 01:34

Adding variables at beginning to incorporate 'members/protected' posts for registered users when logged in.

$reg = 'published';
if (isset($current_User))
$reg = 'protected';

and updated last line of query to use variable

AND (evo_items__item.post_status = 'published' OR evo_items__item.post_status = '$reg')

Form is loading...

Complete website engine – This forum is powered by b2evolution CMS, a complete engine for your website.