Jump to content

meta data help


cerberus478

Recommended Posts

I would like to be able to have my meta data pick out the information of a page and insert it into the meta tags.

I have a controller class which has the coding to get the data, which is this:

controller.class.php

function get_title(){

	$title='';

	if (isset($this->_params['item']['meta_title'])  && !empty($this->_params['item']['meta_title'])){

		$title=$this->_params['item']['meta_title'];


	}

	$title=strip_tags($title);

	$title=str_replace('"', '\'', $title);

	$title=trim($title);

	if (strlen($title)>150){

		$end_of_last_sentence=strpos($title, '.', 150)+1;

	if ($end_of_last_sentence<150){

			$end_of_last_sentence=150;

		}

		$title=substr($title, 0, $end_of_last_sentence);

	}

		return $title;
}


function get_description(){


	$description='';

	if (isset($this->_params['item']['meta_description'])  && !empty($this->_params['item']['meta_description'])){

		$description=$this->_params['item']['meta_description'];

	}

	$description=strip_tags($description);

	$description=str_replace('"', '\'', $description);

	$description=trim($description);

	if (strlen($description)>150){

		$end_of_last_sentence=strpos($description, '.', 150)+1;

		if ($end_of_last_sentence<150){

			$end_of_last_sentence=150;

		}

		$description=substr($description, 0, $end_of_last_sentence);

	}

	return $description;

}


function get_keywords(){

	$keyword='';

	if (isset($this->_params['item']['meta_keyword'])  && !empty($this->_params['item']['meta_keyword'])){

		$keyword=$this->_params['item']['meta_keyword'];


	}

	$keyword=strip_tags($keyword);

	$keyword=str_replace('"', '\'', $keyword);

	$keyword=trim($keyword);

	if (strlen($keyword)>150){

		$end_of_last_sentence=strpos($keyword, '.', 150)+1;

		if ($end_of_last_sentence<150){

			$end_of_last_sentence=150;

		}

		$keyword=substr($keyword, 0, $end_of_last_sentence);

	}

	return $keyword;
	}

 

Then I have a pages.controller which has the coding for the home page

 

pages.controller.php

public function home(){
	//instantiate a model
	$galleries_model = new galleries_model('galleries');
	$galleries = $galleries_model -> get_all();


	foreach($galleries as $gallery){


		//how to loop through an image so that only the first
		//image is selected
		$sql = "SELECT image_path FROM gallery_images 
				WHERE 
						gallery_id = {$gallery['id']}
				ORDER BY order_by";

		$image = $this->_model->get_one($sql);

		$gallery['image'] = $image;
		$this->_params['list'][] = $gallery;

	}

	$this->_params['item'] = $this->_model->get(array("pages.name = 'home'"));

}

galleries.controller.php
public function galleries(){

	$galleries = $this->_model->get_all();


	$this->_params['list'] = $galleries;


}

public function view($gallery_id){

	$this->_params['item'] = $this->_model->get($gallery_id);

	$this->_params['item'] ;
	//die;

}

 

This is my default page where I want the meta tags to echo out the relevent information

 

default.php

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $this->get_title(); ?></title>
<meta name="Description" content="<?php echo $this->get_description(); ?>" />
<meta name="Keywords" content="<?php echo $this->get_keywords(); ?>" />
<title>Welcome to the Framework</title>
<?php
$this->_page->add_javascript('/vendor/lightbox/js/jquery.lightbox-0.5.min.js');
$this->_page->add_stylesheet('/vendor/lightbox/css/jquery.lightbox-0.5.css');
echo $this->page('stylesheets');
echo $this->page('javascripts');
?>

</head>
<body>


<h1>
Welcome to the My site
</h1>


<?php echo $this->page('view');?>
</body>
</html>

 

In the pages.controller.php  I managed to get it to work using $this->_params['item'] = $this->_model->get(array("pages.name = 'home'"));

 

I want to be able to do the same thing on different pages but I can't get it to work.

 

I hope I explained it clearly.

 

Thank you

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.