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.

Author Topic: Articles AND PAGES assigned to Categories  (Read 4984 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Articles AND PAGES assigned to Categories
« on: March 02, 2008, 07:43:58 pm »

This Modification Sequence will display both Pages and Articles under Categories in your sNews 1.6 site using the following:
1 - Expandable Article & Page Link Admin Panels (by Philmoz) when you click on VIEW or EDIT content panels,
2 - Expandable Category title-links in the Category menu function (by Philmoz),
3 - Remove Admin-created Page-links from the default sNews Page-links function (by EQ).
4 - And... will include REVISED modifications originally posted in the Pages listed under Categories Project explored under "Exploring sNews Versatility".

It would also be useful to include J. Rivera's Article Re-ordering Modifications as well, so you can re-order the listing of both Articles and Pages in menus and Admin Panels, but I'll leave that up to you since there are several ways to make and display menu functions.

The Modification steps that follow apply to a Default sNews 1.6 package but they will also apply to Bakercad's MU package as well, provided you take care to apply them so as not to miss including MU modifications that may apply. Each modification is preceded by a comment line that will help make it easier to search for them in your snews.php file at a later date.

Add the following styles to the bottom of your style.css File:
Code: [Select]

/* snews categories function mods (Philmoz) */
.expandacat { border: 0px solid #ccc; padding: 0px 0px; margin: 0 0 0px 0; background: #fff; color: #0066B3; text-decoration: none; }
.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;}
.New_Admin_Links {font-size: 100%; text-align: center;}


In index.php: Remove the <ul - </ul> tags that wrap the <?php categories(); ?> string. They are now located in the new categories function we'll be adding soon.

All other Mods are in the snews.php file. NOTE: In each code block that follows, do not copy the PHP tags at the start and end of each block.They are only there to show the scripts in color, nothing else.

1. Add to the Language Variable Array:
Search for - #categories, and add the following under it (excluding the PHP tags) like so:
Code: [Select]
<?php

# categories
# PAGES-IN-CATS - for Philmoz's Admin Articles (and pages) listed by Category
$l['uncategorised'] = 'Uncategorised';

?>


2. Replace function categories():
Search for - // DISPLAY CATEGORIES - and comment out the whole function to disable it. (wrap it with /* at the start & */ at the end).
Copy in this NEW function to take its place, either above or below the default function (excluding the PHP tags):
Code: [Select]
<?php

# PAGES-IN-CATS (keyrocks) Mod 01
// DISPLAY expanded CATEGORIES (with toggle, set cat link, set home link) (Philmoz)
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)) {
    
# PAGES-IN-CATS (keyrocks) Mod 01
# Selects published articles & pages (position 1 & 3), descending order by date.
$calc_num_query "SELECT * FROM ".db('prefix')."articles WHERE position IN (1,3) AND category = $r[id] AND published = '1' ORDER BY date DESC";
# default string - selects published articles only (position 1), descending order by date.
        
//$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 == && 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 -->";
}

?>


3. Replace function pages():
Search for - // DISPLAY PAGES - and comment out the whole function to disable it. (wrap it with /* at the start & */ at the end).
Copy in this NEW function to take its place, either above or below the default function (excluding the PHP tags):
Code: [Select]
<?php

# PAGES-IN-CATS (keyrocks) Mod 02
// DEFAULT PAGES - sNews generated pages only, replaces default function pages (based on default_pages() by EQ)
function pages() {
$categorySEF get_id('category'); $pageSEF get_id('article'); $home l('home_sef');
$class = (empty($categorySEF) || $categorySEF == $home && empty($pageSEF)) ? ' class="current"' '';
echo '<li><a'.$class.' href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
$class = ($categorySEF == 'archive') ? ' class="current"' '';
echo '<li><a'.$class.' href="'.db('website').'archive/" title="'.l('archive').'">'.l('archive').'</a></li>';
$class = ($categorySEF == 'contact') ? ' class="current"''';
echo '<li><a'.$class.' href="'.db('website').'contact/" title="'.l('contact').'">'.l('contact').'</a></li>';
$class = ($categorySEF == 'sitemap') ? ' class="current"''';
echo '<li><a'.$class.' href="'.db('website').'sitemap/" title="'.l('sitemap').'">'.l('sitemap').'</a></li>';
}

?>


4. In // ARTICLES FORM :
A) - Search for this string - if ($contents != 'page_new' && $edit_option != 3) {.
     We need to comment it out and relocate it to another place in this function, so replace the string with:
Code: [Select]
<?php

# PAGES-IN-CATS (keyrocks) Mod 03 - Check if content is NOT a page. Relocated to # PAGE DROPDOWN
//if ($contents != 'page_new' && $edit_option != 3) {

?>


B) - About 17 lines below that, locate this string - if ($contents == 'extra_new' || $edit_option == 2) {.
     Just above it... add the following, which takes the place of the one we commented out in step A above:
Code: [Select]
<?php

# PAGES-IN-CATS Mod 04 - PAGE DROPDOWN field starts-----------
# Check if content is NOT a page.
if ($contents != 'page_new' && $edit_option != 3) {
# show Page Dropdown - visible only if adding or editing extra

?>


C) - Search for - // ARTICLES - ADMIN LIST.
     Comment out the whole function to disable it. (wrap it with /* at the start & */ at the end).
     Paste in the following new functions to replace it:
Code: [Select]
<?php

# PAGES-IN-CATS (keyrocks)
// ARTICLES - ADMIN LIST - modified (Philmoz) displays articles & pages to Admin in expandable category panels
function admin_articles($contents) { ## NOTE - DOES NOT INCLUDE MU-EXTRA MODS YET
$showAdminLinks 1;
$homel('home');
$xt=1;
$catNAMES[$xt-2] = $contents == 'extra_view' l('all') : l('uncategorised');
$catNAMES[0]= $home;
$query1 "SELECT * FROM ".db('prefix')."categories  ORDER BY id ASC";
$result1 mysql_query($query1);
while($ct mysql_fetch_array($result1)){
$catNAMES[$ct['id']]= $ct['name'];
$catSEF[$ct['id']] = $ct['seftitle'];
$xt++;
}
switch ($contents) {
# Patch/fix applied (from Patches & fixes forum)
        case 'article_view'$title l('articles'); $subquery "WHERE position < 2 AND position >-1 "; break;
        # un-patched string
//case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1"; break;
case 'extra_view'$title l('extra_contents'); $subquery "WHERE SUBSTRING(position,1,1) = '2'"; break;
case 'page_view'$title l('pages'); $subquery "WHERE position = 3"; break;
}

echo 
new_admin_links($showAdminLinks)."\n";
foreach (
$catNAMES as $catkey => $catvalue) {
$subsubQuery "AND category = $catkey ";
$query "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey ORDER BY category,date DESC";
$result mysql_query($query);
$numrows mysql_num_rows($result);
if ((!$result || !mysql_num_rows($result)) && $numrows !==0) {echo '<p>'.l('article_not_exist').'</p>';}
else {
if ($numrows) {
/*validation fix*/ $catSEF[$catkey] = $catkey==0?l('home_sef'):$catSEF[$catkey];
echo '<fieldset>'."\n".'<legend><a onclick="toggle(\''.$catSEF[$catkey].$catkey.'\')" style="cursor:pointer;" title="'.$catvalue.' '.$title.'">'.$catvalue.' '.$title.'</a>'.'</legend> '."\n";
echo '<div id="'.$catSEF[$catkey].$catkey.'" style="display:none;">'."\n";$i=0;
  
while ($r mysql_fetch_array($result)){
$articleSEF $contents != 'extra_view' $r['seftitle'].'/' '';
echo '<p><strong>'.$r['id'].' - '.$r['title'].'</strong> '.l('divider').' <a href="'.db('website').find_cat_sef($r['category']).'/'.$articleSEF.'">'.l('view').'</a> '."\n";
echo  l('divider').' <a href="'.db('website').'index.php?action=admin_article&id='.$r['id'].'">'.l('edit').'</a> '.date(s('date_format'), strtotime($r['date']));
/*altered--hidden page mod */if ($r['display_auto'] == 0){echo l('divider').l('hidden_page').l('divider');}/* shows hidden in admin*/
    
if ($r['published'] == 2) {echo  l('divider').' ['.l('status').' '.l('future_posting').']'."\n";}
if ($r['published'] == 0) {echo  l('divider').' ['.l('status').' '.l('unpublished').']'."\n";}
echo '</p>';
$i++;
}
echo '</div></fieldset>'."\n";
}}}}

// New Admin Links panel (Philmoz) displays above Article-by-category panels.
function new_admin_links($offon){
if ($offon == 1){
$divider "&nbsp;&nbsp;|&nbsp;&nbsp;";
$new_links '<fieldset class="New_Admin_Links"><span>';
$new_links .= $divider.'<a href="'.db('website').'article_new/" title="'.l('article_new').'">'.l('article_new').'</a>';
$new_links .= $divider.'<a href="'.db('website').'page_new/" title="'.l('page_new').'">'.l('page_new').'</a>';
$new_links .= $divider.'<a href="'.db('website').'extra_new/" title="'.l('extra_new').'">'.l('extra_new').'</a>';
$new_links .= $divider.'<a href="'.db('website').'admin_category/" title="'.l('add_category').'">'.l('add_category').'</a>'.$divider.'</span></fieldset>';
return $new_links;}
}

?>


D) - And... lastly... add the following javascript function to the very end of the snews.php file... after the last closing PHP tag. This time, include the PHP tags with it. It's required for Philmoz's new categories() function:
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 }?>


And that's all there is to it. You should now be able to assign Pages to Categories, and view them in your new sidebar menu generated by Philmoz's categories function.

(keys)
« Last Edit: March 06, 2008, 02:21:47 am by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Articles AND PAGES assigned to Categories
« Reply #1 on: March 02, 2008, 11:42:11 pm »

Awesome mod Doug. 
Logged

Nicu Alecu

  • Full Member
  • ***
  • Karma: 12
  • Posts: 224
    • BLUEBYTE.ro // IT consultant
Re: Articles AND PAGES assigned to Categories
« Reply #2 on: March 03, 2008, 04:39:42 pm »

Ahh ... cool! Just when I was getting used to the way sNews works with content  ;D
Bookmarked!
Logged

m84

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
Re: Articles AND PAGES assigned to Categories
« Reply #3 on: October 09, 2008, 02:25:04 pm »

Just a *bump* for a really good mod and a well done tutorial to make it work! I must admit that i tried it once and didn't manage to make it work but today got it working! ;D Thanks!
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Articles AND PAGES assigned to Categories
« Reply #4 on: October 09, 2008, 03:43:25 pm »

Just a *bump* for a really good mod and a well done tutorial to make it work! I must admit that i tried it once and didn't manage to make it work but today got it working! ;D Thanks!

And thank you for the kind comments... good to hear you find it useful.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Slickwilly789

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Re: Articles AND PAGES assigned to Categories
« Reply #5 on: January 01, 2009, 06:51:35 pm »

Hey Key,

You suggested this mod to me in another thread to implement subpages in a site I am working on. I'm working with 1.7, and it seems that some of the above functions and mods, listed in order to use your mod might be included in snews already. In addition, the functions in 1.7, seem more complex than the ones in 1.6, by commenting them out I'm commenting out other things in 1.7 which aren't supposed to be commented out. Is there a changelog around the the forums from what changes were made from 1.6 to 1.7?
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Articles AND PAGES assigned to Categories
« Reply #6 on: January 02, 2009, 02:35:40 pm »

Hey Key,
Is there a changelog around the the forums from what changes were made from 1.6 to 1.7?

(I answered this yesterday... the post disappeared?)
No, not that I'm aware of. There are many significant differences between 1.6 & 1.7. I had gone through the 1.6 snews.php file doing a line by line comparison with the snews.php file in 1.5.31 and made comment notes in it (in the download package) where nothing had changed and where changes were. I did try doing this with 1.7 a while ago but stopped (after doing a little) when I realized how much had changed. Perhaps one of the Dudes who worked on 1.7 may have a better answer than me.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU