1 (edited by 2009-01-23 16:55:42)

Topic: [HACK] Add news title and/or category to <title>

Name: Add news title and/or category to <title>
Author: Ifa
Updated: 18.11.2008
Cutenews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Adds the news title and/or category between your <title> tags
Instructions: This hack will add the news title and/or category that is currently viewed to the page title (<title></title>).
Add this code to your file that includes cutenews. Put this between the <head></head> tags. Change the $path = 'cutenews/data'; to match your cutenews folder. And change the <title>default title</title> to what you want the title to be when it's not the news title.

if (is_array($category)) $category = ' - '.implode(' - ', $category);

This line is for multiple categories. By default it seperates the categories with a -, ie "title - category1 - category2 - category3".
You can freely change both - to suit your needs, just keep the ' '. The same goes with the line below, only this is for a single category.

else $cat = ' - '.$title_values[1];

$title_values = title_values($_GET['id'], TRUE); // Change TRUE to FALSE if you dont use a category

Like it says, if you don't want category in your title, change TRUE to FALSE. This only saves the script some extra work.

function title_values($id, $use_category)
                $path = './cutenews/data';//CHANGE PATH TO THE CUTENEWS DATA DIRECTORY HERE
        if ($use_category)
            $cat_lines = file($path.'/category.db.php');
            foreach ($cat_lines as $cat_line)
                    $cat_array = explode('|', $cat_line);
                    $my_cats[$cat_array[0]] = $cat_array[1];

        $news_lines = file($path.'/news.txt');
        foreach ($news_lines as $news_line)
                $news_array = explode("|", $news_line);
                if ($news_array[0] == $id)
                        $title = strip_tags($news_array[2]);

                        if ($use_category and !empty($news_array[6]))
                                if (strstr($news_array[6], ','))
                                        $cat_array = explode(',', $news_array[6]);
                                        foreach ($cat_array as $category)
                                            $category_arr[] = $my_cats[$category];
                                else $category_arr = $my_cats[$news_array[6]];
        return array ($title, $category_arr);

if (isset($_GET['id']))
        $title_values = title_values($_GET['id'], true);//change true to false if the category doesn't need to be in the titlebar.
        $title = $title_values[0];
        if (is_array($title_values[1])) $cat = ' - '.implode(' - ', $title_values[1]);
        else $cat = ' - '.$title_values[1];

        echo '<title>'.$title.''.$cat.'</title>';

else echo '<title>Default Title</title>';

Posts: 1

Pages 1

You must login or register to post a reply

CutePHP Forums → Hacks & Tricks / FAQ → [HACK] Add news title and/or category to <title>

The pun_antispam official extension is installed. Copyright © 2003–2009 PunBB.