Find PHP Code to add Meta tags in website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
laxminarayanlnt
Forum Newbie
Posts: 4
Joined: Fri Sep 04, 2009 8:28 am

Find PHP Code to add Meta tags in website

Post by laxminarayanlnt »

Find a PHP Code for adding meta tags in website.

Actually i my website meta tags are comming from database & client not given the database access.

My index page has following code-:

Code: Select all

 
<?php
require_once('config.php');
 
include_once(APP_DIR.'include/connect.php');
 
include_once(APP_DIR.'include/functions.php');
 
include_once(APP_DIR.'smarty.php');
 
include_once(APP_DIR.'globals.php');
 
$smarty->display("page_home.php");
 
?>
 
[color=#BF0000[b]]& globals.php [/b]
{ 
<?php
/////////////////////////////////////////////
//get page vars from DB
$query_page = "SELECT `name`, `value` FROM `vars` WHERE `name` LIKE '%$page%' ORDER BY `name` ASC";
$result_page = mysql_query($query_page);
$fields_page = fieldsNumDB($result_page);
$smarty -> assign("fields_page", $fields_page);
/////////////////////////////////////////////
//categories list
$query_cats = "SELECT * FROM `categories` WHERE `type` = '1'";
$result_cats = mysql_query($query_cats);
$cats = fieldsNumDB($result_cats);
$smarty -> assign("cats", $cats);
/////////////////////////////////////////////
//get current category items
if($category_id) {
    $query_items = sprintf("SELECT 
    `categories`.`id` AS `cat_id`,
    `categories`.`name` AS `cat_name`,
    `products`.`id`,
    `products`.`name`
        FROM
    `categories`
        INNER JOIN `products` ON (`categories`.`id` = `products`.`manufacturer_id`)
        WHERE
    (`categories`.`id` = %s) AND
    (`products`.`display` = 'Y')
    ORDER BY `products`.`color_type`,
    `product_order` DESC", $category_id);
    $result_items = mysql_query($query_items);
    $fields_items = fieldsNumDB($result_items);
    $smarty -> assign("fields_items", $fields_items);
}
/////////////////////////////////////////////
//get specials for index.php and services.php
if($page == "index" || $page == "specials") {
    //get item details
    $query_special = "SELECT 
      `categories`.`name` AS `cat_name`,
      `products`.`id`,
      `products`.`name` AS `item_name`,
      `products`.`short_desc`,
      `products`.`full_desc`,
      `products`.`points_specification`,
      `products`.`price_from`,
      `products`.`color_type`,
      `images`.`obrazok`,
      `products`.`meta_keywords`,
      `products`.`meta_description`
    FROM
      `products`
      LEFT JOIN `images` ON (`products`.`id` = `images`.`item_id`)
      INNER JOIN `categories` ON (`products`.`manufacturer_id` = `categories`.`id`)
    WHERE
      (`products`.`special` = 'Y') AND
    (`products`.`display` = 'Y')
    ORDER BY `cat_name`, `product_order` ASC";
    $result_special = mysql_query($query_special);
    $fields_special = fieldsNumDB($result_special);
    $smarty -> assign("fields_special", $fields_special);   
}
/////////////////////////////////////////////
//get specials all pages
// For Work Groups
$query_workgroups = "SELECT 
  `products`.`id`,
  `categories`.`id` AS `cat_id`,
  `categories`.`name` AS `cat_name`,
  `products`.`name` AS `item_name`,
  `products`.`short_desc`,
  `products`.`price_from`,
  `images`.`obrazok`
FROM
  `products`
  LEFT JOIN `images` ON (`products`.`id` = `images`.`item_id`)
  INNER JOIN `categories` ON (`products`.`manufacturer_id` = `categories`.`id`)
WHERE
(`products`.`special` = 'Y') AND
(`products`.`display` = 'Y')
AND
(`products`.`bw_speed` > 0 AND `products`.`bw_speed` < 31)    
ORDER BY `product_order` DESC";
 
$result_workgroups = mysql_query($query_workgroups);
 
$specials_workgroups = fieldsNumDB($result_workgroups);
 
$smarty -> assign("specials_workgroups", $specials_workgroups);
 
// For Departments
$query_departments = "SELECT 
  `products`.`id`,
  `categories`.`id` AS `cat_id`,
  `categories`.`name` AS `cat_name`,
  `products`.`name` AS `item_name`,
  `products`.`short_desc`,
  `products`.`price_from`,
  `images`.`obrazok`
FROM
  `products`
  LEFT JOIN `images` ON (`products`.`id` = `images`.`item_id`)
  INNER JOIN `categories` ON (`products`.`manufacturer_id` = `categories`.`id`)
WHERE
(`products`.`special` = 'Y') AND
(`products`.`display` = 'Y')
AND
(`products`.`bw_speed` > 29 AND `products`.`bw_speed` < 51)   
ORDER BY `product_order` DESC";
 
$result_departments = mysql_query($query_departments);
 
$specials_departments = fieldsNumDB($result_departments);
 
$smarty -> assign("specials_departments", $specials_departments);
 
// For Production
$query_production = "SELECT 
  `products`.`id`,
  `categories`.`id` AS `cat_id`,
  `categories`.`name` AS `cat_name`,
  `products`.`name` AS `item_name`,
  `products`.`short_desc`,
  `products`.`price_from`,
  `images`.`obrazok`
FROM
  `products`
  LEFT JOIN `images` ON (`products`.`id` = `images`.`item_id`)
  INNER JOIN `categories` ON (`products`.`manufacturer_id` = `categories`.`id`)
WHERE
(`products`.`special` = 'Y') AND
(`products`.`display` = 'Y')
AND
(`products`.`bw_speed` > 50)      
ORDER BY `product_order` DESC";
 
$result_production = mysql_query($query_production);
 
$specials_production = fieldsNumDB($result_production);
 
$smarty -> assign("specials_production", $specials_production);
 
// For Color
$query_color = "SELECT 
      `products`.`id`,
      `categories`.`id` AS `cat_id`,
      `categories`.`name` AS `cat_name`,
      `products`.`name` AS `item_name`,
      `products`.`short_desc`,
      `products`.`price_from`,
      `images`.`obrazok`
    FROM
      `products`
      LEFT JOIN `images` ON (`products`.`id` = `images`.`item_id`)
      INNER JOIN `categories` ON (`products`.`manufacturer_id` = `categories`.`id`)
    WHERE
      (`products`.`color_type` = 'C') AND
      (`products`.`special` = 'Y') AND
(`products`.`display` = 'Y')
    ORDER BY `product_order` DESC";
 
$result_color = mysql_query($query_color);
 
$specials_color = fieldsNumDB($result_color);
 
$smarty -> assign("specials_color", $specials_color);
 
/////////////////////////////////////////////
//get random text for 'speak' box
$query = "SELECT * FROM `rnd_text` WHERE `position` = 'speak'";
$result = mysql_query($query);
$rnd_text = fieldsNumDB($result);
$rnd_key = array_rand($rnd_text);
// Check string lenght
if(strlen($rnd_text[$rnd_key]['text']) > 190){
    $text_link = sprintf("\n<br /><a href=\"digital_copier_advices.php?text_id=%s\">Read More &raquo;</a>\n", $rnd_text[$rnd_key]['text_id']);
}
else{
    $text_link = '';
}
$smarty -> assign("speak_title", $rnd_text[$rnd_key]['title']);
$smarty -> assign("speak_text", $rnd_text[$rnd_key]['text']);
$smarty -> assign("speak_link", $text_link);
?>
}
Last edited by onion2k on Fri Sep 04, 2009 10:16 am, edited 1 time in total.
Reason: Added php tags.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Find PHP Code to add Meta tags in website

Post by onion2k »

Err.. what's the problem?
laxminarayanlnt
Forum Newbie
Posts: 4
Joined: Fri Sep 04, 2009 8:28 am

Re: Find PHP Code to add Meta tags in website

Post by laxminarayanlnt »

I want a php code to force fully print Meta tags in website without the use of database. Is its possible. Reply me at laxminarayan108@gmail.com
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Find PHP Code to add Meta tags in website

Post by onion2k »

laxminarayanlnt wrote:Is its possible.
Probably. But you're not giving us enough information to know if it's possible with the code you have at the moment. You need to think the problem through and give a lot more detail.

And noone is going to email you about this (unless they're trying to sell you their coding services).
laxminarayanlnt
Forum Newbie
Posts: 4
Joined: Fri Sep 04, 2009 8:28 am

Print a Meta tags with PHP Code.

Post by laxminarayanlnt »

I want a PHP Code to Print a Meta tags in Website.

Actually most of my client Website pages Meta Tags are comes from database And in database they show only description & Keywords i change the desc & Keywords with of database with query update - pass id and category name.

I want to change the title also so i need the php code with switch case pass category name & id to change the title. With particular id & category name the change the title of page and else they take a default title.


Regards
Laxmi Narayan
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Find PHP Code to add Meta tags in website

Post by onion2k »

If you have the code to fetch the content from the database then you can just use that again - change it from the form you use to edit the content to just display it in the correct tags.
Post Reply