VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Meton on January 20, 2016, 16:54:15 PM

Title: Create a Meta based on URL
Post by: Meton on January 20, 2016, 16:54:15 PM
Hi guys,

Maybe this question is more for a joomla forum but ill give it a go here.

I am experiencing a couple of issues with the meta and title tags in virtuemart. As a example when you create a manufacturer and link to a catagory with the manufacturer there is no way to set a meta desc and title.

Example, when you create a link to:

URL/product/manufacturer/name/catagory

-----------------------------------------

What i would like to do is create a small script in php that looks at a URL and replaces the meta data and title. example

if url = /product/manufacturer/brandA/catagory{

set meta description to xxxxx
}

Does anyone know how this is done or a good extention to do this?

Kind regards,

Meton
Title: Re: Create a Meta based on URL
Post by: Studio 42 on January 20, 2016, 18:48:57 PM
You can get meta tag, if manufacturer ID is set and add the manufacturer name, after or before and resend back to Joomla the meta

this is the base code:
$mid = vRequest::getInt('virtuemart_manufacturer_id');
if($mid) {
$doc = JFactory::getDocument();
$metaDesc= $doc->getDescription();
$doc->setDescription($metaDesc.' '.$this->product->mf_name) ;
}
Title: Re: Create a Meta based on URL
Post by: Meton on January 21, 2016, 13:48:36 PM
Quote from: Studio 42 on January 20, 2016, 18:48:57 PM
You can get meta tag, if manufacturer ID is set and add the manufacturer name, after or before and resend back to Joomla the meta

this is the base code:
$mid = vRequest::getInt('virtuemart_manufacturer_id');
if($mid) {
$doc = JFactory::getDocument();
$metaDesc= $doc->getDescription();
$doc->setDescription($metaDesc.' '.$this->product->mf_name) ;
}


Hi m8, thank you for your reply.

The problem is i cannot set the meta data for subs of a manufacturer. (brand\catagory).
Title: Re: Create a Meta based on URL
Post by: Meton on January 21, 2016, 14:01:20 PM
Hi All,

Just to check, I have written a simple code that seems to do the job. Did i do this correctly, am i in any risk of breaking default functions?

The code:



$oudeTitle = $this->getTitle();
$oudeDesc = $this->getDescription();

if (preg_match("/merk.*?bruder.?$/" , $this->base)){
$title = 'Bruder';
$metadesc ='Meta brand desc';
}

elseif (preg_match("/merk.*?bruder.*?aanhangers.?$/" , $this->base)){
$title = 'aanhanger meta title';
$metadesc ='brand subs meta.';

}

elseif (preg_match("/merk.*?bruder.*?accessoires.?$/" , $this->base)){
$title = 'accessoires';
$metadesc ='Meta desc accessoires';

}

else{

echo '<b>GEEN DATAWIJZIGING!</b> <br><br>';
};



$this->setTitle($title);
$this->setDescription($metadesc);
$this->setMetaData('title',$title);

echo '<b>OUDE GEGEVENS:</b> <br>';
echo '<b>Meta title:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '.$oudeTitle . '<br>' ;
echo '<b>Meta desc:</b>&nbsp;&nbsp;&nbsp;&nbsp; '.$oudeDesc. '<br><br>' ;

echo '<b>NIEUWE GEGEVENS:</b> <br>';
echo '<b>Meta title:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$this->getTitle(). '<br>' ;
echo '<b>Meta desc:</b> &nbsp;&nbsp;&nbsp;&nbsp;'.$this->getDescription(). '<br><br>' ;

?>


I did not take the time to write a function so please forgive me :P

Kind regards,

Meton
Title: Re: Create a Meta based on URL
Post by: Studio 42 on January 22, 2016, 17:39:29 PM
Meta description, need to be encoded corrretly and no HTML !!! only simple text