Topic: Cutenews 2.0: Page title & meta tags

Hi!

I upgraded my CuteNews yesterday from 153 to 2.0 and the problem is, I used to have a code in my old version which took the page title and the other meta tags, which for example Facebook uses, like description from the news.txt which is not used anymore as there's a folder of news instead.

My simple question goes: How can I get the page title as the same as full story's title is and description to match the couple of first lines of the article?

Re: Cutenews 2.0: Page title & meta tags

Hi!

I upgraded my CuteNews yesterday from 153 to 2.0 and the problem is, I used to have a code in my old version which took the page title and the other meta tags, which for example Facebook uses, like description from the news.txt which is not used anymore as there's a folder of news instead.

My simple question goes: How can I get the page title as the same as full story's title is and description to match the couple of first lines of the article?

Use (full_news page):

<?php 

require_once 'cutenews/cn_api.php';
$entry = cn_api_get_entry();
if ($entry['t']) 
{
     // ........
     $header_title = $entry['t'];

     print_r($entry);
}
Best regards,
CN Support team

3 (edited by 2013-10-04 13:42:39)

Re: Cutenews 2.0: Page title & meta tags

Worked a treat, thanks! How about getting image url from a piece of news for og:image meta tag? Didn't quite understand the structure of cn_api even though I tried.

edit. ofc, there it was in array, everything is fine now, thank you!

Re: Cutenews 2.0: Page title & meta tags

Use (full_news page):

<?php 

require_once 'cutenews/cn_api.php';
$entry = cn_api_get_entry();
if ($entry['t']) 
{
     // ........
     $header_title = $entry['t'];

     print_r($entry);
}

I tried to implement this code on my page, and all that it did was publish the story again, outside of the .css styling. It did not publish the title or description.  Could you clarify your instructions please?

Re: Cutenews 2.0: Page title & meta tags

hi everyone i love this site and i have visited this great website on fixed interval of time my maximum problem are solved from here. from their i have make a new website for content writing please visit.   Article blogs content writing

Re: Cutenews 2.0: Page title & meta tags

itz helpful https://cutephp.com/forum/style_emoticons/default/smile.gif

Re: Cutenews 2.0: Page title & meta tags

I tried to implement this code on my page, and all that it did was publish the story again, outside of the .css styling. It did not publish the title or description.  Could you clarify your instructions please?

By printing the Array to your web page (print_r as seen above), you can see the keys some of which has the sufficient information for eg. title, description, full story... etc. Some of the strings you have to parse with PHP to get what you want.

For example here is the code I'm using, $entry['t'] will print the title without the need of parsing the string, $entry['s'] has the short story and $entry['f'] contains the full story. I have fetched them with cn_api.php and then with some functions I have parsed them to what I want from the strings in question.

require_once 'cutenews/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";
      echo "<meta property=\"og:title\" content=\"".$header_title." \" />";
      echo "<meta property=\"og:image\" content=\"http://hcmeanmachine.com/cutenews/uploads/".$image."\"/>";
      echo "<meta property=\"og:description\" content=\"".$fdesc."\" />";
      
} else {
      
        echo "<title>Masiina » Uutiset</title>\n";
        echo "<meta property=\"og:title\" content=\"Masiina » Uutiset\" />";
    }

8 (edited by 2015-07-10 00:58:41)

Re: Cutenews 2.0: Page title & meta tags

Hi!

I upgraded my CuteNews yesterday from 153 to 2.0 and the problem is, I used to have a code in my old version which took the page title and the other meta tags, which for example Facebook uses, like description from the news.txt which is not used anymore as there's a folder of news instead.

My simple question goes: How can I get the page title as the same as full story's title is and description to match the couple of first lines of the article?

use screenshot this in home page

<?php

require_once 'cutenews/cn_api.php';
$entry = cn_api_get_entry();
if ($entry['t'])
{
     // ........
     $header_title = $entry['t'];

     print_r($entry);
}

Re: Cutenews 2.0: Page title & meta tags

By printing the Array to your web page (print_r as seen above), you can see the keys some of which has the sufficient information for eg. title, description, full story... etc. Some of the strings you have to parse with PHP to get what you want.

For example here is the code I'm using, $entry['t'] will print the title without the need of parsing the string, $entry['s'] has the short story and $entry['f'] contains the full story. I have fetched them with cn_api.php and then with some functions I have parsed them to what I want from the strings in question.

require_once 'cutenews/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";
      echo "<meta property=\"og:title\" content=\"".$header_title." \" />";
      echo "<meta property=\"og:image\" content=\"http://hcmeanmachine.com/cutenews/uploads/".$image."\"/>";
      echo "<meta property=\"og:description\" content=\"".$fdesc."\" />";
      
} else {
      
        echo "<title>Masiina » Uutiset</title>\n";
        echo "<meta property=\"og:title\" content=\"Masiina » Uutiset\" />";
    }

This code is brilliant. Just stumbled upon this thread and this is exactly what I needed.  https://cutephp.com/forum/style_emoticons/default/cool.gif

10 (edited by 2013-12-21 10:39:28)

Re: Cutenews 2.0: Page title & meta tags

Hey guys,

May I know if I can remove the following and will the code still work properly?

echo "<meta property=\"og:title\" content=\"".$header_title." \" />";
echo "<meta property=\"og:image\" content=\"http://hcmeanmachine.com/cutenews/uploads/".$image."\"/>";
echo "<meta property=\"og:description\" content=\"".$fdesc."\" />";

and

echo "<meta property=\"og:title\" content=\"Masiina » Uutiset\" />";

Thanks

Re: Cutenews 2.0: Page title & meta tags

i can't get this to work (title does not change). we're exactly do i need to paste this code on?

Re: Cutenews 2.0: Page title & meta tags

i can't get this to work (title does not change). we're exactly do i need to paste this code on?

Just replace  <title> </title> with that code

Re: Cutenews 2.0: Page title & meta tags

It works perfect for me, but for optimal SEO use, is it possible to use page alias as title? What would have to be changed to the code?

Re: Cutenews 2.0: Page title & meta tags

Guys I'm using this but I have a problem...I have different cutenews codes in the page and when I share the article with facebook I get the wrong preview...I don't get the article but another part of the page...but title is ok.

How can I fix it? https://cutephp.com/forum/style_emoticons/default/sad.gif

Re: Cutenews 2.0: Page title & meta tags

up

16 (edited by 2015-02-23 19:55:58)

Re: Cutenews 2.0: Page title & meta tags

Hello...

I use in this code in my newssite, with little changes:

<?php 

require_once '../scripts/artikelsystem/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 "
        <meta name=\"description\" content=\"".$fdesc."\" />
        <title>".$header_title."</title>
        ";
} else {
      
echo "
        <meta name=\"description\" content=\"MY DESCRIPTION.\" />
                <title>MY TITEL</title>
        ";
    }    

?>

Do anybody know how I can use the "short story" for the description instead of .$fdesc?

Because at the moment the description shows me the Titel in front and then some words from my test news (maybe the full story).

I only want the short story in the description without the news title in front.

Greetings
Peter

Re: Cutenews 2.0: Page title & meta tags

$fdesc is obtained from the variable $ rawdesc,which is initialized by the contents of full story ($ entry ['f']). If you want to replace it with short story, you need to modify the code so that variable $ str would be used instead of $rawdesc, which is initialized by the contents of short story ($entry['s']).

Best regards,
CN Support team

18 (edited by 2015-03-02 05:16:15)

Re: Cutenews 2.0: Page title & meta tags

$fdesc is obtained from the variable $ rawdesc,which is initialized by the contents of full story ($ entry ['f']). If you want to replace it with short story, you need to modify the code so that variable $ str would be used instead of $rawdesc, which is initialized by the contents of short story ($entry['s']).

Could you please be a little bit more clear?

- Which file I have to modify?
- For which line should I look?
- Should I only replace $rawdesc with $str?

I would appreciate an answer not only for coding specialists! ;-)

Greetings
Peter

Re: Cutenews 2.0: Page title & meta tags

After getting some support from a friend I changed easily:

$rawdesc = $entry['f'];

to

$rawdesc = $entry['s'];

to get the short story in my description meta tag.

Thank you anyway... ;-)

Peter

Re: Cutenews 2.0: Page title & meta tags

By printing the Array to your web page (print_r as seen above), you can see the keys some of which has the sufficient information for eg. title, description, full story... etc. Some of the strings you have to parse with PHP website to get what you want.

For example here is the code I'm using, $entry['t'] will print the title without the need of parsing the string, $entry['s'] has the short story and $entry['f'] contains the full story. I have fetched them with cn_api.php and then with some functions I have parsed them to what I want from the strings in question.

require_once 'cutenews/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";
      echo "<meta property=\"og:title\" content=\"".$header_title." \" />";
      echo "<meta property=\"og:image\" content=\"http://hcmeanmachine.com/cutenews/uploads/".$image."\"/>";
      echo "<meta property=\"og:description\" content=\"".$fdesc."\" />";
      
} else {
      
        echo "<title>Masiina » Uutiset</title>\n";
        echo "<meta property=\"og:title\" content=\"Masiina » Uutiset\" />";
    }

Worked a treat, thanks! How about getting image url from a piece of news for og:image meta tag? Didn't quite understand the structure of cn_api even though I tried.

edit. ofc, there it was in array, everything is fine now, thank you!

21 (edited by 2015-04-01 15:49:48)

Re: Cutenews 2.0: Page title & meta tags

Had the same problem, solved it thanks t o this post. THANKS!  https://cutephp.com/forum/style_emoticons/default/rolleyes.gif tried to imprimir too ...

Re: Cutenews 2.0: Page title & meta tags

Thanks a lot! helpfully! https://cutephp.com/forum/style_emoticons/default/smile.gif

Re: Cutenews 2.0: Page title & meta tags

Cant get this work... I used the script Admin provided earlier, if im right it should print only title of the news but i get id, title, full story and other stuff also. So, how can i print ONLY the news title? v. 2.0.4.