Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums How To News filter by category
Sickboy
Posted on 22 Dec 2009, 16:15:32

Access: Member
Total Posts: 13
Joined: 2009-12-04

Hi Chris,
Im not sure if this question has been answered before as i cant seem to find anything about it on the forums but i integrated your script into my website with no issues up until now.

I have 4/5 types of news items i want to post on my site that i would like to assign to categories.

The issue i have is allowing the users to filter news by categories i have created.

Is this possible?

Any help is appeciated mate.

Thanks again

Ant
#1338
Chris
Posted on 22 Dec 2009, 19:00:05

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

There are a number of different ways you could tackle this. When you specify your news include you specify which categories you'd like to use, so you just need to figure out a way to allow users to select the categories then pass them to the news script.

The first way and probably the easiest would be to manually list your categories as hyperlinks, something like this

Code:
<a href="?cat=Category1">Category1</a>
<a href="?cat=Category2">Category2</a>


then for your news include code add this

Code:
<?php
$cat
[] = $_GET['cat']; #grab the category from the url
include 'news/index.php';
?>


This will work but it won't be perfect as it only lets the user specify one particular category.

Another way would be to create a form with some check boxes that would allow the user to select multiple categories. You could something like

Code:
<form method="post" action="">
<input type="checkbox" name="cat[]" value="Category1" /> Category1 <br />
<input type="checkbox" name="cat[]" value="Category2" /> Category2 <br />
<input type="checkbox" name="cat[]" value="Category3" /> Category3 <br />
</form>


Then for your news include to get the values of the check boxes the user has selected do this

Code:
<?php
$cat 
= $_POST['cat']; #grab the categories the user has selected using the check boxes
include 'news/index.php';
?>

#1341
Last edited by Chris at 2009-12-22 21:28:47 Reason:
Sickboy
Posted on 23 Dec 2009, 12:17:40

Access: Member
Total Posts: 13
Joined: 2009-12-04

thats fantastic dude thankyou.

I think the first option with the hyperlinks will work as i was going to make a seperate menu on my site with links to the different news categories.

Ill give this a go and get back to you if theres any issues.


Have a great Christmas and a Happy Newyear if i dont speak to you mate.


Ant
#1354
Network-13.com © 2013