1. News count in category in the main

News count in category in the main

  |   8
News count
This hack will show on the main page the count of the news in categories and how many new news been added since the last visit of the visitor ( cache system).
Installation

1)
-(DLE 10.3 and older) Open index.php
- (DLE 10.4 and newer) Open engine/modules/main.php
Find:
$tpl->set ( '{AJAX}', $ajax );

BEFORE this line add:
/*********Main Menu**********/
$count_news = dle_cache( "count_news_of_category", $config[’skin’] );
if( !$count_news ){  //cache with the news is empty    
$sql_result = $db->query("select ct.id,
(select count(*) from ". PREFIX ."_post ps where ps.category = ct.id AND (DATE_FORMAT(date, '%Y%m%d')=CURDATE()) AND approve = '1') as new_,
(select count(*) from ". PREFIX ."_post ps where ps.category = ct.id AND approve = '1') as allnews_from ". PREFIX ."_category ct"                          );    $count_news_of_category = '';
while($row = $db->get_row($sql_result))
	{
		$t = ' ('.$row['allnews_'].'/'.$row['new_']. '+)';
		$tpl->set('{count_categ_'.$row['id'].'}', $t);
		$count_news_of_category .= $row['id'].'#'.$t.'|';
	}
/**To cache **/
create_cache( 'count_news_of_category', $count_news_of_category);
$db->free();}
else{  //taking number of news from cache
$arr_newscount = explode('|', $count_news);
for ($i = 0; $i <= count($arr_newscount) - 2; $i++)
	{$arr_onenews = explode('#', $arr_newscount[$i]);
	$tpl->set('{count_categ_'.$arr_onenews[0].'}', $arr_onenews[1]);
	}}
/************************************/

====================================================================
2) Open ./engine/modules/addnews.php ,
DLE 10.1 and older find:
if( $config['allow_alt_url'] == "yes" )

DLE 10.2 and newer find:
if( $config['allow_alt_url'] )

BEFORE this line add:
clear_cache('count_news_of_category');

====================================================================
3) Open /engine/ajax/editnews.php , find:
clear_cache( 'news_' );

BEFORE this line add:
clear_cache('count_news_of_category');

====================================================================
4) Now in your template on the main page put tags for the count of categories:
Tag look like {count_categ_1} where 1 - is the ID of the category.
For example:
<a href="/adventure">Adventure <span>{count_categ_4}<span></a>

Will show : Adventure 12/2+ where 12 is the number of the news and 2+ is the new news been posted.
Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.

Details

+5

Comments 8

DLEStarter
DLEStarter
DLE TEAM
Commented By DLEStarter on December 10, 2014 (7:17 am)
The hack is very much the similar function with: http://www.dlestarter.com/tutorials/hack/256-alternative-category-counts.html however, this tutorial uses "cache" which is better.

Also the step on Open ./engine/modules/addnews.php , find:
If you are using DLE 10.2 and 10.3 find
if( $config['allow_alt_url'] )

The function for DLE 10.1 and older versions is
if( $config['allow_alt_url'] == "yes" )

Thank you for sharing.
29 225Forum topics : 9Forum replies : 558Forum likes : 116
Putaso
Putaso
Members
Commented By Putaso on January 8, 2015 (7:10 am)
I'm trying using with 10.3 but not working any idea why?

Thanks!

Okey works now with

$count_news = dle_cache( "count_news_of_category", $config[’skin’] );if( !$count_news ){  //cache with the news is empty
$sql_result = $db->query("select ct.id,                                 (select count(*) from ". PREFIX ."_post ps where ps.category = ct.id AND (DATE_FORMAT(date, '%Y%m%d')=CURDATE()) AND approve = '1') as new_,                                 (select count(*) from ". PREFIX ."_post ps where ps.category = ct.id AND approve = '1') as allnews_                          from ". PREFIX ."_category ct"                          );    $count_news_of_category = '';    while($row = $db->get_row($sql_result))    {           $t = ' ('.$row['allnews_'].'/'.$row['new_']. '+)';       
$tpl->set('{count_categ_'.$row['id'].'}', $t);                   $count_news_of_category .= $row['id'].'#'.$t.'|';    }    /**To cache **/    create_cache( 'count_news_of_category', $count_news_of_category);    $db->free();}else{  //taking number of news from cache  
$arr_newscount = explode('|', $count_news);  for ($i = 0; $i <= count($arr_newscount) - 2; $i++)  {  $arr_onenews = explode('#', $arr_newscount[$i]);    
$tpl->set('{count_categ_'.$arr_onenews[0].'}', $arr_onenews[1]);  }}


http://i.imgur.com/ffTDFnQ.jpg

But I would remove 0+) any idea?
N/A 1Forum topics : 1Forum replies : 1Forum likes : 0
DLEStarter
DLEStarter
DLE TEAM
Commented By DLEStarter on January 8, 2015 (8:04 pm)
replace
$t = ' ('.$row['allnews_'].'/'.$row['new_']. '+)';

with:
$t = ' ('.$row['allnews_'].')';
29 225Forum topics : 9Forum replies : 558Forum likes : 116
seoulxd
seoulxd
Members
Commented By seoulxd on April 26, 2015 (12:54 pm)
dle 10.4????
N/A 10Forum topics : 0Forum replies : 1Forum likes : 0
DLEStarter
DLEStarter
DLE TEAM
Commented By DLEStarter on April 26, 2015 (1:16 pm)
Quote: seoulxd
dle 10.4????

I have updated the tutorial steps...actually if you know what happen to "index.php" in 10.4 then it extremely simple because everything is the same...just keep in mind on any tutorials, hacks and module in Datalife Engine 10.4, any steps telling to open index.php, what you need is instead of open index.php you just open engine/modules/main.php, if you write this down and memorize it then you will never ever ask this same question again and again...keep that in mind you will know what to do
29 225Forum topics : 9Forum replies : 558Forum likes : 116
onchannel
onchannel
V.I.P.
Commented By onchannel on October 4, 2015 (11:03 am)
Quote: DLEStarter
$t = ' ('.$row['allnews_'].')';


there must be somthing missing or i am doing this wrong. On my site, shows on a few categories the number of article ( but not the real number of them ) and on a category it doesn`t show anything, it`s ZERO but the categories has articles in it.

I hava cleared the cache and all of that stuff, but still not showing right. can someone help me?

my site is on my signature
N/A 84Forum topics : 8Forum replies : 14Forum likes : 0

full movies
Ammir
Ammir
Members
Commented By Ammir on November 26, 2015 (1:18 am)
im getting this error

MySQL error in file: /engine/modules/main.php at line 369
Error Number: 1064
The Error returned was:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dle_category ct' at line 3
SQL query:

select ct.id, (select count(*) from dle_post ps where ps.category = ct.id AND (DATE_FORMAT(date, '%Y%m%d')=CURDATE()) AND approve = '1') as new_, (select count(*) from dle_post ps where ps.category = ct.id AND approve = '1') as allnews_from dle_category ct
N/A 38Forum topics : 4Forum replies : 43Forum likes : 0
Inphecthyuz
Commented By Inphecthyuz on May 26, 2016 (7:52 pm)
Quote: Ammir
im getting this error

MySQL error in file: /engine/modules/main.php at line 369
Error Number: 1064
The Error returned was:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dle_category ct' at line 3
SQL query:

select ct.id, (select count(*) from dle_post ps where ps.category = ct.id AND (DATE_FORMAT(date, '%Y%m%d')=CURDATE()) AND approve = '1') as new_, (select count(*) from dle_post ps where ps.category = ct.id AND approve = '1') as allnews_from dle_category ct

I have the same problem bro :(
N/A 21Forum topics : 1Forum replies : 2Forum likes : 0

Please wait while the pixels get undressed. No peeking ;)
Information!Would you like to leave your comment? Please Login to your account to leave comments. Don't have an account? You can create a free account now.
DLEStarter Notice!Please note...Every hack and every module will get additional queries from your database and some hacks and some modules may result your server overload, so install only what you "need", remove any hacks and modules from your script when you don't need them, all hacks and modules appears in this website are not guaranteed by DLEStarter Team for your script security and compatibility, please read instruction carefully and use hacks and modules at your own risk...Thank you.