Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] Category Options  (Read 4043 times)

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
[MOD] Category Options
« on: November 11, 2007, 01:01:51 AM »

This mod allows you to add some text (any html including images etc.) at the top of a category page and also allows you the option to display some categories as lists of articles rather than a blog type layout. The "display info line" option is set for an entire category rather than for each individual article.

Step 1: Backup

Three new tables in the categories column are needed:
Code: [Select]
ALTER TABLE categories ADD text TEXT;
ALTER TABLE categories ADD displayinfo CHAR(3);
ALTER TABLE categories ADD displayaslist CHAR(3);

In language variables add:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
$l['displayaslist'] = 'Under the category only show a list of the articles';
// END MOD CATEGORY OPTIONS

In function center()

Under:
Code: [Select]
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";Add:        
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS

$query_category = "SELECT text, displayinfo, displayaslist FROM categories WHERE id = $use_cat_id";
$result_category = mysql_query($query_category);
$numrows_category = mysql_num_rows($result_category);
$edit_link = '<a href="'.db('website').'index.php?action=admin_category&id='.$use_cat_id.'" title="'.l('edit').' '.$title.'">'.l('edit').'</a>';

while ($r = mysql_fetch_array($result_category)) {
if ($r['displayinfo'] == 'YES') {$infoline = true;}
if (!empty($r['text'])) {$category_text = $r['text'];}

if (($r['displayaslist'] == 'YES') && (!empty($currentPage) || empty($article))) {
$list_articles = true;
$article_limit = 100;
}
else {$list_articles = false;}

}
// END MOD CATEGORY OPTIONS

Under:
Code: [Select]
if (!$result || !$numrows) {echo $title_not_found;}
else {
Add:   
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
if (!empty($currentPage)) {
echo $category_text;

if ($_SESSION[db('website').'Logged_In'] == token()) {
echo '<p>'.$edit_link.'</p>';
}
}
if ($list_articles) {
echo '<ul>';
}
// END MOD CATEGORY OPTIONS

Comment out this line:
Code: [Select]
// $infoline = $r['displayinfo'] == 'YES' ? true : false;
Change this:
Code: [Select]
if ($r['displaytitle'] == 'YES') {echo '<h2>'.(strlen($text) > $shorten ? $link.$category.'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a>' : $title).'</h2>';}
file_include(str_replace('[break]', '', $text), $shorten);

To:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
if ($list_articles) {
echo '<li><h4>'.$link.$category.'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a></h4></li>';
}
else {
// END MOD CATEGORY OPTIONS
if ($r['displaytitle'] == 'YES') {echo '<h2>'.(strlen($text) > $shorten ? $link.$category.'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a>' : $title).'</h2>';}
file_include(str_replace('[break]', '', $text), $shorten);
// BEGIN MOD CATEGORY OPTIONS
}
// END MOD CATEGORY OPTIONS

Change this:
Code: [Select]
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> ';
break;
To this:
Code: [Select]
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
// BEGIN MOD CATEGORY OPTIONS
// echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> ';
if (!$list_articles) {
echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> ';
}
// END MOD CATEGORY OPTIONS
break;

Just before this (after the closing curly bracket in the line above):
Code: [Select]
if (!empty($currentPage) && ($numrows_articles > $article_limit) && s('display_pagination') == 'on') {Add this:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
if ($list_articles) {
echo '</ul>';
}
// END MOD CATEGORY OPTIONS

In function form_categories()

Under:
Code: [Select]
if (isset($_GET['id']) && is_numeric($_GET['id']) && !is_null($_GET['id'])) {Add:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
$frm_text = str_replace('&', '&amp;', $_SESSION['temp']['text'] ? $_SESSION['temp']['text'] : $r['text']);
$frm_display_info = $r['displayinfo'] == 'YES' ? 'ok' : '';
$frm_displayaslist = $r['displayaslist'] == 'YES' ? 'ok' : '';
// END MOD CATEGORY OPTIONS

Under:
Code: [Select]
else {Add:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
$frm_text = $_SESSION['temp']['text'];
$frm_display_info = 'ok';
$frm_displayaslist = '';
// END MOD CATEGORY OPTIONS

Under:
Code: [Select]
echo html_input('text', 'description', 'desc', $frm_description, l('description'), '', '', '', '', '', '', '', '', '', '');Add:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
echo html_input('textarea', 'text', 'txt', $frm_text, l('text'), '', '', '', '', '', '2', '100', '', '', '');

echo '<p>';
echo html_input('button', 'strong', '', 'B', '', 'button', 'onclick="tag(\'strong\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'em', '', 'I', '', 'button', 'onclick="tag(\'em\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'strike', '', 'Strike', '', 'button', 'onclick="tag(\'strike\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'p', '', 'P', '', 'button', 'onclick="tag(\'p\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'br', '', 'BR', '', 'button', 'onclick="tag(\'br\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'break', '', 'Break', '', 'button', 'onclick="tag(\'break\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'img', '', 'Image', '', 'button', 'onclick="tag(\'img\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'link', '', 'Link', '', 'button', 'onclick="tag(\'link\')"', '', '', '', '', '', '', '', '');
echo html_input('button', 'include', '', 'Include', '', 'button', 'onclick="tag(\'include\')"', '', '', '', '', '', '', '', '');
echo '</p>';

echo html_input('checkbox', 'display_info', 'di', 'YES', l('display_info'), '', '', '', '', $frm_display_info, '', '', '', '', '');
echo html_input('checkbox', 'displayaslist', 'dl', 'YES', l('displayaslist'), '', '', '', '', $frm_displayaslist, '', '', '', '', '');
// END MOD CATEGORY OPTIONS

In function form_articles()
Comment out:
Code: [Select]
// echo html_input('checkbox', 'display_info', 'di', 'YES', l('display_info'), '', '', '', '', $frm_display_info, '', '', '', '', '');
In function processing()
Under:
Code: [Select]
$display_info = $_POST['display_info'] == 'on' ? 'YES' : 'NO';Add:
Code: [Select]
// BEGIN MOD CATEGORY OPTIONS
$displayaslist = $_POST['displayaslist'] == 'on' ? 'YES' : 'NO';
// END MOD CATEGORY OPTIONS

And change this:
Code: [Select]
switch(true) {
case(isset($_POST['add_category'])):
mysql_query("INSERT INTO ".db('prefix')."categories(name, seftitle, description, published) VALUES('$name', '$seftitle', '$description', '$publish_category')");
break;
case(isset($_POST['edit_category'])):
mysql_query("UPDATE ".db('prefix')."categories SET name = '$name', seftitle = '$seftitle', description = '$description', published = '$publish_category' WHERE id = $id LIMIT 1;");
break;
case(isset($_POST['delete_category'])):
mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
break;
}
To this:
Code: [Select]
switch(true) {
case(isset($_POST['add_category'])):
// MODIFIED FOR MOD CATEGORY OPTIONS
mysql_query("INSERT INTO ".db('prefix')."categories(name, seftitle, description, published, text, displayinfo, displayaslist) VALUES('$name', '$seftitle', '$description', '$publish_category', '$text', '$display_info', '$displayaslist')");
break;
case(isset($_POST['edit_category'])):
// MODIFIED FOR MOD CATEGORY OPTIONS
mysql_query("UPDATE ".db('prefix')."categories SET name = '$name', seftitle = '$seftitle', description = '$description', published = '$publish_category', text = '$text', displayinfo = '$display_info', displayaslist = '$displayaslist' WHERE id = $id LIMIT 1;");
break;
case(isset($_POST['delete_category'])):
mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
break;
}
« Last Edit: November 11, 2007, 01:43:46 AM by ad_267 »
Logged

Rui Mendes

  • Development,Testing, Support
  • sNews Dude
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1063
  • sNews1.80 Reborn
    • Comunidade Portuguesa
Re: [MOD] Category Options
« Reply #1 on: November 11, 2007, 01:14:22 AM »

Hello ad_267, thank you for sharing.

Did you have a Demo?
Logged
Need a Job on Europe. Linkdin - Facebook / Group

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
Re: [MOD] Category Options
« Reply #2 on: November 11, 2007, 01:51:38 AM »

No I don't have a demo sorry.
I attached a screen shot of what a category looks like with the articles as a list and the text at the top from my local installation:
Logged

Rui Mendes

  • Development,Testing, Support
  • sNews Dude
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1063
  • sNews1.80 Reborn
    • Comunidade Portuguesa
Re: [MOD] Category Options
« Reply #3 on: November 11, 2007, 02:08:59 PM »

Good ideia, congratulations mate.

Well done.
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6290
  • Semantically Challenged
    • snews.ca
Re: [MOD] Category Options
« Reply #4 on: November 15, 2007, 05:47:57 PM »

Quick question... does the categories function continue to operate normally in the side-bar... and provide the articles list for a given category only at the top of the category page?
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
Re: [MOD] Category Options
« Reply #5 on: November 16, 2007, 06:35:22 AM »

Quick question... does the categories function continue to operate normally in the side-bar... and provide the articles list for a given category only at the top of the category page?

Yes the category function operates as usual. The long category description and list of articles is only shown on that category page (all modifications are to the center function and the admin area).
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6290
  • Semantically Challenged
    • snews.ca
Re: [MOD] Category Options
« Reply #6 on: November 16, 2007, 01:47:41 PM »

Yes the category function operates as usual. The long category description and list of articles is only shown on that category page (all modifications are to the center function and the admin area).
OK... yesterday, after asking my question... I discovered another way of accomplishing pretty much the same result without needing any changes to the database. I installed Philmoz's Articles by Category and Insert Function mods.

The Articles by Category mod allows display of article-links for a given category by inserting the category ID number in the menu_articles function-call string in the index.php file. As an example - <?php menu_articles(0,4,'1'); ?> - the category ID of '1' is added as a 3rd parameter within the brackets... and this will display only the article-links for that category.

Using the Insert Function mod... you can then user a new Function Insert button in the Editor button set (under the textarea) to insert the above function and its parameters into an "extra" and have it display on all pages within a given category... by using the prompts to insert the function name as  - menu_articles and the parameters in the 2nd prompt as 0,4,'1'. After inserting this into the "extra" and assigning it to the category pages for that category... the article-link list then displays in the extra position (side-bar) for all of that category's pages.

[Added:] I just gave Joost's Article Menu in Category mod a test-run and it works just as well when you insert the function-name using Philmoz's Insert Function button. I must admit Joost's function is more convenient to use because there is no need to include any parameters... it knows which category menu to insert on its own.  :)

It is not as automatic as your method, but it does allow more flexibility in positioning.
« Last Edit: November 16, 2007, 04:25:47 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
Re: [MOD] Category Options
« Reply #7 on: November 16, 2007, 08:30:17 PM »

Ok yes that sounds like it could do the same sort of thing pretty well, the only extra thing my mod does is allows you to have some text associated with a category and displayed at the top of the category page. I intended this mod to be aimed towards people who wanted to use sNews as more of a normal CMS where articles would be sub pages in a category and the category page just lists these articles, while still being able to have some categories that were "news" type categories that showed some introduction text and a "read more" link for each article.
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6290
  • Semantically Challenged
    • snews.ca
Re: [MOD] Category Options
« Reply #8 on: November 16, 2007, 08:59:12 PM »

Ok yes that sounds like it could do the same sort of thing pretty well, the only extra thing my mod does is allows you to have some text associated with a category and displayed at the top of the category page. I intended this mod to be aimed towards people who wanted to use sNews as more of a normal CMS where articles would be sub pages in a category and the category page just lists these articles, while still being able to have some categories that were "news" type categories that showed some introduction text and a "read more" link for each article.
Thanks for the additional explanation.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU