My first mod for sNews 1.6.
New modification "limitation your articles from each category" September, 1

Multiple Areas(zones) for Categories (MA 1.0) -
cat1, cat 2, cat 3 and cat 4 - means I have 4 areas for categories
cat1 - put in new category Position Area=0 (see right image)
cat2 - put in new category Position Area=1
cat3 - put in new category Position Area=2
cat4 - put in new category Position Area=3
See how to use in your index.php in examples
If you want more then one areas for put your categories, this is works fine.
Example :
Top category, Left category, Right Category
You can :
- Show / Hide count (articles) in category
- Show / Hide category in sitemap
Very simple, just few code
In SQL database:alter table categories add catnumber int(6) default '0';
alter table categories add showcount varchar(4) NOT NULL default 'YES';
alter table categories add showsitemap varchar(4) NOT NULL default 'YES';
Add red lines in categories function:
Purple new modification// DISPLAY CATEGORIES
function categories($num, $showhome, $showcnt, $start, $size) {
if ($num=='') $num=0;
if ($showhome==''|| $showhome!='false')$showhome='true'; else $showhome='false';
if ($showcnt=='' || $showcnt!='false')$showcnt='true'; else $showcnt='false';
$categorySEF = get_id('category');
$class = $category_title == $categorySEF ? ' class="current"' : '';
if ($num==0 || $showhome=='true') echo '<li><a'.$class.' href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
$query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' AND catnumber='$num' ORDER BY catorder ASC";
if (!empty($start) && !empty($size)) $query .=" LIMIT $start, $size";
$result = mysql_query($query); $num_cat = mysql_num_rows($result);
if ($num_cat==0 && $showhome!='true'){echo l('no_articles');} else
while ($r = mysql_fetch_array($result)) {
$calc_num_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND category = $r[id] AND published = 1";
$cm_result = mysql_query($calc_num_query);
$num_rows = mysql_num_rows($cm_result);
$category_title = $r['seftitle'];
$class = $category_title == $categorySEF ? ' class="current"' : '';
echo '<li><a'.$class.' href="'.db('website').$category_title.'/" title="'.$r['description'].'">'.$r['name'];
//echo (s('num_categories') == 'on' ? ' ('.$num_rows.')' : '').'</a></li>';
if ($showcnt=='true' && $r['showcount']=='YES') echo ' ('.$num_rows.')'; echo '</a></li>';
}}
Add red code in sitemap
echo '</p>';
$cat_query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' AND showsitemap = 'YES' ORDER BY catorder";
$cat_result = mysql_query($cat_query);
while ($c = mysql_fetch_array($cat_result)) {
Find blue text and add line red
// CATEGORIES FORM
function form_categories() {
...
$frm_description = $r['description'];
$frm_publish = $r['published'] == 'YES' ? 'ok' : '';
$frm_numcat = $r['catnumber'];
$frm_showsitemap = $r['showsitemap'] == 'YES' ? 'ok' : '';
$frm_showcount = $r['showcount'] == 'YES' ? 'ok' : '';
$frm_task = 'edit_category';
...
$frm_description = '';
$frm_publish = 'ok';
$frm_numcat = 0;
$frm_showsitemap = 'ok';
$frm_showcount = 'ok';
$frm_task = 'add_category';
...
echo html_input('text', 'seftitle', 's', $frm_sef_title, l('sef_title_cat'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 'description', 'desc', $frm_description, l('description'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 'cat_num', 'catnum', $frm_numcat, l('cat_num'), '', '', '', '', '', '', '', '', '', '');
echo html_input('checkbox', 'showcount', 'scnt', 'YES', l('show_count'), '', '', '', '', $frm_showcount, '', '', '', '', '');
echo html_input('checkbox', 'showsitemap', 'ssm', 'YES', l('show_sitemap'), '', '', '', '', $frm_showsitemap, '', '', '', '', '');
echo html_input('checkbox', 'publish', 'pub', 'YES', l('publish_category'), '', '', '', '', $frm_publish, '', '', '', '', '');
...
In function processing()
found
$publish_article = ($_POST['publish_article'] == 'on' || $position > 1) ? 1 : 0;
$publish_category = $_POST['publish'] == 'on' ? 'YES' : 'NO';
append this 3 lines
$catnumber = $_POST['cat_num'];
$showsitemap = $_POST['showsitemap'] == 'on' ? 'YES' : 'NO';
$showcount = $_POST['showcount'] == 'on' ? 'YES' : 'NO';
found again
case(check_if_unique('category_seftitle', $seftitle, $id)): echo notification(1,l('err_SEFExists').l('errNote')); form_categories(); break;
case(cleancheckSEF($seftitle) == 'notok'): echo notification(1,l('err_SEFIllegal').l('errNote')); form_categories(); break;
default:
switch(true) {
case(isset($_POST['add_category'])):
Add red lines
default:
switch(true) {
case(isset($_POST['add_category'])):
mysql_query("INSERT INTO ".db('prefix')."categories(name, seftitle, description, published, catnumber, showcount, showsitemap) VALUES('$name', '$seftitle', '$description', '$publish_category', '$catnumber', '$showcount', '$showsitemap')");
break;
case(isset($_POST['edit_category'])):
mysql_query("UPDATE ".db('prefix')."categories SET name = '$name', seftitle = '$seftitle', description = '$description', published = '$publish_category', catnumber ='$catnumber', showcount = '$showcount', showsitemap ='$showsitemap' WHERE id = $id LIMIT 1;");
break;
case(isset($_POST['delete_category'])):
mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
break;
}
Dont forget to add in language section$l['cat_num'] = 'Category Area';
$l['show_count'] = 'Count articles on category';
$l['show_sitemap'] = 'Show in Sitemap';
$l['no_categories'] = 'No categories at the moment';
How can you use it ?In your index.php or calling function
Sintax: <?php categories(Area, home, count, start, size); ?> Area - category number
home - show(true) or hide (false)
count (articles) - show(true) or hide (false)
start - start article
size - how many articles you want to show
You can use (examples) <?php categories(); ?> - this call categories Position=0, show home, and count articles
<?php categories(1); ?> - this call categories Position=1, show home and count articles
<?php categories(1,'false'); ?> - this call categories Position=1, dont show home and count categories
<?php categories(2,'false','false'); ?> - this call categories Position=2 hide home and not count categories
<?php categories(10,'false','false',1,3); ?> - this call categories Position=10 hide home and not count categories, show categories 1 to 3 from that area
Complicated ?You can Download
Here (
don't forget to add purple text in categories function.)
Best reagards
Rui Mendes