[solved] category browsing

If you have any problems with Fusion News, post your problems here and we'll help you out as soon as possible.

[solved] category browsing

Postby UndercoverAndrey » Thu Dec 24, 2009 11:19 pm

i'd like to allow the visitors to browse the news by category. is this possible?
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm

Re: category browsing

Postby Blackshadow » Fri Dec 25, 2009 12:26 pm

Moved to Help and Support forum

First of all, Merry Christmas! :)

Out of the box it's not possible, but it's possible with a bit of extra code. I don't have time to write something to do what you want write now, but I'll get something done for you ASAP.
~ Blackshadow
Fusion News Developer
User avatar
Blackshadow
Fusion News Developer
 
Posts: 1296
Joined: Tue Oct 17, 2006 8:10 pm
Location: UK

Re: category browsing

Postby UndercoverAndrey » Sat Dec 26, 2009 2:09 am

thanks a lot i apprecate it


& merry christmas as well =D
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm

Re: category browsing

Postby Blackshadow » Sat Dec 26, 2009 4:13 pm

Here's a simple PHP script that lists the categories, and links to a page which will display the news for the selected category:
Code: Select all
<?php

// EDIT THIS HERE
$fn_directory = 'news;

include $fn_directory . '/common.php';

$show_category = isset ($_GET['show_category']) ? (int)$_GET['show_category'] : 0;

if ( $show_category <= 0 )
{
    ob_start();

    $category_file = file ($fn_directory . 'categories.php');
    array_shift ($category_file);

    $categories = array();
   
    echo '<ul>';
    foreach ( $category_file as $category )
    {
        $data = get_line_data ('categories', $category);
        echo '<li><a href="?' . $_SERVER['QUERY_STRING'] . '&amp;show_category=' . $data['category_id'] . '">' . $data['name'] . '</a></li>';
    }
    echo '</ul>';
   
    ob_end_flush();
}
else
{
    $fn_category = $show_category;
    include $fn_directory . '/news.php';
}

?>

Copy and paste that on to the page you want to list the categories, and it'll do the rest for you. At the moment, it displays the categories in a bulleted list, but I think you can work out how to change that :) If not, just ask.
~ Blackshadow
Fusion News Developer
User avatar
Blackshadow
Fusion News Developer
 
Posts: 1296
Joined: Tue Oct 17, 2006 8:10 pm
Location: UK

Re: category browsing

Postby UndercoverAndrey » Sat Dec 26, 2009 11:31 pm

im getting this error message from the code above

"Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/clear/public_html/cats.html on line 8"


do I have to edit something for it to work? thanks
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm

Re: category browsing

Postby joshua.s.belanger » Sun Dec 27, 2009 2:30 am

You need to edit the
Code: Select all
// EDIT THIS HERE
$fn_directory = 'news;
-Josh
User avatar
joshua.s.belanger
FN Follower
 
Posts: 249
Joined: Wed Jun 03, 2009 2:54 pm

Re: category browsing

Postby Blackshadow » Sun Dec 27, 2009 12:22 pm

Sorry, I forgot to mention you need to edit that line josh has pointed out. And there should be an extra apostrophe after news:
Code: Select all
$fn_directory = 'news';

Change news to the directory you installed Fusion News to.
~ Blackshadow
Fusion News Developer
User avatar
Blackshadow
Fusion News Developer
 
Posts: 1296
Joined: Tue Oct 17, 2006 8:10 pm
Location: UK

Re: category browsing

Postby djbobolod » Sun Dec 27, 2009 5:16 pm

I was looking for the same. I can do with
Code: Select all
$fn_directory = 'news';
djbobolod
Newbie
 
Posts: 17
Joined: Thu Dec 10, 2009 6:40 pm

Re: category browsing

Postby UndercoverAndrey » Mon Dec 28, 2009 12:13 am

well the directory i have news installed to is already called news. i tried changing the 'news' to the full directory path

$fn_directory = 'home/clear/public_html/news';

still getting error messages


thanks, sorry about all the trouble
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm

Re: category browsing

Postby Blackshadow » Tue Dec 29, 2009 10:25 am

You're missing a forward slash at the beginning of your path. It should be /home/clear...
~ Blackshadow
Fusion News Developer
User avatar
Blackshadow
Fusion News Developer
 
Posts: 1296
Joined: Tue Oct 17, 2006 8:10 pm
Location: UK

Re: category browsing

Postby UndercoverAndrey » Tue Dec 29, 2009 11:19 pm

no idea whats's wrong, that doesnt solve the problem though... could something else be wrong with the code?

theres also a news directory inside the news folder itself... is the directory suppose to lead to that folder or just the folder there fusion news is installed to?

either way, both arent working, sorry all the problems



this takes you to the fusion news login

http://clearnonsense.com/news/


this is what code im using

Code: Select all
    <?php

    // EDIT THIS HERE
    $fn_directory = '/home/clear/public_html/news';

    include $fn_directory . 'common.php';

    $show_category = isset ($_GET['show_category']) ? (int)$_GET['show_category'] : 0;

    if ( $show_category <= 0 )
    {
        ob_start();

        $category_file = file ($fn_directory . 'categories.php');
        array_shift ($category_file);

        $categories = array();
       
        echo '<ul>';
        foreach ( $category_file as $category )
        {
            $data = get_line_data ('categories', $category);
            echo '<li><a href="?' . $_SERVER['QUERY_STRING'] . '&amp;show_category=' . $data['category_id'] . '">' . $data['name'] . '</a></li>';
        }
        echo '</ul>';
       
        ob_end_flush();
    }
    else
    {
        $fn_category = $show_category;
        include $fn_directory . '/news.php';
    }

    ?>
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm

Re: category browsing

Postby Blackshadow » Wed Dec 30, 2009 1:57 pm

Looks like there's something wrong with the code I gave you :p

This line:
Code: Select all
include $fn_directory . 'common.php';

Should have a / before common.php:
Code: Select all
include $fn_directory . '/common.php';


Try making that change and see what happens.
~ Blackshadow
Fusion News Developer
User avatar
Blackshadow
Fusion News Developer
 
Posts: 1296
Joined: Tue Oct 17, 2006 8:10 pm
Location: UK

Re: category browsing

Postby UndercoverAndrey » Wed Dec 30, 2009 11:35 pm

alright got that done, so now im able to generate this page

is there a way to link to those categories from within the website itself and not a separate page?

what i'm trying to say is, it works as its own page http://www.clearnonsense.com/cats.php

however, when i try to integrate it into my website itself, this happens http://clearnonsense.com/index.php?id=cats


thanks =]
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm

Re: category browsing

Postby joshua.s.belanger » Thu Dec 31, 2009 3:42 pm

I think this will work for your site:

Replace cats.php with this:
Code: Select all
<?php
// EDIT THIS HERE
    $fn_directory = '/home/clear/public_html/news';

        include $fn_directory . '/common.php';
   
      ob_start();
      
    $category_file = file ($fn_directory . '/categories.php');
    array_shift ($category_file);

    $categories = array();
     
    echo '<ul>';
    foreach ( $category_file as $category )
    {
        $data = get_line_data ('categories', $category);
        echo '<li><a href="?&amp;show_category=' . $data['category_id'] . '">' . $data['name'] . '</a></li>';
    }
    echo '</ul>';
       
    ob_end_flush();      
?>


Then open your index.php page... On the top where you want the category links put this:
Code: Select all
<?php

include 'cats.php';

?>


Then below where you want the news to show put:
Code: Select all
<?php

$show_category = isset ($_GET['show_category']) ? (int)$_GET['show_category'] : 1;
$fn_category = $show_category;
include 'news/news.php';

?>


This will show your category #1 by default. You can change that by changing the number at the end of this line:
Code: Select all
$show_category = isset ($_GET['show_category']) ? (int)$_GET['show_category'] : 1;
-Josh
User avatar
joshua.s.belanger
FN Follower
 
Posts: 249
Joined: Wed Jun 03, 2009 2:54 pm

Re: category browsing

Postby UndercoverAndrey » Thu Dec 31, 2009 10:14 pm

thanks josh, the code works

EDIT: scratch the question i had, I figured it out. thanks a lot for everyone's help & happy new year
User avatar
UndercoverAndrey
FN User
 
Posts: 35
Joined: Thu Dec 24, 2009 11:18 pm


Return to Help and Support

Who is online

Users browsing this forum: No registered users and 1 guest