Hello

September 07, 2010, 05:20:18 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?
Login with username, password and session length
What sNews Is: - sNews is a simple, basic, customizable CMS tool suitable for developers with beginner-to-advanced PHP skills. It is also useful to have a good working knowledge of how to work with, set up and manage MySQL databases. sNews is not - geared towards the end-user who knows little or nothing about building and developing PHP-MySQL based websites.
News: Try sNews 1.7 DEMO
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [mod] Another article menu  (Read 2611 times)
Joost
Guest
« on: November 04, 2008, 05:05:29 PM »

This menu displays articles in the current category.

Past the following code in sNews.php

Code:
<?php
function menu_articles_incat(){
 global 
$categorySEF$subcatSEF,$_catID$_ID$_XNAME;
 if( isset(
$_catID) ){
$link  = (!empty($categorySEF) ? $categorySEF.'/' '');
if( isset($_XNAME)) $link .= ((!empty($subcatSEF)) ? $subcatSEF.'/' '');
$source mysql_query('SELECT id,title,seftitle FROM '.
_PRE.'articles WHERE category ='.$_catID.' AND visible=\'YES\' AND published=1 ORDER BY artorder,`date`');
$list '';
while($r mysql_fetch_assoc($source)){
 if( $_ID === $r['id']) $list .= sprintf('<li id="here">%s</li>',$r['title']);
 else  $list .= sprintf('<li><a href="%s%s/">%s</a></li>',$link,$r['seftitle'],$r['title']);
}
 }
 if(
$list) echo "\n<ul>$list</ul>\n";
}
?>

Paste
Code:
<?php menu_articles_incat(); ?>

....in index.php
« Last Edit: November 04, 2008, 05:07:04 PM by Joost » Logged
rubenam
Newbie
*

Karma: 0
Posts: 14


« Reply #1 on: January 11, 2009, 08:41:34 PM »

Hi, great mod.
I have changed '.$_catID.' for the number ID of a category, because I want that the articles of this category always apperars. The poblem is that when I click on the link of the article,dont works. Only works if I am in the correct category.

What i need to change to have a correct link to the article content from another category?.

Thank you
Logged
H.A.C
Jr. Member
**

Karma: 19
Posts: 86


i love snews community for its great members


WWW
« Reply #2 on: January 12, 2009, 03:44:33 AM »

Because the global var $subcatSEF will always refer to the current category, if your desired cat is not the current cat, the article's hyperlink will be wrong. So I think if you want to show articles in a specified category! the query string must also return its has subcat or not.

Code:
<?php
function article_menu_id($yourcat$size) {
$r mysql_query('SELECT
title, a.seftitle AS asef,  
c.seftitle AS csef,
x.seftitle AS xsef
FROM '
._PRE.'articles'.' AS a
LEFT OUTER JOIN '
._PRE.'categories'.' as c ON category = c.id
LEFT OUTER JOIN '
._PRE.'categories'.' as x ON c.subcat = x.id AND x.published =\'YES\'
WHERE position = 1 '
.$yourcat.' AND a.published = 1 AND c.published =\'YES\'
ORDER BY `date`
LIMIT '
.$size);
while ($r mysql_fetch_array($result)) {
if ($r['csef']) $uri $r['xsef'] ? $r['xsef'].'/'.$r['csef'] :  $r['csef'];
else $uri $r['csef'];
echo '<li>'.'<a href="'._SITE.$uri.'/'.$r['asef'].'/">'.$r['title'].'</a></li>';
}
}
?>


i did not test the function above. just a fast idea!
Logged

I'm not available ....until the end of the year 2009!
----------------------------
The largest website powered by sNews is in its way to become the biggest!
My great personal website powered by sNews 1.6
http://www.chasoft.net
Come to see how it's great!
Joost
Guest
« Reply #3 on: January 12, 2009, 12:31:08 PM »

Because the global var $subcatSEF will always refer to the current category,

Maybe that solution works in this particular situation, but I am afraid it more complicated than that. $subcatSEF refers to the second part of a uri: /seftitle/seftitle/
So it can be:
- An article
- a subcategory
- A commentpage ( /seftitle/c_2/)
- A category page ( /seftitle/p_2/)


Anyway, a (quick and dirty) solution might be the following function:

Code:
function menu_special() {
$_cat = 1;
$query = 'SELECT
title,a.seftitle AS asef,date,
c.name AS name,c.seftitle AS csef,
x.name AS xname,x.seftitle AS xsef
FROM '._PRE.'articles'.' AS a
LEFT OUTER JOIN '._PRE.'categories'.' as c
ON category = c.id
LEFT OUTER JOIN '._PRE.'categories'.' as x
ON c.subcat =  x.id AND x.published =\'YES\'
WHERE position = 1
AND a.published = 1
AND c.published =\'YES\'
AND a.visible = \'YES\'
AND a.category = '.$_cat.'
ORDER BY artorder,date DESC';
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$date = date(s('date_format'), strtotime($r['date']));
$link = isset($r['xsef']) ? $r['xsef'].'/'.$r['csef'] : $r['csef'];
echo  '<li><a href="'._SITE.$link.'/'.$r['asef'].'/"
title="'.$r['name'].' / '.$r['title'].' ('.$date.')">'.$r['title'].'</a>
</li>';
}
}


Past <?php menu_special(); ?> somewhere in index.php and change $_cat= 1 to the number you want.

Logged
adsnew
Newbie
*

Karma: 1
Posts: 13



« Reply #4 on: January 13, 2009, 12:24:04 AM »

tks Joost  for this mod .

QST :

if in the title of this menu i need the courant categories name ?


tks for answer me
Logged

I'am work for Media site with snews Smiley
rubenam
Newbie
*

Karma: 0
Posts: 14


« Reply #5 on: January 26, 2009, 06:33:04 PM »

Thank you very much for your solutions Joost. I was busy implementing it, and works great.

Category name is not needed. Only is necesary to put the number of the category. You can see the number of each category in phpmyadmin.

Regards,

Ruben
Logged
sibas
Full Member
***

Karma: 9
Posts: 193


WWW
« Reply #6 on: May 30, 2010, 04:59:53 PM »

how to display only the articles and not also the extras
the main mod by Joost display also and "extras", is any easy way to avoid that?
Logged
Keyrocks
Doug
Administrator
ULTIMATE member
******

Karma: 419
Posts: 5568


Semantically Challenged


WWW
« Reply #7 on: May 30, 2010, 08:46:53 PM »

how to display only the articles and not also the extras
the main mod by Joost display also and "extras", is any easy way to avoid that?

If you are using the one in Joost's post at the top of this thread, it would display articles, extras and pages because the query is not written to specifically filter out extras and pages. Try this one, with AND position=1 added to the query so it should only SELECT articles, which are always assigned position 1.

Code:
<?php

function menu_articles_incat(){
    global 
$categorySEF$subcatSEF,$_catID$_ID$_XNAME;
    if( isset(
$_catID) ){
$link  = (!empty($categorySEF) ? $categorySEF.'/' '');
if( isset($_XNAME)) $link .= ((!empty($subcatSEF)) ? $subcatSEF.'/' '');
$source mysql_query('SELECT id,title,seftitle FROM '.
_PRE.'articles WHERE category ='.$_catID.' AND visible=\'YES\' AND published=1 AND position=1 ORDER BY artorder,`date`');
$list '';
while($r mysql_fetch_assoc($source)){
 if( $_ID === $r['id']) $list .= sprintf('<li id="here">%s</li>',$r['title']);
 else  $list .= sprintf('<li><a href="%s%s/">%s</a></li>',$link,$r['seftitle'],$r['title']);
}
    }
    if(
$list) echo "\n<ul>$list</ul>\n";
}

?>

Logged

Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
sibas
Full Member
***

Karma: 9
Posts: 193


WWW
« Reply #8 on: May 31, 2010, 12:30:57 PM »

Thank you Keyrocks, that was easy  Smiley
I use so many time Snews and still don't know the basics  Roll Eyes
Logged
sibas
Full Member
***

Karma: 9
Posts: 193


WWW
« Reply #9 on: June 01, 2010, 01:36:16 PM »

I play with the last mod of Joost “menu_special()”
and end it with this

Code:
function menu_special($yourcat, $size) {
$query = 'SELECT
title,a.seftitle AS asef,date,
c.name AS name,c.seftitle AS csef,
x.name AS xname,x.seftitle AS xsef
FROM '._PRE.'articles'.' AS a
LEFT OUTER JOIN '._PRE.'categories'.' as c ON category = c.id
LEFT OUTER JOIN '._PRE.'categories'.' as x ON c.subcat =  x.id AND x.published =\'YES\'
WHERE position = 1
AND a.published = 1
AND c.published =\'YES\'
AND a.visible = \'YES\'
AND a.category = '.$yourcat.'
ORDER BY artorder,date DESC';
$query .=" LIMIT $size";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$date = date(s('date_format'), strtotime($r['date']));
$link = isset($r['xsef']) ? $r['xsef'].'/'.$r['csef'] : $r['csef'];
echo  '<li><a href="'._SITE.$link.'/'.$r['asef'].'/"
title="'.$r['name'].' / '.$r['title'].' ('.$date.')">'.$r['title'].'</a>
</li>';
}
}

how can I display the last articles, if i try menu_special(6,2); display always the first ones!
Logged
Keyrocks
Doug
Administrator
ULTIMATE member
******

Karma: 419
Posts: 5568


Semantically Challenged


WWW
« Reply #10 on: June 01, 2010, 04:32:59 PM »

Your function only displays the article links for the category defined by its ID - the first number.
If you use menu_special(6,2); in index.php, it will display only the first two article links for the category with ID of 6.
It will always display the same two article links for that category no matter what site page you view.

In the last line of your function's $query you have the ORDER defined as ORDER BY artorder,date DESC';
This line determines the order in which the $query SELECTS the data and how it will be displayed by the function itself.

Notice that you have 2 ORDER parameters set there: - 1) first by the artorder and 2) by date DESC - by date in descending order. You only need to set one parameter there, as the first - artorder - always over-rides the second one.

This means the article links will display in the order you set them to by changing the order of articles in any category (or sub-category) group in the Admin's Articles - View Panel. There, you can number the order in which you want the articles to display. Set an article as "0" and its link will always show as the first in the list, followed by 1, 2, 3 and so on. If you have 10 articles in the category group, number them as you wish from "0" to "9".

You can change the ORDER in the $query to suit the order you wish to display links in.
      1) ORDER by date, oldest to newest: ORDER BY date ASC'; // ascending order, artorder settings do not apply
      2) ORDER by date, newest to oldest: ORDER BY date DESC'; // descending order, artorder settings do not apply
      3) ORDER by article-order settings: ORDER BY artorder'; // as set in the Articles - View panel, date order does not apply
« Last Edit: June 01, 2010, 04:35:39 PM by Keyrocks » Logged

Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
sibas
Full Member
***

Karma: 9
Posts: 193


WWW
« Reply #11 on: June 02, 2010, 05:48:46 PM »

First of all is not my function, is Joost function and just modifying a little bit with H.A.C function above  Grin
I need to display 6-8 different categories with their articles links in index

ORDER BY date DESC'; did the trick  Wink

Thanks for the help to explain what and how to do ++karma to you!
Logged
Keyrocks
Doug
Administrator
ULTIMATE member
******

Karma: 419
Posts: 5568


Semantically Challenged


WWW
« Reply #12 on: June 02, 2010, 07:02:35 PM »

Thanks for the help to explain what and how to do ++karma to you!

Glad you have the solution. Thanks for the +K.  Cool
Logged

Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: [1]
  Print  
 
Jump to:  

English Steel 1.6 © Saxon North Technologies
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!