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 Automaticaly show headlines of the same category below an article
Groefie
Posted on 05 Jul 2010, 17:05:28

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

I'm not sure if this is possible, but I like to show headlines of the same category below an article on the full story page.

For example, at the moment when someone clicks on the 'read more' link, the 'full article-page' (in my case bericht.php) opens with the full article on it. This is great but it should be even nicer if it's possible to show - let's say the last 30 - headlines from the same category below that full story. I tried this with

<?php
$template = 'full';
include('content/index.php');
?>
<br />
<?php
$static = 'true';
$nppage = '30';
$template = 'headlines';
include 'content/index.php';
?>

in the 'bericht.php' page but this also shows the headlines of the other categories. When i should use for example

<?php
$template = 'full';
include('content/index.php');
?>
<br />
<?php
$static = 'true';
$cat[] = 'Entertainment';
$nppage = '30';
$template = 'headlines';
include 'content/index.php';
?>

only headlines from the entertainment category will be shown, but as I use the same 'bericht.php' page for all categories only the entertainment headlines are shown also below a full article of another category.

Of course I can use different templates and full story pages for each category but maybe there is an easier solution to work this out?
#2610
Chris
Posted on 05 Jul 2010, 19:26:48

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

This would be possible with a bit of custom code.

On your bericht.php file that displays the full article, just below where you have your normal include code which looks something like this

Code:
<?php
include 'news/index.php';
?>


Add the following code so it looks like this

Code:
<?php
include 'news/index.php';

// custom code for displaying news articles that are assigned to the same category as the one displayed above.
// Grab all categories that the above article is assigned to then assign them to the $cat array then do another include
if($_GET['id']){
    require_once(
'news/db.php');
    require_once(
'news/config.php');
    
    
$cat = array();
    
$assignedcats = array();
    
$assignedcats = DataAccess::fetch("SELECT news30_cats.name AS catname FROM news30_groupcats
            LEFT JOIN news30_cats ON news30_groupcats.catid = news30_cats.id
            WHERE storyid = ?"
, $_GET['id']);
    foreach(
$assignedcats AS $cats){
            
$cat[] = $cats['catname'];
    }
    
$static = true;
    
$template = 'headlines';
    include 
'news/index.php';
}
?>


Now when you view a full article, any articles which are assigned to the same category will be displayed below.
#2613
Last edited by Chris at 2010-07-05 19:28:55 Reason:
Groefie
Posted on 05 Jul 2010, 19:53:55

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

thanks. I tried this with this code (I use a folder named 'content' instead of 'news') but too bad it gives no output below the full article. The template 'headlines' does exist.

<?php
$template = 'full';
include('content/index.php');

if($_GET['id']){
require_once('content/db.php');
require_once('content/config.php');

$cat = array();
$assignedcats = array();
$assignedcats = DataAccess::fetch("SELECT news30_cats.name AS catname FROM news30_groupcats
LEFT JOIN news30_cats ON news30_groupcats.catid = news30_cats.id
WHERE storyid = ?", $_GET['id']);
foreach($assignedcats AS $cats){
$cat[] = $cats['catname'];
}
$static = true;
$template = 'headlines';
include 'content/index.php';
}
?>
#2614
Chris
Posted on 05 Jul 2010, 20:04:26

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

If you're using friendly URLs change it to this

Code:
<?php
include 'news/index.php';

if(
$url['0']){
    require_once(
'../news/db.php');
    require_once(
'../news/config.php');
    
    
$cat = array();
    
$assignedcats = array();
    
$assignedcats = DataAccess::fetch("SELECT news30_cats.name AS catname FROM news30_groupcats
            LEFT JOIN news30_cats ON news30_groupcats.catid = news30_cats.id
            WHERE storyid = ?"
, $url['0']);
    foreach(
$assignedcats AS $cats){
            
$cat[] = $cats['catname'];
    }
    
$static = true;
    
$template = 'headlines';
    include 
'../news/index.php';
}
?>
#2615
Groefie
Posted on 05 Jul 2010, 20:35:59

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

with ../ it didn't work but with ./ it does! Thanks a lot!
#2616
Chris
Posted on 05 Jul 2010, 22:15:18

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

Ah yes the ../ was left there by mistake. Glad it's working :D
#2619
Groefie
Posted on 07 Jul 2010, 12:25:07

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

it seems to work fine, except for 1 digit story id's (id's below 10). Below them the headlines of all categories/articles are displayed instead of only the ones of the same category. Any idea how to solve this?
#2639
Chris
Posted on 09 Jul 2010, 18:31:41

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

Try this instead

Code:
<?php
include 'news/index.php';

if(
$url['0']){
    require_once(
'../news/db.php');
    require_once(
'../news/config.php');
    
    
$cat = array();
    
$assignedcats = array();
    
$assignedcats = DataAccess::fetch("SELECT news30_cats.name AS catname FROM news30_groupcats
            LEFT JOIN news30_cats ON news30_groupcats.catid = news30_cats.id
            WHERE storyid = ? AND type = 'news'"
, $url['0']);
    foreach(
$assignedcats AS $cats){
            
$cat[] = $cats['catname'];
    }
    
$static = true;
    
$template = 'headlines';
    include 
'../news/index.php';
}
?> 
#2653
Network-13.com © 2013