1 (edited by 2013-12-11 02:46:29)

Topic: CuteNews 2.0 How to add news headlines to page title?

Hello,

How can I add news headlines to my page title? Back in 1.5.x, there is this hack which I used it and it worked perfectly. This is the URL to the page title hack, https://cutephp.com/forum/index.php?showtopic=31743

I tried to use this in CuteNews 2.0 but it doesn't work.

Please help.

Thanks

Re: CuteNews 2.0 How to add news headlines to page title?

Hi,
I use this code in the balise <head> :

<?PHP require_once "../../news/cn_api.php";$entry = cn_api_get_entry();if ($entry['t']){$header_title = ($entry['t']);$short_story = ($entry['s']);$tagline = ($entry['tg']);$category_name  = ( join(' / ', $entry[':cot']) );$trunc_short = trim( (strip_tags($short_story)) );}echo '<title>'.$header_title.' - '.$category_name.'</title>';echo '<meta name="Description" content="'.$trunc_short.'"/>';echo '<meta name="news_keywords" content="'.$category_name.','.$tagline.'"/>';echo '<meta name="keywords" content="'.$category_name.','.$tagline.'"/>';echo '<meta property="og:title" content="'.$header_title.'"/>';echo '<meta property="og:description" content="'.$trunc_short.'"/>';echo '<meta property="twitter:title" content="'.$header_title.'"/>';echo '<meta property="twitter:description" content="'.$trunc_short.'"/>'; ?><?php if ($_GET['id']) echo '<link rel="canonical" href="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>'; ?><?php if ($_GET['id']) echo '<meta property="og:url" content="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>'; ?><?php if ($_GET['id']) echo '<meta name="twitter:url" content="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>'; ?>

3 (edited by 2013-12-15 13:05:39)

Re: CuteNews 2.0 How to add news headlines to page title?

Thanks Matt! Will try it out once I am free.

Sorry if I am asking too much but is there a cleaner version for this so I can understand the PHP code properly or could you explain to me how it work?

Re: CuteNews 2.0 How to add news headlines to page title?

Still looking for a better solution for this. Anyone?

Re: CuteNews 2.0 How to add news headlines to page title?

Hi,

It's the better solution...

Re: CuteNews 2.0 How to add news headlines to page title?

Hi,

I just tried your code and I added it to my <head> area but it doesn't work.

Do I need to change anything from the code?

Re: CuteNews 2.0 How to add news headlines to page title?

Hi sun,

Maybe look this : ../../news/cn_api.php
For you it could be ../name_of_files_cutenews/cn_api.php

8 (edited by 2014-03-13 02:02:38)

Re: CuteNews 2.0 How to add news headlines to page title?

hi, i am also looking for a solution to this. i tried your code but the title still hasn't changed.

how do i replace ../../news/cn_api.php if the page that's displaying my news is on the root folder and cute news is on a folder called news?

9 (edited by 2014-03-14 14:05:59)

Re: CuteNews 2.0 How to add news headlines to page title?

Easy. Add this to the webpage that is displaying CuteNews.

require_once 'yourcutenewsfoldername/cn_api.php';
$entry = cn_api_get_entry();

if ($entry['t'])
{
     // ........
     $header_title = $entry['t'];
     $str = $entry['s'];
     $rawdesc = $entry['f'];
    
function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
}

function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}

$rawdesc2 = stripBBCode($rawdesc);

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = "";
$sdesc = preg_replace($pattern, $replacement, $rawdesc2);
$fdesc = strip_tags($sdesc);

$image = get_string_between($str, "[img]", "[/img]");


      echo "<title>".$header_title."</title>\n";
      
} else {
      
        echo "<title>Your Website Title</title>\n";
    }

Your final code should be something like this,

<?php

$number="4";
$template = "default";
$PHP_SELF = "thepagewhereyoupost.php";
include("yourcutenewspath/show_news.php");
    
    
require_once 'yourcutenewsfolder/cn_api.php';
$entry = cn_api_get_entry();

if ($entry['t'])
{
     // ........
     $header_title = $entry['t'];
     $str = $entry['s'];
     $rawdesc = $entry['f'];
    
function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
}

function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}

$rawdesc2 = stripBBCode($rawdesc);

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = "";
$sdesc = preg_replace($pattern, $replacement, $rawdesc2);
$fdesc = strip_tags($sdesc);

$image = get_string_between($str, "[img]", "[/img]");


      echo "<title>".$header_title."</title>\n";
      
} else {
      
        echo "<title>Your Website Title</title>\n";
    }

?>

Change require_once 'yourcutenewsfolder/cn_api.php'; and <title>Your Website Title</title> to the correct path and name.

10 (edited by 2015-01-09 00:48:46)

Re: CuteNews 2.0 How to add news headlines to page title?

Guys I have a problem with this...

I have a sidebar which is also done with cutenews.

When I share on facebook I get the sidebar text description instead of the fullstory's article.

The code obviously is put in the "include" that has the fullstory and it is set to show only active news.
How the hell can I fix this?

11 (edited by 2015-02-23 18:54:43)

Re: CuteNews 2.0 How to add news headlines to page title?

Your final code should be something like this,

<?php

$number="4";
$template = "default";
$PHP_SELF = "thepagewhereyoupost.php";
include("yourcutenewspath/show_news.php");
    
    
require_once 'yourcutenewsfolder/cn_api.php';
$entry = cn_api_get_entry();

if ($entry['t'])
{
     // ........
     $header_title = $entry['t'];
     $str = $entry['s'];
     $rawdesc = $entry['f'];
    
function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
}

function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}

$rawdesc2 = stripBBCode($rawdesc);

$pattern = "/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
$replacement = "";
$sdesc = preg_replace($pattern, $replacement, $rawdesc2);
$fdesc = strip_tags($sdesc);

$image = get_string_between($str, "[img]", "[/img]");


      echo "<title>".$header_title."</title>\n";
      
} else {
      
        echo "<title>Your Website Title</title>\n";
    }

?>

Change require_once 'yourcutenewsfolder/cn_api.php'; and <title>Your Website Title</title> to the correct path and name.

It should not be directly as this. I put it on top to the other meta tags and let the code from the integration wizard in my main content section below. If you use the code, like you posted it, the title will be shown in the content code, where the rest of the body is and this would be not so seo friendly in my eyes. So I have to php code sections for this - one in the header, the other in the body.

Posts: 11

Pages 1

You must login or register to post a reply

CutePHP Forums → Problem Solving / Help & Support → CuteNews 2.0 How to add news headlines to page title?