Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: [MOD] Meta description & keywords for search engines (sNews 1.4)  (Read 15405 times)

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567

I noticed that the meta tag description was always the same one for each article and i think that it is not a good thing for googlebot ;)

I modified the function title so that it is the first 60 characters of the article.

The title function:
Code: [Select]
// TITLE
function title() {
echo "";
        $article_title = get_id('article');
if ($article_title == "") {
$title = s('website_title');
} else {
$query = "SELECT * FROM " .s('prefix'). "articles WHERE seftitle = '$article_title'";
$result = mysql_query($query);
//******************added********************************
                $query2 = "SELECT text FROM " .s('prefix'). "articles WHERE seftitle = '$article_title'";
                $result2 = mysql_query($query2);
                $line = mysql_fetch_array($result2);
$description = substr(strip_tags($line[0]),0,60);
/********************************************************
while ($r = mysql_fetch_array($result)) {
$title = s('website_title'). " » ". $r['title'];
}
}
echo "" .$title. "";

        //*** meta tag description
echo "n";
        //**********************

javascript_headers();
}
Is there a better solution?
Logged

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #1 on: March 26, 2006, 10:50:20 am »

Interesting work avenir ;)

In my opinion what we really need is the ability to add a metatag description and keywords at editing time..taking this further we could also add a tag field which could then tie into the search function..so you could search by tags, display a tag cloud type of effect, or display a 'related articles' section.
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

albert

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 405
    • http://www.oswt.co.uk/
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #2 on: March 26, 2006, 12:22:58 pm »

Hi

Not sure if thier is a better solution but it is a great start. Have you tested this code ?

Now the next stage is to make Keywords :) :: pull from artical or add to data base,

If data base is the only way then adding
the description would be easy to as well.

Albert

Quote from: avenir
I noticed that the meta tag description was always the same one for each article and i think that it is not a good thing for googlebot ;)

I modified the function title so that it is the first 60 characters of the article.

The title function:
Code: [Select]
// TITLE
function title() {
echo "";
        $article_title = get_id('article');
if ($article_title == "") {
$title = s('website_title');
} else {
$query = "SELECT * FROM " .s('prefix'). "articles WHERE seftitle = '$article_title'";
$result = mysql_query($query);
//******************added********************************
                $query2 = "SELECT text FROM " .s('prefix'). "articles WHERE seftitle = '$article_title'";
                $result2 = mysql_query($query2);
                $line = mysql_fetch_array($result2);
$description = substr(strip_tags($line[0]),0,60);
/********************************************************
while ($r = mysql_fetch_array($result)) {
$title = s('website_title'). " » ". $r['title'];
}
}
echo "" .$title. "";

        //*** meta tag description
echo "n";
        //**********************

javascript_headers();
}

Is there a better solution?

Logged
Albert
http://snews.awddesign.co.uk/snews/ site: v1.3
http://snews.awddesign.co.uk/           site: v1.2 http://www.awddesign.co.uk/
“Putting together the largest collection of sNews 1.5 designs. Coming very soon :)

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #3 on: March 30, 2006, 10:53:24 pm »

Ok i have found a good solution  (ability to add a metatag description and keywords at editing time)  ;D

*************************************************
       DESCRIPTION_META MOD

         Add a metatag description and  keywords
         for each article.
*************************************************

1. Add two columns at the end of the articles table with these sql commands:

ALTER TABLE articles ADD description_meta CHAR(100);
ALTER TABLE articles ADD keywords_meta CHAR(100);

2. Modify the snews.php file:

2.a. Add these lines in ADMINISTRATION LANGUAGE VARIABLES

Code: [Select]
//**** for description mod ***
$l['description_meta'] = "Description META Tag (for search engines)";
$l['keywords_meta'] = "Keywords META Tag (keywords separated with a comma)";
//*************************
2.b. Modify the title() function:

Code: [Select]
// TITLE
function title() {
echo "";
    $article_title = get_id('article');
if ($article_title == "") {
$title = s('website_title');
} else {
$query = "SELECT * FROM " .s('prefix'). "articles WHERE seftitle = '$article_title'";
$result = mysql_query($query);
 
while ($r = mysql_fetch_array($result)) {
$title = s('website_title'). " » ". $r['title'];
       //***************for description_meta mod ************************
$description_meta = $r['description_meta'];
$keywords_meta = $r['keywords_meta'];
//****************************************************************
}
}
echo "n" .$title. "";
//************** for description_meta mod ***************************************************************
if (description_meta != "") echo "\n";
     if($keywords_meta != "") echo "\n\n";
//*******************************************************************************************************

javascript_headers();
}
2.c. Modify new_article() function (line ~1193) :
Code: [Select]
function new_article() { ?>


 
   


 

:


   

'.l('make_sef_text').''); ?>
   


   

:


   


   





:



       

:


   





     

:


     


     


....

2.d. Modify edit_article($mode) function (line ~1346) :


Code: [Select]
function edit_article($mode) { ?>
         

$id = $_REQUEST['id'];
  $query = mysql_query("SELECT * FROM " .s('prefix'). "articles WHERE id='$id'");
  $r = mysql_fetch_array($query);
  $article_category = $r['category']; ?>
 


 
   

:


   

'.l('make_sef_text').''); }; ?>


   
   

:


   




:



:






   
     

:


.....
2.e. Modify processing() function (line ~1538) :

Code: [Select]
function processing() {
if ($_SESSION['Logged_In'] != True) {
echo "

". l('admin_error') ."

".l('error_not_logged_in')."

";
return 0;
};

$action = $_REQUEST['action'];
  $id = $_REQUEST['id'];
  $commentid = $_POST['commentid'];
  $name = str_replace("'", "'", $_POST['name']);
  $category = $_POST['category'];
  $description = $_POST['description'];
  $title = str_replace("'", "'", $_POST['title']);
  $seftitle = $_POST['seftitle'];

//**************** for description mod *******************
$description_meta = str_replace("'", "'", $_POST['description_meta']);
$keywords_meta = str_replace("'", "'", $_POST['keywords_meta']);
//*****************************************************

    $comment = str_replace("'", "'", $_POST['editedcomment']);
  $text = str_replace("'", "'", $_POST['text']);

    ....
In the same function, line ~1650, in the ** if ($_POST['task'] == "new") ** section, replace
   
Quote
$query = "INSERT INTO ". s('prefix'). "articles(title,seftitle,text,textlimit,date,category,position,displaytitle,displayinfo,commentable,image,published) VALUES('". $title ."', '". $seftitle ."', '". $text ."', '". $text_limit ."', '". $date ."', '". $category ."', '". $position ."', '". $display_title ."', '". $display_info ."', '". $commentable ."', '". $image ."', '". $fpublished ."')";
by
   
Code: [Select]
//********* changed for description mod *************
$query = "INSERT INTO ". s('prefix'). "articles(title,seftitle,text,textlimit,date,category,position,displaytitle,displayinfo,commentable,image,published,description_meta,keywords_meta) VALUES('". $title ."', '". $seftitle ."', '". $text ."', '". $text_limit ."', '". $date ."', '". $category ."', '". $position ."', '". $display_title ."', '". $display_info ."', '". $commentable ."', '". $image ."', '". $fpublished ."','".$description_meta."','".$keywords_meta."')";
//***********************************************
In the ** if ($_POST['task'] == "advancededit") ** section, ADD these blue lines:
   
Quote
} else if ( check_if_unique('article_seftitle', $seftitle, $id) ) {
            echo "

". l('admin_error') ."

" .l('error_article_seftitle_exists'). "

";
               edit_article(advanced);
            unset($_SESSION['temp']);
         } else {
               mysql_query("UPDATE ". s('prefix'). "articles SET title='$title' WHERE id='$id'");
               mysql_query("UPDATE ". s('prefix'). "articles SET seftitle='$seftitle' WHERE id='$id'");
      

       //************* ADD for description mod *******************
         mysql_query("UPDATE ". s('prefix'). "articles SET description_meta='$description_meta' WHERE id='$id'");
         mysql_query("UPDATE ". s('prefix'). "articles SET keywords_meta='$keywords_meta' WHERE id='$id'");
   //**************end ADD ************************************


               mysql_query("UPDATE ". s('prefix'). "articles SET text='$text' WHERE id='$id'");
               mysql_query("UPDATE ". s('prefix'). "articles SET textlimit='$text_limit' WHERE id='$id'");
            
            ...
************************************************************
I have tested this mod and it works very well. Come now googlebot  ;D


screenshot:

Logged

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #4 on: April 01, 2006, 08:24:24 am »

I will test this later avenir, but if this works as well as I'm sure that it will..a big thankyou from me personally for your coding.

Many say that these tags are no longer useful for many search engines, but the point is, it doesn't hurt to have them as long as you play by the rules and don't 'stuff' them with misleading terms..I can't personally see the day when you would get banned or de-ranked for using them.

thanks again..excellent work ;D

now here's a challenge for you..alter the search function so that it will search in the keywords_meta field also..this could be useful for some..

and after that..write a new function that displays 'related items' based on the same field, so this could be displayed after an article, or alongside it, of course with the option to select the number of displayed items

now that would be really cool for article sites! ;D
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #5 on: April 01, 2006, 10:52:51 am »

thanks bryn!

Yes 'related items' & possibility to search on keywords is a good thing for all  :)

For exemple, in the search editbox, we could write "keywords:keyword1,keyword2,...". It is easy also to sort by categories...

We can also create a related(keywords, n) function...

I will concentrate myself on the problem  ;D
Logged

Tjobbe

  • Full Member
  • ***
  • Karma: 0
  • Posts: 112
    • http://www.farstyle.com
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #6 on: April 05, 2006, 06:16:03 pm »

so what do I add in the index.php for it to call the meta?

i added the mod bit by bit as outlined below.

This is a greta mod if I can get it to work, well done avenir!
Logged

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #7 on: April 05, 2006, 06:40:51 pm »

thanks Tjobbe  8)

Just add in in the header of your index.php file just before .

Logged

Tjobbe

  • Full Member
  • ***
  • Karma: 0
  • Posts: 112
    • http://www.farstyle.com
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #8 on: April 06, 2006, 11:00:16 am »

Quote from: avenir
thanks Tjobbe  8)

Just add in in the header of your index.php file just before .



OK, so I uploaded the wrong snews.php file!

Woops!
Logged

harry

  • Newbie
  • *
  • Karma: 1
  • Posts: 37
    • http://www.thebusinesscardshop.net/order/
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #9 on: April 10, 2006, 10:59:36 am »

Avenir thankyou for this great mod!  ;D.

Took me a while to get it going, but it's up and running now and works great!

I only have the index page indexed by google (for my news section) (maybe due to missing descriptions and keywords.), hopefully i can see some more pages indexed by the help of this mod! Again thankss  :-*

gomisan

  • Full Member
  • ***
  • Karma: 0
  • Posts: 194
    • http://fish-cam.net/
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #10 on: April 17, 2006, 07:26:17 am »

I've added this mod to my fish-cam site, it'll take a whiel for me to go through and update all the keywords etc, but it's a great idea.

However.. my index.php has hardcoded meta-tags that I'd like to keep, I really don't want to have to re-write my core tags every time. So how do search engines interpret 2 sets of tags?

Do they treat them as one? or do they ignore some of them?

Iif they ignore some, is there a way to set some 'default tags, and default description that gets inserted at the start of the tags? Can ths be done in the variables we setup for the site?

Example: say i want my Description to read: "Freshwater Tropical Webcam" on every page and my keywords "tropical, webcam, aquarium" then they should be defined in snews.php, and this mod could ADD keywords and description information.

So a page on 'Clown Loaches' (just for example) I'd just add "Fish Care information" and "clown loach"  to the respective fields as I edit the page, but the meta tags would read: "Freshwater Tropical Webcam, Fish Care information" and  "tropical, webcam, aquarium, clown loach" (yes those commas would need to be inserted too.)

Hope that is clear, and hope someone can help with the code.
Logged
Check out my sNews powered Tropical Fishtank site, live Fish-Cam !!

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #11 on: April 17, 2006, 10:48:03 am »

Hey Gomisan, it's easy  ;D

1. ADD these lines in your GLOGAL SETTINGS:

Code: [Select]
$s['description_meta_suffix'] = "Fish Care information";
$s['keywords_meta_suffix'] = "clown loach";

2. Modify title function():


CHANGE
Code: [Select]
while ($r = mysql_fetch_array($result)) {
$title = s('website_title'). " » ". $r['title'];
$description_meta = $r['description_meta'];
$keywords_meta = $r['keywords_meta'];
}
}
echo "n" .$title. "";
if($description_meta != "") echo "n";
if($keywords_meta != "") echo "n";

javascript_headers();
TO

Code: [Select]
while ($r = mysql_fetch_array($result)) {
$title = s('website_title'). " » ". $r['title'];
$description_meta = $r['description_meta'];
$keywords_meta = $r['keywords_meta'];
}
}
echo "n" .$title. "";
//*************** CHANGE THESE TWO LINES *****************************
if($description_meta != "") echo "\n";
if($keywords_meta != "") echo "\n";

//********************************************************************

javascript_headers();
I haven't tested this code...tell me if it works  ;)
Logged

gomisan

  • Full Member
  • ***
  • Karma: 0
  • Posts: 194
    • http://fish-cam.net/
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #12 on: April 17, 2006, 11:58:47 am »

It works... sort of.

If a field is completed for the article the meta tags show properly. But if the article has no meta tag information added, the default stuff doesn't show either.

If you are at a page like the home page, no meta tag information at all is shown, which is bad. The concept howeveer is sound, and if I get time I'll look at how it can be implemented better, I just have to get a site online first ... last minute job.
Logged
Check out my sNews powered Tropical Fishtank site, live Fish-Cam !!

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #13 on: April 17, 2006, 12:19:35 pm »

ok in the title function, try something like that:

Code: [Select]
while ($r = mysql_fetch_array($result)) {
$title = s('website_title'). " » ". $r['title'];
$description_meta = $r['description_meta'];
$keywords_meta = $r['keywords_meta'];
}
}
 echo "n" .$title. "";
//*************** CHANGE THESE LINES *****************************
if($description_meta != "") echo "n";
  else echo "n";

if($keywords_meta != "") echo "n";
  else echo "n";

//********************************************************************


Logged

Shaun Aneiros

  • Jr. Member
  • **
  • Karma: 2
  • Posts: 98
    • http://www.poorpeoplesparty.org
[MOD] Meta description & keywords for search engines (sNews 1.4)
« Reply #14 on: April 18, 2006, 08:02:28 am »

So now that I have to re-install my entire website, I really wanna add this, is there an updated code that we could display, that fixes all the bugs/problems people had with this?
Logged
Why does my daughter like me to pose for pictures with my angry face?
Pages: [1] 2 3