Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Change meta description  (Read 455 times)

mailos

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
Change meta description
« on: July 26, 2012, 11:59:31 PM »

I need to get a description of the specified number of characters from the article. For example, the first 100 characters. How to do it in the meta descriptions:

<meta name="description" content="'.(!empty($_DESCR)? $_DESCR: s('website_description')).'" />

The selected point I would like to automatically get the last 100 characters of the article. How to do it. Thanks in advance.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Change meta description
« Reply #1 on: July 27, 2012, 03:21:19 AM »

Up above function title(), where your <meta name="description" string is located, is the // globals section. The last string in that section is:
Code: [Select]
<?php // disregard opening PHP tag, for coloration only

if(!empty($R['description_meta']))  $_DESCR $R['description_meta']; else $_DESCR $R['description'];

// disregard closing PHP tag, for coloration only ?>


It basically says that IF the description_meta value for the article (in the articles dbase table) is not empty (there is one), use it as the value for $_DESCR - else (if it is empty) - use the other value.

The data-type for description_meta in the articles dbase table is varchar(255) so it will accept up to 255 characters max. When you are creating your article, you could simply copy the first 100 or so characters of your article and paste it into the "Description META Tag (for search engines):" field in the "Customize" panel for the article before saving it. It will then be generated as the meta description tag in the title() function... and show up in the <head> source code of your page for search engines to find and use.

I would not modify the snews.php file to automatically pull the first 100 characters of any article as the value you want in the title() function. That would require a new function above the title() function with a fair bit of code in it.  8)
« Last Edit: July 27, 2012, 03:42:51 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mailos

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
Re: Change meta description
« Reply #2 on: July 27, 2012, 09:57:25 AM »

The fact that I can copy this I know, but I did need to be done automatically, or you need to modify this function. I will add entries to the central panel and I have no place there for the description meta.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Change meta description
« Reply #3 on: July 27, 2012, 02:23:17 PM »

This is how I attempted to do what you are looking for yesterday. While it works for a couple of articles, it does not work for all articles everywhere... it leaves the description empty in some cases. And when viewing the home page article, the generated description content also includes the HTML tags from the articles table text... they need to be stripped out before being used in the meta description tag. But you can try this and see how it works at this point.

BEFORE modding, make a backup copy of your snews.php file in case you need to refresh (in case of terminal error).

1. We need to include the article text in the query used by function title().
In your snews.php file find (search for):
Code: [Select]
$Try_Article = mysql_query('SELECT
... and replace the string below it with:
Code: [Select]
a.id AS id, title, text, position, description_meta, keywords_meta,

2. Further down, in the //globals section, find:
Code: [Select]
if(!empty($R['category'])) $_CAT = $R['category'];
... and above it, insert:
Code: [Select]
<?php // ignore this tag, for coloration only

if(!empty($R['text'])) $_MDESC substr($R['text'],0,100); // defines new $_MDESC value as 1st 100 characters of article text

// ignore this tag, for coloration only 
?>


3. Next, find: function title() and in the global string below it, after the word global add $_MDESC, so it looks like:
Code: [Select]
global $_MDESC, $_ID, $categorySEF, $_DESCR, $_KEYW, $_TITLE, $_NAME, $_XNAME;
... this makes the value of the new $_MDESC available for use in the function.

4. And, lastly, replace your <meta name="description" string with the new one that will generate the first 100 characters of your article text as the string's content... with this new one:
Code: [Select]
<meta name="description" content="'.(!empty($_MDESC) ? $_MDESC : $_MDESC).'" />
« Last Edit: July 27, 2012, 02:40:22 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mailos

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
Re: Change meta description
« Reply #4 on: July 27, 2012, 11:23:00 PM »

It no works :(
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Change meta description
« Reply #5 on: July 31, 2012, 06:38:35 PM »

Just a suggestion: I wouldn't use a method like this. 

Read up on what Google recommends for the Meta Description:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=35624#1
Logged