Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: [1] 2

Author Topic: Pages listed under Categories  (Read 11404 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Pages listed under Categories
« on: November 13, 2007, 05:47:08 PM »

Yes... Displaying Page links under Categories is realistically achievable.
I experimented a bit this morning and... so far... the results are positive... so I thought I'd share it with anyone interested in pursuing this more.

I started with a fresh, un-modded localhost install of sNews 1.6. I added a few mods to the snews.php and index.php files that  are required to get this working reasonably well.
1) Added the patches & fixes (that should be applied to any un-modded snews.php file before starting)
2) Philmoz's Admin Links Panel mods
3) Philmoz's Article Links under Categories
4) Equilni's Separeate Pages Function

Quick Run-down on Pages Categorization:
Note: This is not necessarily a complete list of Mod instructions... it is only to give you a good idea of what's involved.

Revised Approach - Nov.23.07:

1) The first step is a minor mod to create a new option to display the Categories drop-down list in the "Customize" panel when adding or editing Pages... so we can assign a page to a category. The Customize panel is located within the // ARTICLES FORM ( function form_articles$contents) ). We replace this line - if ($contents != 'page_new' && $edit_option != 3) { - which (essentially) says... "If the contents are NOTa new page or the edit option is not option 3 (for pages only)"... with one that says "If the contents ARE a new page or the edit option IS 3... by removing the exclamation marks from the string...

Code: [Select]
<?php

# If content IS a new page - categories display is enabled when adding/editing "pages"
if ($contents 'page_new' && $edit_option 3) {
# If content IS NOT a new page - categories display is disabled when adding/editing "pages"
//if ($contents != 'page_new' && $edit_option != 3) {

?>


2) Once Philmoz's Article Links under Categories mod has been added to function categories... I then took a copy of the function, pasted it above (or below) the existing categories function, and re-named it to - page_categories. There was only one critical change needed to make it display Page links under the Categories... and that was to change the article position number in the $calc_num_query string from "1" to "3"... which is assigned to all pages in the articles dbase table.

Code: [Select]
<?php


// DISPLAY PAGE CATEGORIES - Page Lists under categories (Philmoz)
function page_categories() {
    
$linkingSwitch=0;  // set to 1 to make category name act as a link to the category page.
    
$showHomeAsCAT=0// set to 0 to omit the Home link.
    
if (!$_SESSION[db('website').'Logged_In'] == token()){jsuser();}
    
$categorySEF get_id('category');
    
$divset="expanda".$categorySEF;
    
$class $category_title == $categorySEF ' class="current"' '';
    echo 
"\r\n".'<ul class="expandacat">';
    
// link to home page, displays when - $showHomeAsCAT - is set to "1"
    
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";    }
    
# fetching published categories, with the result = mysql_query($query)
    
$query "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder ASC";
    
$result mysql_query($query);
    
#---------------------------- lists page links ---------------|
    
while ($r mysql_fetch_array($result)) {
        
# fetching published pages (articles w/position 3) for each category
$calc_num_query "SELECT * FROM ".db('prefix')."articles WHERE position = 3 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 == && $_SESSION[db('website').'Logged_In'] == token()) || $num_rows 0) {
            
# category link (next 4 rows)
            
$category_title $r['seftitle'];
            
$divid="expanda2".$category_title// Changed $divid from expanda to expanda2
            
$class $category_title == $categorySEF ' class="current"' '';
            
$echo'<li class="expandacat">'."\r\n".'<a'.$class.' style="cursor:pointer;" title="'.$r['description'].'" onclick="toggle(\''.$divid.'\')"';
            
# If category name is set to display as as link, make it so
            
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";
            
# display page links under each category
    while ($art mysql_fetch_array($cm_result)) {
            
$echo.= '<li class="page_links"><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";
}

?>


And... to test display with this new function... add the new function-call string into index.php (above the categories menu):

Code: [Select]
<?php


[size=9pt]<h3>PAGE Categories:</h3>
<
ul> <?php page_categories(); ?>
</ul>

<h3>Categories:</h3>
<ul> <?php categories(); ?> </ul>[/size]

?>

Create some categories. Create a few pages. When you create each page, open the Customize Panel and choose a category from the categories drop-down field, and save as usual. A link to the new page will display in the Pages menu and it will also be available under the PAGE Categories list. Clicking the page link will display the page immediately.

This mod will need some more work to see how it can be integrated usefully into sNews... but it was a fairly easy one to apply at this stage.  :)


« Last Edit: March 02, 2008, 04:47:46 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Zucye

  • Sr. Member
  • ****
  • Karma: 5
  • Posts: 347
    • Simplemente una Mujer
Re: Pages listed under Categories
« Reply #1 on: November 13, 2007, 05:55:11 PM »

demo?
Logged
We can always learn from our failures, not so much from obvious success - C. Robinson (W. Disney). :)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #2 on: November 13, 2007, 05:58:02 PM »

No demo. I just started working on this one this morning... on my localhost machine... and it still has a ways to go. It isn't hard to envision though... the new page_categories function does the same thing as the normal categories function... but in this case it lists page-links under categories instead of article links.  :)
(Milestone: This was post number 3,000.)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Zucye

  • Sr. Member
  • ****
  • Karma: 5
  • Posts: 347
    • Simplemente una Mujer
Re: Pages listed under Categories
« Reply #3 on: November 13, 2007, 06:43:28 PM »

CONGRATULATIONS KEYS on your 3000 Post! (karma point for you)

I am kind of lost in the explanation (but don't mind me much, I am kind of tired today)

What I am really looking for is a way to display a list of articles when I category is display rather than 5, 10 or any number of articles the user has chosen.  I wan to show a simple list of all the articles available under that given category.  Is it a mod available for something like this??
Logged
We can always learn from our failures, not so much from obvious success - C. Robinson (W. Disney). :)

Joost

  • Guest
Re: Pages listed under Categories
« Reply #4 on: November 14, 2007, 01:33:16 AM »

@Zucye

Maybe    
Another article menu
is of any use.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #5 on: November 15, 2007, 03:26:55 AM »

Progress update:
Here is an image that shows how the page_categories function lists Page links under categories... and how the categories function continues to display Article links under categories separately at the moment. The extra_pages function... which split the non-default page links away from the default page links... is no longer needed.



Yet to do: The Page links generated by the Sitemap function (for the Sitemap page) still need to be altered so that the category SEF link will be included in them. Currently, the links are generated (by default) without the categorySEF included... and they result in a "not found" message. I am not sure how to get the categorySEF into the Sitemap page links... if anyone has a solution to offer, please post it here.
« Last Edit: November 15, 2007, 09:45:29 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #6 on: November 16, 2007, 05:05:07 PM »

Progress Update:
Have been taking this Pages in Categories thing a bit further... and testing out some other mods that are quite useful... 2 in particular that make placement of auto-generated Category menus a real breeze.

I installed Philmoz's Insert Function mod. I also installed his Articles by Category mod. Combined, this allows the Admin to insert a menu listing all article-links for any category in an "extra" position to display all article links in a given category. You do have to remember the category-name and its associated parameters... to insert in the 2 prompts provided by the "Function" editor button.

Then I gave Joost's Article Menu in Category mod a test-run and it works just as well... in fact... it's even more convenient to use because there is no need to include any parameters. You just insert the function-name and it automatically generates all of the article-links for the category you assign the "extra" into. Even better, cloning the function... re-naming it to page_menu_incat and changing the article position number to '3' from '1'... (in the dbase query string) generates all of the page-links associated with the current category.
Slick...  must say... (again) slick;D

Another Update - Bakercad to the Rescue:
Bakercad came to the rescue today with a revised Sitemap function to generate all of the page-links by category along with the existing article-links by category. A little more testing time in its raw state... and application to a copy of the current MESU package... and we may well have an alternative MESU package for those who want the added flexibility of assigning pages to categories.
Thanks again Bob... and a karma point to boot.  :)
« Last Edit: November 16, 2007, 09:57:43 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #7 on: November 19, 2007, 09:13:56 PM »

Pages in Categories Completed
Thanks to Bakercad's contribution of a new sitemap function... I have completed a version of the default sNews 1.6 package that lists Pages by Category as well as Articles by Category... with the ability to assign extra contents to all article pages in a category or to all pages in a category. Articles and pages can also be re-ordered within their category groups as well.

I have not posted it as another "package" in the Mods & Addons forum yet. Before doing so, I need an indication of how many of you are seriously interested in having an sNews 1.6 that offers the additional feature of posting Pages to Categories. If there is a lot of interest, I will post the package as a download.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Re: Pages listed under Categories
« Reply #8 on: November 20, 2007, 06:13:00 AM »

Demo Link?
Logged
Yes! I have no siggy.

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #9 on: November 23, 2007, 10:03:13 PM »

Just a note to advise that... if you wish to experiment with this Pages in Categories mod... I have posted a change in the first post to Step One. This change is simpler and eliminates a few bugs experienced with the first approach.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Pages listed under Categories
« Reply #10 on: November 24, 2007, 06:46:31 AM »

Yet to do: The Page links generated by the Sitemap function (for the Sitemap page) still need to be altered so that the category SEF link will be included in them. Currently, the links are generated (by default) without the categorySEF included... and they result in a "not found" message. I am not sure how to get the categorySEF into the Sitemap page links... if anyone has a solution to offer, please post it here.

Nice mod, I am interested in this mod too.  No reason why a page should be limited to being outside the category realm!

I see your having the same problem as myself with the subcategories mod with the links (catSEF/pageSEF/)... I think skidoo's subpages mod may have an answer.... I have a feeling it's in there....
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #11 on: November 24, 2007, 04:28:27 PM »

I see your having the same problem as myself with the subcategories mod with the links (catSEF/pageSEF/)... I think skidoo's subpages mod may have an answer.... I have a feeling it's in there....
@ EQ... actualy... I got this sorted out thanks to assistance from Bakercad. He revised a copy of function sitemap() to generate the links with the categorySEF included in them. I am using Bakercad's new function and it is working flawlessly. At this point... my Pages in Categories mod is completed... and I am spending some more time test-running to fine-tune it here and there. So far I have it running well in a bare-bones single-user version of sNews 1.6 and my most recent MEMU project. I am not sure if I should release these once testing is done... having too many package versions available will get too confusing I think.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Pages listed under Categories
« Reply #12 on: November 25, 2007, 04:14:54 PM »

Is it a global solution?  categorySEF/pageSEF?

You wouldn't mind sharing that function alone??
« Last Edit: November 25, 2007, 04:31:48 PM by equilni »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Pages listed under Categories
« Reply #13 on: November 25, 2007, 07:35:35 PM »

Is it a global solution?  categorySEF/pageSEF?
You wouldn't mind sharing that function alone??
Sure... if you mean Bakercad's Sitemap function... here it is, formatted for the default sNews. It displays the page-links by category:

Code: [Select]
function sitemap() {
   echo '<h2>'.l('sitemap').'</h2>';
   $link = l('divider').' <a href="'.db('website');
   $sections = array(l('pages'),l('articles'));
   foreach($sections as $section) {
      switch ($section){
         case l('pages'):
            $position = '3';
            $toplinks = '<p><strong><a href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></strong><br /></p>
               <p><strong><a href="'.db('website').'archive/" >'.l('archive').'</a></strong><br />';
            $botlinks = '<p><strong><a href="'.db('website').'contact/">'.l('contact').'</a></strong><br /></p>
               <p><strong><a href="'.db('website').'sitemap/">'.l('sitemap').'</a></strong><br /></p>
               <p><strong><a href="'.db('website').'rss/">'.l('rss_feed').'</a></strong></p>';
         break;
         case l('articles'):
            $position = '1';
            $toplinks = '<p><strong><a href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></strong><br />';
            $botlinks = '';
         break;
      }
      echo '<p><strong>'.$section.'</strong></p>';
      $art_query = "SELECT * FROM ".db('prefix')."articles WHERE position = $position AND published = '1'";
      $query = $art_query." AND category = 0 ORDER BY date DESC";
      $result = mysql_query($query);
      echo $toplinks;
      while ($r = mysql_fetch_array($result)) {
         $art_title = $r['title'];
         echo $link.find_cat_sef($r['category']).'/'.$r['seftitle'].'/" title="'.$art_title.'">'.$art_title.'</a><br />';
      }
      echo '</p>';
      $cat_query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder";
      $cat_result = mysql_query($cat_query);
      while ($c = mysql_fetch_array($cat_result)) {
         echo '<p><strong><a href="'.db('website').$c['seftitle'].'/" title="'.$c['description'].'">'.$c['name'].'</a></strong><br />';
         $catid = $c['id'];
         $query = $art_query." AND category = $catid ORDER BY id DESC";
         $result = mysql_query($query);
         while ($r = mysql_fetch_array($result)) {
            $date = date(s('date_format'), strtotime($r['date']));
            echo $link.$c['seftitle'].'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a><br />';
         }
         echo '</p>';
      }
      echo $botlinks;
   }
}
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Pages listed under Categories
« Reply #14 on: December 01, 2007, 03:14:40 PM »

2) Once Philmoz's Article Links under Categories mod has been added to function categories... I then took a copy of the function, pasted it above (or below) the existing categories function, and re-named it to - page_categories. There was only one critical change needed to make it display Page links under the Categories... and that was to change the article position number in the $calc_num_query string from "1" to "3"... which is assigned to all pages in the articles dbase table.

Why not try position IN (1,3) to avoid the entire function completly, just add it to Philmoz's function and you should be set.  Unless of course a total distinction is needed...

Then if you use the regular pages function or my seperate pages mod..
In function pages or extra_pages you can have the query as so:
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND category = 0 ORDER BY id";

Sitemap could have less modifications too ...
Code: [Select]
//SITEMAP

function sitemap() {
echo '<h2>'.l('sitemap').'</h2>';

echo '<p><strong>'.l('pages').'</strong></p>';

echo '<ul>';

$link = '<li><a href="'.db('website');

echo $link.'" title="'.l('home').'">'.l('home').'</a></li>';

echo $link.'archive/" title="'.l('archive').'">'.l('archive').'</a></li>';
// initial page query is calling for home'd pages and not pages in categories
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND category = 0 AND published = '1' ORDER BY date";

$result = mysql_query($query);

$home = l('home_sef');

while ($r = mysql_fetch_array($result)) {

        $page_title = $r['title'];

        if ($r['id'] != s('display_page')) {
echo $link.$home.'/'.$r['seftitle'].'/" title="'.$page_title.'">'.$page_title.'</a></li>';
}

    }

    echo $link.'contact/">'.l('contact').'</a></li>';

    echo $link.'sitemap/">'.l('sitemap').'</a></li>';

    rss_links();

    echo '</ul>';

    echo '<p><strong>'.l('articles').'</strong></p>';

    echo '<ul>';

    $art_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = '1'";

    $query = $art_query." AND category = 0 ORDER BY date DESC";

    $result = mysql_query($query);

    echo '<li><strong><a href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></strong></li>';

    while ($r = mysql_fetch_array($result)) {

        $art_title = $r['title'];

        echo $link.l('home_sef').'/'.$r['seftitle'].'/" title="'.$art_title.'">'.$art_title.'</a></li>';

    }

    echo '</ul>';

    $cat_query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder";

    $cat_result = mysql_query($cat_query);
    while ($c = mysql_fetch_array($cat_result)) {
    echo '<p><strong><a href="'.db('website').$c['seftitle'].'/" title="'.$c['description'].'">'.$c['name'].'</a></strong></p>';
        $catid = $c['id'];
// looking for both position 1 and 3, articles and pages for categories only
        $query = "SELECT * FROM ".db('prefix')."articles WHERE position IN (1,3) AND published = '1' AND category = $catid ORDER BY id DESC";
        $result = mysql_query($query);
        $recs = mysql_fetch_array($result);
        if (!empty($recs)) {               
        $x = mysql_data_seek($result, 0);
          echo '<ul>';
          while ($r = mysql_fetch_array($result)) {
            $date = date(s('date_format'), strtotime($r['date']));
            echo $link.$c['seftitle'].'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a></li>';
          }
          echo '</ul>';
        } else { echo l('no_articles_in_cat'); }

}
}
« Last Edit: December 01, 2007, 03:41:28 PM by equilni »
Logged
Pages: [1] 2