Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 5

Author Topic: [MOD_HELP] sub categories  (Read 33758 times)

heathrowintl

  • Newbie
  • *
  • Karma: 0
  • Posts: 25
[MOD_HELP] sub categories
« on: July 04, 2006, 11:47:58 AM »

hi people. ive been trying to build a website for someone and they NEED sub categories. and snews1.4 doesn't have them automatically, but i refuse to use anything else. snews is just to good! there has been a few posts on sub cats, but not any code posted. so here is my sub categories mod. i think it allows a 1 tier sub category (no subcategories of subcategories, but im sure this is an easy mod of this).

im relatively new to php, so im sure my bits are poorly coded. and full of bugs and needs testing by others. but if anyone/everyone can improve it and post it. very much appreciated.

i'll try and explain where the code bits go, but it probably won't make sense.

TODO (need help)
+ the archive page doesn't list them USEFULLY
+ when you edit a sub category, i haven't got it to remember which category it was in.
+ (edited after), just thought it doesn't yet list sub categories of a category when you click a category.


// FIRSTLY
modify (sql alter) the categories table, adding a column called 'subcatof' which is int(8) and default value '0' not null. easily done with phpmyadmin.


// administration language variable

Code: [Select]
$l['subcategory'] = "Sub Category of";// display categories -- LINE 478
REPLACE THIS
    
Code: [Select]
$query = "SELECT * FROM " .s('prefix'). "categories WHERE published = 'YES' ORDER BY id";WITH THIS
    
Code: [Select]
$query = "SELECT * FROM " .s('prefix'). "categories WHERE published = 'YES' AND subcatof = 0 ORDER BY id";the modified display categories. commented (slightly)
Code: [Select]
// DISPLAY CATEGORIES
function categories() {
echo "<ul>";
echo "<li><a href='". s('website'). "' title='" .s('website_title'). "'>". l('home') ."</a></li>";

# display categories, but do not display sub-cats
$query = "SELECT * FROM " .s('prefix'). "categories WHERE published = 'YES' AND subcatof = 0 ORDER BY id";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$calc_num_query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 AND category = $r[id]";
$cm_result = mysql_query($calc_num_query);
$num_rows = mysql_num_rows($cm_result);
$category_title = $r['seftitle'];
if (s('display_num_categories') == True)
{
echo "<li><a href='" .s('website').$category_title. "/' title='". $r['description'] ."'>" .$r['name']. " (" .$num_rows. ") </a></li>";

# display sub categories of the current category
disp_subcat($r['id']);
}
else
{ echo "<li><a href='" .s('website').$category_title. "/' title='". $r['description'] ."'>" .$r['name']. "</a></li>";

# display sub categories of the current category
disp_subcat($r['id']);
}}
echo "</ul>";
}
// display sub categories function... called by display categories
Code: [Select]
#display sub categories
function disp_subcat($var) {
echo "<ul>";
$query = "SELECT * FROM " .s('prefix'). "categories WHERE published = 'YES' AND subcatof = " . $var;
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$calc_num_query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 AND category = " . $var;
$cm_result = mysql_query($calc_num_query);
$num_rows = mysql_num_rows($cm_result);
$category_title = $r['seftitle'];
if (s('display_num_categories') == True)
{
echo "<li><a href='" .s('website').$category_title. "/' title='". $r['description'] ."'>" .$r['name']. " (" .$num_rows. ") </a></li>";}
else
{ echo "<li><a href='" .s('website').$category_title. "/' title='". $r['description'] ."'>" .$r['name']. "</a></li>"; }}


echo "</ul>";
}
modifed view_categories(), the change is commented.

Code: [Select]
function view_categories() { ?>
<h2><? echo l(categories); ?></h2>
<p>Home</p> <?
$query = "SELECT * FROM " .s('prefix'). "categories ORDER BY id";
$result = mysql_query($query);
   while ($r = mysql_fetch_array($result)) {
     if (isset($_SESSION['Logged_In'])) { echo "<p>". $r['name'] ." <img src='" .s('website'). "images/arrow.gif' alt='|' /> <a title='". $r['description'] ."' href='" .s('website'). "index.php?action=editcategory&id=$r[id]'>". l(edit_category) ."</a> <img src='" .s('website'). "images/arrow.gif' alt='|' /> <a href='" .s('website'). "index.php?action=process&task=deletecategory&id=$r[id]'".if_javascript_on(" onclick='return confirm(\"".l('warning_delete')."\");'",'return').">". l(delete_category) ."</a> <img src='" .s('website'). "images/arrow.gif' alt='|' /> ";
     if ($r['published'] == "YES") { echo l('published'); } else { echo l('unpublished'); }}
echo "</p>";
     }
echo "
"; ?>
    <fieldset>
<legend><? echo l('add_category'); ?></legend>
<form name="post-text" method="post" action="">
     <p><? echo l('name'); ?>:</p>
       <p><input type="text" value="<? echo $_POST['name']; ?>" id="article_title" class="field" name="name" /><?php if_javascript_on(' <a href="javascript:makesef();">'.l('make_sef_text').'</a>'); ?></p>
       <p><? echo l('sef_title_cat'); ?>:</p>
     <p><input type="text" name="seftitle" value="<? if ($_POST['name'] == '') { echo cleanSEF($_POST['name']); } else { echo cleanSEF($_POST['seftitle']); }; ?>" id="article_sef" class="field" /></p>
      
       <p><? echo l('description'); ?>:</p>
       <p><input type="text" class="field" name="description" /></p>

<? # SUB CAT MOD?>
<p><? echo l('subcategory'); ?>:</p>
<p><select name="subcat"><? category_list(); ?>
<option value="0" selected="selected">not a sub category</option></select></p>


<p><input type="checkbox" value="YES" name="publish" checked> <? echo l('publish_category'); ?></p>
       <p><input type="hidden" name="task" value="add_category" /></p>
     <p><input type="submit" name="submit_text" value="<? echo l(add_category); ?>" /></p>
     </form>
     </fieldset><?
}
function to list categories that can be selected as a subcat

Code: [Select]
# LISTS CATEGORIES...specifically SUB CATEGORIES
function category_list($var) {
if(isset($var))
{
$query = "SELECT * FROM " .s('prefix'). "categories WHERE subcatof = 0 AND id <> " . $var;
}
else
{
$query = "SELECT * FROM " .s('prefix'). "categories WHERE subcatof = 0";
}
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo "<option value=\"" . $r['id'] . "\">" . $r['name'] . "</option>";
}
}
modifed EDIT categories

Code: [Select]
//***************
// EDIT CATEGORY
//***************
function edit_category() { ?>
<h2><? echo l('edit_category') ?></h2><?
$categoryid = $_GET['id'];
$query = "SELECT * FROM " .s('prefix'). "categories WHERE id = $categoryid";
$result = mysql_query($query);
   while ($r = mysql_fetch_array($result)) {
     if (isset($_SESSION['Logged_In'])) {
    echo "<p>". $r['name'] ." <img src='" .s('website'). "images/arrow.gif' alt='|' /> <a href='index.php?action=process&task=deletecategory&id=$r[id]'".if_javascript_on(" onclick='return confirm(\"".l('warning_delete')."\");'",'return').">". l(delete_category) ."</a> <img src='" .s('website'). "images/arrow.gif' alt='|' /> ";
     if ($r['published'] == "YES") { echo l('published'); } else { echo l('unpublished'); }
echo "</p>"; }
     echo "
"; ?>
     <fieldset>
<legend><? echo l('edit_category'); ?></legend>
    <form name="post-text" method="post" action="index.php?action=process&task=edit_category">
     <p><? echo l('name'); ?>:</p>
     <p><input type="text" class="field" value="<?php echo $r['name']; ?>" id="article_title" name="name" /><?php if_javascript_on(' <a href="javascript:makesef();">'.l('make_sef_text').'</a>'); ?></p>
     <p><? echo l('sef_title_cat'); ?>:</p>
     <p><input type="text" class="field" value="<?php echo $r['seftitle']; ?>" id="article_sef" name="seftitle" /></p>
     <p><? echo l('description'); ?>:</p>
     <p><input type="text" class="field" value="<?php echo $r['description']; ?>" name="description" />
</p>

<? #sub cat mod ?>
<p><? echo l('subcategory'); ?>:</p>
<p><select name="subcat">
<? category_list($r['id']); ?>
<option value="0" selected="selected">not a sub category</option></select></p>

<? if ($r['published'] == "YES") { ?>
      <p><input type="checkbox" value="YES" name="publish" checked /> <? echo l('publish_category'); ?></p><?
       } else { ?>
      <p><input type="checkbox" value="YES" name="publish" /> <? echo l('publish_category'); ?></p>
      <? } ?>
      <p><input type="hidden" name="id" value="<?php echo $categoryid?>" /></p>
      <p><input type="hidden" name="task" value="edit_category" /></p>
      <p><input type="submit" name="submit_text" value="<? echo l('edit_category'); ?>" /></p>
     </form>
       </fieldset>
       <? }
}
now for changes in the PROCESSING (CAT, ART, COM)

add a post variable
Code: [Select]
$subcat = $_POST['subcat'];final bit...(finally)
modify the INSERT and UPDATE statements...so the changes actually happen in the database!

original line 1470 INSERT statement
Code: [Select]
mysql_query("INSERT INTO ". s('prefix'). "categories(name,seftitle,description,published) VALUES('$name', '$seftitle', '$description', '$publish_category')");becomes

Code: [Select]
mysql_query("INSERT INTO ". s('prefix'). "categories(name,seftitle,description,published,subcatof) VALUES('$name', '$seftitle', '$description', '$publish_category', '$subcat')");AND

this update statement must be added somewhere around original line 1497
Code: [Select]
mysql_query("UPDATE ". s('prefix'). "categories SET subcatof='$subcat' WHERE id='$id'");i think thats it. i can easily supply more code...or the whole snews file.
thanks for reading this. i really apreciate it!
« Last Edit: September 24, 2007, 01:34:19 AM by philmoz »
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD_HELP] sub categories
« Reply #1 on: July 04, 2006, 11:56:40 AM »

wowsa... Your seven'th post is this, hehe...what will the future hold ? Great, Heath. I'm not able to look at code or even test it at this point in time, as I'm worse than everybody at PHP ;).

I will however subscribe to this thread as it is something that would like to be developed, and possibly use in the future. I'm there for you when it comes to beta testing, just give me a hollar.

Patric.
Logged
"It's only dead fish that goes with the flow... "
Updated

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD_HELP] sub categories
« Reply #2 on: July 04, 2006, 12:03:07 PM »

nice job, heathrowintl ;)

a few notes:
- you could supply us with the full sql statement (it's easier to copy/paste, especially for those who aren't very good at coding)
- i've already seen a couple of snipets of that sort, and this is a shorter one...
- important: calling sql within loop is usually a bad idea (multiple sql calls are significantly slowing down db server), but as long as there are not many subcaterories, everything will work fine

(i will test it later today ;) )
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

heathrowintl

  • Newbie
  • *
  • Karma: 0
  • Posts: 25
[MOD_HELP] sub categories
« Reply #3 on: July 04, 2006, 12:14:24 PM »

i used phpmyadmin, so it was a piece of cake. but the following command should work
Code: [Select]
ALTER TABLE categories ADD COLUMN subcatof INT(8) NOT NULL DEFAULT 0
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD_HELP] sub categories
« Reply #4 on: July 04, 2006, 05:28:10 PM »

heathrowintl, i'm up to my neck in your mod :D

try this function instead of yours, and tell me what you think of it...

Quote
# LISTS CATEGORIES...specifically SUB CATEGORIES
function category_list($var) {
   $query = 'SELECT * FROM '.s('prefix').'categories WHERE subcatof = 0';
   isset($var) ? $query .= ' AND id <> $var' : $query .= '';
   $result = mysql_query($query);
   echo '<option value="0"';
   !isset($var) ? print ' selected="selected">' : print '>';
   echo 'not a sub category</option>';

   while ($r = mysql_fetch_array($result)) {
      echo '<option value="'.$r['id'].'"';
      isset($var) ? print ' selected="selected">' : print '>';
      echo $r['name'].'</option>';
   }
}
note: before you try it, remove this from your mod (2 occurrences):
Quote
<option value="0" selected="selected">not a sub category</option>
« Last Edit: September 24, 2007, 01:34:42 AM by philmoz »
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD_HELP] sub categories
« Reply #5 on: July 04, 2006, 09:43:54 PM »

okay, mate - got it up and running smoothly... but you need to provide a brand new navigation system layout for it... css will be highly appreciated ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

adisnoop

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
[MOD_HELP] sub categories
« Reply #6 on: August 27, 2006, 06:05:39 PM »

I am sort off newbie in php could someone supply the whole Snews file?

Could that be possible

Thanx in advance

Adi
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD_HELP] sub categories
« Reply #7 on: August 27, 2006, 07:33:22 PM »

You could just download it from the Solucija.com site: http://www.solucija.com/home/snews/ All you need is there...
Logged
"It's only dead fish that goes with the flow... "
Updated

adisnoop

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
[MOD_HELP] sub categories
« Reply #8 on: September 01, 2006, 10:28:47 PM »

I mean with this mod installed:)
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD_HELP] sub categories
« Reply #9 on: September 02, 2006, 06:37:18 AM »

this mod is still under construction, adisnoop. please contact heathrowintl for more info
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

tobto

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 71
    • seo service
[MOD_HELP] sub categories
« Reply #10 on: November 09, 2006, 09:11:52 AM »

hi guys!
I'm very interested into subcategories future. With this MOD Snews will be a bomb!!
Could you tell me, pls, what goes on with that MOD? Are there modified snews.php ?
Thanks to all!
Logged

mininovax

  • Newbie
  • *
  • Karma: 1
  • Posts: 44
    • http://www.ondapc.net
[MOD_HELP] sub categories
« Reply #11 on: November 10, 2006, 07:26:50 PM »

this does not work with 1.5.

I would suggest using the extra() functions for each individual category if you want a subcategory

2 boxes - 1 = Categories and the other subcategories

If you click on

category 1 - extra () links to category 1
category 2 - extra () links to category 2
...

just my 2 cents
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD_HELP] sub categories
« Reply #12 on: November 11, 2006, 12:46:01 AM »

Quote from: tobto
hi guys!
I'm very interested into subcategories future. With this MOD Snews will be a bomb!!
Could you tell me, pls, what goes on with that MOD? Are there modified snews.php ?
Thanks to all!
MODS are alterations to the base application that someone has developed in order to extend sNews for their use.

Essentially, sNews is just the core, and everyone takes it in their own direction.
No-one is locked into "the way someoneelse thinks it should be".

What Mika, Luka, others on the team have provided is a product that you can extend in the way "you think things should be"

As such, you will have to want to play with code, to develop/troubleshoot in order to achieve.


Some people have modified sNews for download.
Logged
Of all the things I have lost, it is my mind that I miss the most.

dracko

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 57
    • http://www.gritala.com
[MOD_HELP] sub categories
« Reply #13 on: November 13, 2006, 05:31:45 AM »

can somebody help into creating a mod for 1.5rc3? i need this feature.. hope someone may have some free time, ty in advace  :D
Logged

bionicman

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 51
[MOD_HELP] sub categories
« Reply #14 on: November 15, 2006, 02:18:35 PM »

Hey guys, this topic is dying :(

It's very useful mod, many of us needs it. I don't know PHP in such level to help heathrowintl ending this mod. Anyone volunteer?  :rolleyes:
Logged
Pages: [1] 2 3 ... 5