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.

Author Topic: [MOD-WIP]Showing all articles in category dependent menu  (Read 4072 times)

centered

  • Guest
[MOD-WIP]Showing all articles in category dependent menu
« on: June 08, 2007, 10:55:14 AM »

This mod shows all the articles in a clicked category. If it is the fromt page (ie http://localhost/sNews/) it will show nothing.

This is a working version for text-db users

Thanks to:
Michael on post 5 in this thread:
http://www.solucija.com/forum/viewtopic.php?id=706

Luka on post 2 in this thread:
http://www.solucija.com/forum/viewtopic.php?id=709

0. Backup

1. Place this function after the connect_to_db:
Code: [Select]
// FIND CATEGORY'S ID THROUGH SEF TITLE
function find_cat_id($categorysef) {
connect_to_db();
$db = new Database(s('dbname')) or die(s('dberror'));
$query = "SELECT id FROM " .s('prefix'). "categories WHERE seftitle = '$categorysef'";
$result = $db->query($query);
   while ($r = $result->fetch_array()) {
   $cat_id = $r['id'];  
}
if (isset($cat_sef)) {
$cat_sef_title = $cat_sef;
}
return $cat_id;
}
2. Place this function after menu_items:
Code: [Select]
// Category Menu showing Articles in Category
function category_menu() {
connect_to_db();
$db = new Database(s('dbname'));
$category = $_GET['category'];
$sfcatName = get_id('category');
$getCat = find_cat_id($sfcatName);
$query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 3 AND category = '$category' ORDER BY id ASC AND ";
$query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 AND published = 1 AND category = ".$getCat." ORDER BY date DESC";
$result = $db->query($query);
if ($result == 0) { echo ""; }
else {
echo "<h3>Category Articles</h3>";
echo "<ul class='menu'>";
while ($r = $result->fetch_array()) {
echo "<li><a href='" .s('website'). find_cat_sef($r['category']). "/" .$r['seftitle']. "/'>". $r['title'] ."</a></li>";
}
?></ul><?
}
}
3. In index.php, place this after menu_items
Code: [Select]
<? category_menu(); ?>Working on a mysql version soon, no promises though

If you are in the website/ you will see nothing:


If you click on a category, you will get a menu:
« Last Edit: August 25, 2007, 03:11:35 AM by Phil Martin (Philmoz) »
Logged

amak

  • Newbie
  • *
  • Karma: 4
  • Posts: 41
[MOD-WIP]Showing all articles in category dependent menu
« Reply #1 on: June 08, 2007, 02:08:22 PM »

Quote from: centered
Working on a mysql version soon, no promises though
Nice work .. i'd love to see this for the standard mysql version ;)
Logged
Regards,
Amak

centered

  • Guest
[MOD-WIP]Showing all articles in category dependent menu
« Reply #2 on: June 08, 2007, 02:30:49 PM »

Thanks, it will be my next project...
Logged

centered

  • Guest
[MOD-WIP]Showing all articles in category dependent menu
« Reply #3 on: July 20, 2007, 07:33:00 AM »

didnt update this...

mysql
Code: [Select]
// CATEGORY MENU

function category_menu() {

     $categorySEF = get_id('category');

     $exist = check_category($categorySEF);

     if (!empty($categorySEF) && $exist == true) {

     echo '';

} else {

echo "<h2>Category Articles</h2><ul class='dates'>";

$sfcatName = get_id('category');

$getCat = find_cat_id($sfcatName);

  $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 AND published = 1 AND category = '$getCat' ORDER BY date DESC";

$result = mysql_query($query) or die(s('dberror'));

if ($result == 0) { echo ""; }

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

      echo "<li><a href='" .s('website'). find_cat_sef($r['category']). "/" .$r['seftitle']. "/'>". $r['title'] ."</a></li>";

    }

echo "</ul>
";

}

}
« Last Edit: August 25, 2007, 03:11:58 AM by Phil Martin (Philmoz) »
Logged

Joost

  • Guest
[MOD-WIP]Showing all articles in category dependent menu
« Reply #4 on: July 20, 2007, 01:13:50 PM »

Looks like: Another page menu (1.5, 1.6) :)
Logged