Please login or register.

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

Author Topic: Another article menu  (Read 13764 times)

Joost

  • Guest
Another article menu
« on: June 25, 2007, 03:19:30 am »

Perhaps the most simple page menu on the forum. No toggle function.

Originally written by Bakercad for 1.5. It works in 1.6 as well, since both use the same database (yes, it is tested). I am just pimping it.;)

what it does:
Displays a menu containing links to all pages of the current category.
The current page is not displayed as a link, instead it's bold.
Home is no category, so there is no menu displayed on 'Home'
This menu can be displayed on any location in the template. Just paste the following code in index.php, whereever you want it to be displayed.
Code: [Select]
<?php menu_articles_incat(); ?>The following code goes into snews.php. Paste it somewhere after or before // MENU ARTICLES. It doesn't matter really where, but don't nest it.

id="this_category" is added to the element ul, so you can easily style it through the stylsheet.
Code: [Select]
<?php

//ARTICLE MENU
function menu_articles_incat$offset 0$max ) {
$limit $list '';
if( $offset or $max ) {
$limit " LIMIT $offset$max";
}
    
$categorySEF get_id('category');
    if ( ! empty(
$categorySEF) && ! check_category($categorySEF) ) {
    
$cat retrieve('id','categories','seftitle',$categorySEF);
    
$query 'SELECT title,seftitle FROM '.db('prefix').'articles WHERE category = '
.$cat.' AND position = 1 AND published = 1 ORDER BY date DESC' $limit;
    
$result mysql_query($query);
$pageSEF get_id('article');
$site db('website');
        while (
$r mysql_fetch_array($result)) {
         if (
$pageSEF === $r['seftitle']){ $list .= '<li><span  id="artikel">'.$r['title'].'</span></li> ';}
 else {
        
$list .= '<li><a href="'.$site.$categorySEF.'/'.$r['seftitle'].'/" >'.$r['title'].'</a></li> ';}
        }
}
if($list) echo "<ul id=\"this_category\">$list</ul>";
}

For mysql versions >= 4.1 use the following (better performance):

Code: [Select]
<?php

//ARTICLE MENU
function menu_articles_incat$offset 0$max ) {
$limit $list '';
if( $offset or $max ) {
$limit " LIMIT $offset$max";
}
    
$categorySEF get_id('category');
    if ( 
$categorySEF && ! check_category($categorySEF) ) {
    
$query 'SELECT title,seftitle FROM '.db('prefix').'articles WHERE category = (SELECT id FROM  '
.db('prefix').'categories WHERE seftitle =\''
.$categorySEF.'\') AND position = 1 AND published = 1 ORDER BY date DESC' $limit; echo $query;
    
$result mysql_query($query);
$pageSEF get_id('article');
$site db('website');
        while (
$r mysql_fetch_array($result)) {
         if (
$pageSEF === $r['seftitle']){ $list .= '<li><span  id="artikel">'.$r['title'].'</span></li> ';}
 else {
        
$list .= '<li><a href="'.$site.$categorySEF.'/'.$r['seftitle'].'/" >'.$r['title'].'</a></li> ';}
        }
}
if($list) echo "<ul id=\"this_category\">$list</ul>";
}


?>
« Last Edit: August 24, 2009, 02:52:20 am by Joost »
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
Another page menu
« Reply #1 on: June 25, 2007, 09:19:16 am »

I love menues, I do... could we see an example, Joost. I mean those of us that don't understand in full ;)... Do you have it online ?
Logged
"It's only dead fish that goes with the flow... "
Updated

Joost

  • Guest
Another page menu
« Reply #2 on: June 25, 2007, 05:36:19 pm »

Here is the link. Brings you straight to 'category 1'. I put this menu at the left site. Nothing is styled. And please don't look at the mess, I didn't expect any visitors. :)
Logged

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Another page menu
« Reply #3 on: June 25, 2007, 08:21:03 pm »

Good ideia Joost.

I'll put this mod to my collection. This works fine with my [MOD] MA (Multiple areas for categories).

I add MA to my website. MAM (MA+Another page menu) Avalaible to download in website

Nice work.
« Last Edit: August 24, 2007, 10:31:34 am by Rui Mendes »
Logged
Need a Job on Europe. Linkdin - Facebook / Group

centered

  • Guest
Another page menu
« Reply #4 on: June 29, 2007, 12:59:51 pm »

I have a dumb question... something I am trying to solve in my version of this mod too.  

When you are in Archives, Contact or Site map, shouldn;t this display nothing?  A user may think that the Home is a clickable link when in fact it is not.  THe user will also think they are home, which again they are not.

Try this partial code out:

Code: [Select]
//PAGE MENU
function menu_articles_incat() {
     $categorySEF = get_id('category');
     $exist = check_category($categorySEF);
     if (!empty($categorySEF) && $exist == true) {
     echo '';
} else {
echo '<h4>Content ';
             $title = retrieve('name', 'categories', 'seftitle', $categorySEF);
             echo $title;
     echo '</h4>'."\n\t".'<ul id="this_category">';
     $cat = retrieve('id','categories','seftitle',$categorySEF);
     $query = "SELECT * FROM ".db('prefix')."articles WHERE category = $cat AND position = 1 AND published = 1 ORDER BY date DESC";
     $result = mysql_query($query);
     $home = s('home_sef');
         while ($r = mysql_fetch_array($result)) {
         $date = date(s('date_format'), strtotime($r['date']));
             $pageSEF = get_id('article');
             if ($pageSEF == $r['seftitle']){
echo "\n\t".'<li><b>'.$r['title'].'</b></li>';
} else {
         echo "\n\t".'<li><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" >'.$r['title'].'</a></li>';
}
         }
     echo'</ul>'."\n";
}  
}
When you click on the above mentioned you get nothing, which you should get.  

Now somethings not working for me, which I see in the sites posted above.... Nothing is displaying in the home category..... shouldn't it?
« Last Edit: August 25, 2007, 12:58:03 am by Phil Martin (Philmoz) »
Logged

centered

  • Guest
Another page menu
« Reply #5 on: June 29, 2007, 01:54:05 pm »

Fixed!
The sitemap function helped on this one...
Code: [Select]
//PAGE MENU
function menu_articles_incat() {
$categorySEF = get_id('category');
        $exist = check_category($categorySEF);
        if (!empty($categorySEF) && $exist == true) {
             echo '';
     } else {
echo "<h3>Category Articles</h3>";
             $cat = retrieve('id','categories','seftitle',$categorySEF);
if ($cat == 0) {
$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);
while ($r = mysql_fetch_array($result)) {
      echo "<p><a href='" .db('website'). find_cat_sef($r['category']). "/" .$r['seftitle']. "/'>". $r['title'] ."</a></p>";
}
    } else {
  $query = "SELECT * FROM ".db('prefix')."articles WHERE category = $cat AND position = 1 AND published = 1 ORDER BY date DESC";
             $result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
      echo "<p><a href='" .db('website'). find_cat_sef($r['category']). "/" .$r['seftitle']. "/'>". $r['title'] ."</a></p>";
    }
}
}
}
« Last Edit: August 25, 2007, 12:58:24 am by Phil Martin (Philmoz) »
Logged

Joost

  • Guest
Another page menu
« Reply #6 on: June 29, 2007, 08:49:45 pm »

Centered I tried your code. When on the hompage, there is a list of pages displayed that belong to the  non-category 'Home'. However, the list disappears when I go to a page in  non-category 'Home'. That is confusing.
My code has been updated. The confusing  Home is taken out.  Consider that this menu can be placed anywhere and non-category 'Home does not need to contain articles. It all depends on how the site is structured. For some structures this menu is useful, for others it might not. :)

However, if a consistent page menu for the  non-category 'Home' could be developed, that would be appreciated.;)
« Last Edit: September 04, 2007, 07:23:23 am by Joost »
Logged

centered

  • Guest
Another page menu
« Reply #7 on: June 29, 2007, 11:14:07 pm »

Ok my stupid day continues... I really should of stayed in bed today.

I guess my solution was to show all articles in thier respected categories.  By default Home is a category (strange but its true).  So if a user posts in the home category then one would expect to see articles in the home category.

Suggestion (not directed at you Joost, but in general)?
Home should be the Home Page and not a Home category.  The category should default to a 'general' cateogry and not home.  WP has a uncategorized category not home.  I think it could be coded in to include a uncategorized section.
Logged

Joost

  • Guest
Another page menu
« Reply #8 on: June 30, 2007, 06:50:54 am »

Quote from: centered
Ok my stupid day continues... I really should of stayed in bed today.

I guess my solution was to show all articles in their respected categories.  By default Home is a category (strange but its true).  So if a user posts in the home category then one would expect to see articles in the home category.

Suggestion (not directed at you Joost, but in general)?
Home should be the Home Page and not a Home category.  The category should default to a 'general' category and not home.  WP has a uncategorized category not home.  I think it could be coded in to include a uncategorized section.
I don't see any stupidity. The only way to avoid mistakes, is doing nothing at all (staying in bed, like you suggest). At least you've tried :) I agree with you if you mean that 'home' is a blurred functionality in sNews.
Logged

Joost

  • Guest
Re: Another page menu
« Reply #9 on: August 24, 2007, 05:09:11 am »

Code fixed for Forum migration.
Logged

stumbler

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Re: Another page menu
« Reply #10 on: September 04, 2007, 03:44:30 am »

Your MOD could well accomplish another sought-after purpose.  For example, once the selected category is recognized in your MOD the resulting action you demonstrated was to place that into the header.

This action, I tend to think, could be modified to one that places an image into the header space.  This would allow styling the header in a way that mimics a new "site".  In my case, I have four categories only, and I wish to display all articles in a category under a new header image selected for that category.  In a case where there are few categories that might work - not sure it is all that useful when there are many categories. 

Could you offer your take on that?

 
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Another page menu
« Reply #11 on: September 04, 2007, 04:31:39 am »

Stumbler -- without detracting anything from this mod, you probably want to check out the body id mod for 1.6. There's also an original version of that mod for v1.5.31.

What the mod does is add an id to the body, and the id takes the name of the page you access. If you for instance go to "contact/", the id of the body will become "contact", if you go to "category/article-1/" the id will be "article-1", and so on. You get the drift. This way it's easy to not only change the header image to make like a "new site", but you can actually make the entire page take on a different look than other pages. Stylewise, it's a rather clever mod -- if I may say so myself. ;D
« Last Edit: September 04, 2007, 04:55:59 am by Fred K (agentsmith) »
Logged

Joost

  • Guest
Display an image on a category
« Reply #12 on: September 04, 2007, 07:00:15 pm »

Stumbler. This will display a different image in each category (not home or pages):
 
Code: [Select]
<?php
function image_in_category () {
$categorySEF get_id('category');
if (!empty(
$categorySEF) || $categorySEF != 0) {
$altretrieve('name''categories''seftitle'$categorySEF);
echo '<img src="'.$categorySEF.'.jpg height="100" width="100" alt="'.$alt.'" />';}
}
?>
Adjust: extension, height and width.

Insert this in the index.php:
Code: [Select]
<?php image_in_category (); ?>It will display the following:
<img src="name-of-current-category,jpg" height="100" width="100" alt="Name of current category" />

a more simple approach (1 variable), but also very flexible:
You can set an id to an element (not necessarily the body).
Code: [Select]
<?php
function id_for_category () {
   
$categorySEF get_id('category');
if (!empty(
$categorySEF) || $categorySEF != 0) {echo ' id="'.$categorySEF.'"';}
}
?>
Insert in index.php in an element (<div >):
Code: [Select]
<?php  id_for_category(); ?>
This will display <div id="name-of-current-category">

Unlike Fred's mod it is not a clever mod. But it works! :D
« Last Edit: October 21, 2007, 03:24:58 am by Joost »
Logged

stumbler

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Re: Another page menu
« Reply #13 on: September 05, 2007, 11:08:19 pm »

Thank you both, Joost and Agent - both solutions are transparent enough for me to understand.  At present I opted for Joost's approach becaue it is the narrow answer to a narrow question. 

I am also using the "draft example" theme you (Joost) offered earlier to create a modified HTML page to simulate the various images and other layout features.  I have a slow-burning fuse, so it takes much longer to reach the comfort level before performing surgery on the snews.php. I must do it by 'Braille' because I do not have the requisite competence needed to whip right through to implementation.  My snews is running in default mode, and I look forward to getting my site and content up.   Many thanks!!!  
Logged

mfaraklit

  • Newbie
  • *
  • Karma: 1
  • Posts: 20
Re: Display an image on a category
« Reply #14 on: October 19, 2007, 03:09:02 pm »

i tried this smart mod in my web site. but it calls a image(i inserted the kod top the center() ) in all pages/articles/contact/sitemap/archive/ and even in all of adminstrator related pages.
what can i do for this problem.
Thank alot from the Turkey.
Logged
Pages: [1] 2 3