Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2

Author Topic: [MOD] Article list under Categories (sNews 1.5)  (Read 16570 times)

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Article list under Categories (sNews 1.5)
« on: December 10, 2006, 08:57:09 PM »

MOD version 1.010
Rectified IE rendering concern -- see below.
To keep this thread clear, any error related issues, please post in the original dev post
http://www.snewscms.com/forum/index.php?topic=2460


Aim is to have categories display articles as a submenu or list.
Also to toggle category to allow expansion/collapsing of categories, to prevent excessively long lists.
Articles sorted in the list, by date -- latest first.



If you have this in your index.php
Code: [Select]
<ul>
<?php categories(); ?>
</ul>
remove the <ul> and </ul> tags. They are included inside the function.

replacement categories() function
Comment out the current  categories() function, paste this below it. If you then don't want/like it, you only have to delete this, and uncomment the original.
Code: [Select]
// DISPLAY expanded CATEGORIES (with toggle, set cat link, set home link)
function categories() {
    $linkingSwitch=0;  // set to 1 to make category name act as a link to the category page.
    $showHomeAsCAT=1; // set to 0 to omit the Home link.
    if (!isset($_SESSION[db('website').'Logged_In'])){jsuser();}
    $categorySEF = get_id('category');
    $divset="expanda".$categorySEF;
    $class = $category_title == $categorySEF ? ' class="current"' : '';
    echo "<!-- start category listing -->\r\n".'<ul class="expandacat">';
    /* *** 'HOME' IS A PAGE NOT A CATEGORY! *** */
    if($showHomeAsCAT==1){  echo '<li class="expandacat">'."\r\n".'<a'.$class.' href="'.db('website').'" title="'.s('website_title').'">'.l('home').'</a>'."\r\n".'</li>'."\r\n";    }
    /* ^^^^^  BUT HERE IT IS ANYWAY  ^^^^^ */
    $query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder ASC";
    $result = mysql_query($query);
    while ($r = mysql_fetch_array($result)) {
        $calc_num_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND category = $r[id] AND published = '1' ORDER BY date DESC";
        $cm_result = mysql_query($calc_num_query);
        $num_rows = mysql_num_rows($cm_result);
        if (($num_rows == 0 && isset($_SESSION[db('website').'Logged_In'])) || $num_rows > 0) {
            $category_title = $r['seftitle'];
            $divid="expanda".$category_title;
            $class = $category_title == $categorySEF ? ' class="current"' : '';
            $echo= '<li class="expandacat">'."\r\n".'<a'.$class.' style="cursor:pointer;" title="'.$r['description'].'" onclick="toggle(\''.$divid.'\')"';
            if ($linkingSwitch == 1){$echo.=' href="'.db('website').$r['seftitle'].'/" title="'.$r['description'].'"';}
            $echo.='>'.$r['name'];
            $echo.= (s('num_categories') == 'on' ? ' ('.$num_rows.')' : '').'</a>'."\r\n";
            $echo.='<ul id="'.$divid. '" class="expandaArticles"  style="';
            if ($divid!==$divset){$echo.='display:none;';}
            $echo.='" >'."\r\n";
        while ($art = mysql_fetch_array($cm_result)) {
            $echo.= '<li><a href="'.db('website').$category_title.'/'.$art['seftitle'].'/" title="'.$art['title'].'">'.$art['title'].'</a></li>'."\r\n";           }
           echo $echo."</ul></li>\r\n";        }
   }
           echo "</ul>\r\n \r\n <!-- end category listing -->";
}
toggle jsuser() function
place this after the last php closing tag ( ?> ) in snews.php
Code: [Select]
<?php
// user javascript -- toggle
function jsuser() { ?>

<script type="text/javascript">
//<![CDATA[
// toggle dynamic divs
function toggle(div) {
if (document.getElementById(div).style.display=='') {
document.getElementById(div).style.display = 'none';
return
} document.getElementById(div).style.display = '';
}
//]]>
</script>
<?php }?>
styles used in testing
Styles used to test. Place these in your style.css , and adjust as you see fit.
Code: [Select]
/* snews cat mod */
.expandacat { border: 0px solid #ccc; padding: 0px 0px; margin: 0 0 0px 0; background: #fff; color: #0066B3; text-decoration:underline; }
.expandaArticles {border: 0px solid #ccc;padding: 0px 2px; margin: 0 0 10px 10px; color: #000; font-size:85%; line-height:1.3em; text-decoration:none;}
/*////////////////*/

$linkingSwitch=1; ==> turns on the link for the category, meaning that if category title is clicked, it will both toggle the underlying article list AND take you to the category page. The article list remains open while on the category page!!!
$linkingSwitch=0 ==> unlink category titles, making it ONLY toggle the article list inside.The article list remains open while  browsing articles in that category!!!

Switch to turn on/off display of home link in the menu listing.
$showHomeAsCAT=1  ===> Home displays above the categories.
$showHomeAsCAT=0 ===> Home is remove from the generated list.


UPDATES
version 1.010 :~IE6 was rendering the listing wider spaced than FF or Opera.
Removed <div>. Nested second level <ul> into the category <li> to give output <li>category<ul><li>article1</li><li>article2</li></ul></li>
Validated source at http://validator.w3.org/ -- passed!!
Many thanks to Harold for his persistance in testing and chasing this 'bug'

Added further instructions to this post.
version 1.002 :~ Added omitted <li> tags around the expanding div. History
version 1.001 :~ wrapped the call for jsuser() function to prevent being called when logged in. When logged in, the default snews javascript is called, and the toggle function is in there... (where did you think I snaffled it from ... eh??) :D
« Last Edit: September 23, 2007, 01:39:29 AM by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
[MOD] Article list under Categories (sNews 1.5)
« Reply #1 on: December 10, 2006, 11:18:42 PM »

Woah Phil, I haven't tried it out yet, but  this look very very good. Thanks :)
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

fshagan

  • Guest
[MOD] Article list under Categories (sNews 1.5)
« Reply #2 on: December 14, 2006, 05:54:45 AM »

Very nice!  I'm making some kind of mistake, though, as I have sNews 1.5 installed and working, but whenever I add code that includes a call to the database like in this mod (specifically this line):

Code: [Select]
if (!isset($_SESSION[db('website').'Logged_In'])){jsuser();}I get a dreaded "Fatal error: Call to undefined function: db() in /snews.php on line 497" (there's a path in there before the "/snews.php", and it is correct).  Its strange because "db" is called earlier in snews.php, and I am connecting to the database and not having any errors unless I add this or any other mod.  I'm sure its on my end, but anyone have any ideas?
Logged

3Pinter

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 61
    • Fromthemill.nl
[MOD] Article list under Categories (sNews 1.5)
« Reply #3 on: December 24, 2006, 10:16:34 AM »

philmoz,

A supreme addon this is exactly what I was missing. However, I was wondering that perhaps

Code: [Select]
$class = $category_title == $categorySEF ? ' class="current"' : '';should get an extra variable... or at least define a new variable which adds a "current" class to the nested listed items.
Doing so it nicely shows the visitors path.

Anyway of doing this?

I tried it but failed (I'm making some progress however sometimes I really get stuck)

My thoughts:
Code: [Select]
$articleSEF = get_id('article'); // write the current article as variable;
$article_title = $art['seftitle']; // declare a value for the active article;
$sub_class = $article_title == $articleSEF ? ' class="current"' : ''; //create a new var for the sub linking class;

//add '.$sub_class.' to the sub_linking:

while ($art = mysql_fetch_array($cm_result)) {
            $echo.= '<li><a href="'.db('website').$category_title.'/'.$art['seftitle'].'/" '.$sub_class.' title="'.$art['title'].'">'.$art['title'].'</a></li>'."\r\n"; }
However this isn't working... maybe somebody could help me with it

3Pinter :/
« Last Edit: September 23, 2007, 01:29:43 AM by philmoz »
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Article list under Categories (sNews 1.5)
« Reply #4 on: December 24, 2006, 05:09:41 PM »

Quote from: 3Pinter
Anyway of doing this?
Yes!!

Oh I'm feeling so clever tonight (mainly because I had to spend 3 hrs on this t get it to work correctly)  :|

You were on the right track, just a matter of putting it all in the right places ;)

find
Code: [Select]
   $categorySEF = get_id('category');and put this just below it.
Code: [Select]
   $articleSEF = get_id('article');then replace the while statement towards the end
Code: [Select]
       while ($art = mysql_fetch_array($cm_result)) {
            $echo.= '<li><a href="'.db('website').$category_title.'/'.$art['seftitle'].'/" title="'.$art['title'].'">'.$art['title'].'</a></li>'."\r\n";           }
with this.
Code: [Select]
       while ($art = mysql_fetch_array($cm_result)) {
            $sub_class = $art['seftitle'] == $articleSEF ? ' class="sub_current"' : '';
            $echo.= '<li '.$sub_class.' ><a href="'.db('website').$category_title.'/'.$art['seftitle'].'/" title="'.$art['title'].'">'.$art['title'].'</a></li>'."\r\n";
                   }
then, add styles, and stir.


**I have it entering the class  .sub_current into the <li>.
styles used for testing
Code: [Select]
.current {color:blue;}
.sub_current {background-color:#cfd;}
.sub_current a {color:navy;}
Hope this is what you were after ;)

« Last Edit: September 23, 2007, 01:35:00 AM by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

3Pinter

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 61
    • Fromthemill.nl
[MOD] Article list under Categories (sNews 1.5)
« Reply #5 on: December 24, 2006, 07:14:02 PM »

Philmoz,

I second your opinion! clever one!

Indeed what I was looking for!
Thanks,
I was quite closing to the solution though... maybe next time
...

3Pinter  :/

3Pinter

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 61
    • Fromthemill.nl
[MOD] Article list under Categories (sNews 1.5)
« Reply #6 on: December 26, 2006, 12:28:59 PM »

Philips,

I noticed that FF using Firebug, came back with an error.
Quote
toggle is not defined
I know nothing about java(script) so I can't fix it maybe you can?


Secondly.
I noticed that your javascript already is implemented in sNews? (line 1799) So is it still necessary?

3Pinter

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Article list under Categories (sNews 1.5)
« Reply #7 on: December 26, 2006, 01:25:26 PM »

firebug? will have to look into that.
The function jsuser() is essentially the same script you find in the base snews.php, with the one exception. The js in snews, is only called when you are logged in, which means that visitors do not then have access to the toggle script to be able to view your underlying article list.
Logged
Of all the things I have lost, it is my mind that I miss the most.

3Pinter

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 61
    • Fromthemill.nl
[MOD] Article list under Categories (sNews 1.5)
« Reply #8 on: December 27, 2006, 12:56:18 PM »

Philmoz, and others of course,

Hmzzz. I disabled javascript to check my site's functionality and I noticed that your piece of nifty coding has no 'backup plan'.... In case someone turned off javascript (like search engines do). Is there a way of creating this backup plan?

Thinking out loud: if (javascript disabled){ show categories and sub articles to; //full tree}

No personal offence, I really appreciate your work so far !!

3Pinter  :/

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] Article list under Categories (sNews 1.5)
« Reply #9 on: February 02, 2007, 01:59:24 PM »

Philly my man... Freaking great modification. Thanks ;)
Logged
"It's only dead fish that goes with the flow... "
Updated

Pali

  • Full Member
  • ***
  • Karma: 16
  • Posts: 111
    • LE-PAVON
[MOD] Article list under Categories (sNews 1.5)
« Reply #10 on: February 05, 2007, 10:03:08 AM »

3Pinter...

there is no backup plan if you set $linkingSwitch=0; and JS is off, but you can replace line 24 with this:

Code: [Select]
           $echo= '<li class="expandacat">'."\r\n".'<a'.$class.' style="cursor:pointer;" href="'.db('website').$r['seftitle'].'/" title="'.$r['description'].'" onclick="toggle(\''.$divid.'\');return false;"';...and it should work....

Time, ohh time... If I get you I will rework this great mod for working with dropdown menu like on my site (currently static) but has similar syntax

<ul>
<li>
<ul><li></li>...</ul>
</li>
</ul>
« Last Edit: September 23, 2007, 01:30:51 AM by philmoz »
Logged
I like sNews!

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] Article list under Categories (sNews 1.5)
« Reply #11 on: February 19, 2007, 07:04:00 PM »

Now... Oniip. Is that menu of yours this mod ?? And how did you manage to get it like that in such case...
Logged
"It's only dead fish that goes with the flow... "
Updated

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Article list under Categories (sNews 1.5)
« Reply #12 on: February 19, 2007, 07:22:59 PM »

yes... good Q.
Would like to know also...
Logged
Of all the things I have lost, it is my mind that I miss the most.

Pali

  • Full Member
  • ***
  • Karma: 16
  • Posts: 111
    • LE-PAVON
[MOD] Article list under Categories (sNews 1.5)
« Reply #13 on: February 19, 2007, 07:32:35 PM »

I will make some manual soon. Currently it is not fully dynamic (some parts are static) but I think I can do it fully dynamic.
Logged
I like sNews!

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
[MOD] Article list under Categories (sNews 1.5)
« Reply #14 on: February 19, 2007, 07:44:50 PM »

Let the modding continue! :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: [1] 2