문제

I read this officail Joomla article about Microdata: http://docs.joomla.org/Microdata

I tried put this meta element in the head section of my Joomla website:

<meta itemprop="name" content="title of your content">

By this code:

$scope="itemprop";
$property="name";
$content="title";

JMicrodata::htmlMeta($content, $property, $scope = '', $inverse = false);

But no success! Can somebody tell me whats the wrong?

도움이 되었습니까?

해결책

Solutions

To add this meta tag in you <head> section of a Joomla website:

<meta itemprop="name" content="title of your content">

You can use one of the following solutions

1) Add this code in the <head> section:

echo JMicrodata::htmlMeta($content = 'title', $property = 'name');

2) In whatever part of your code/file you want:

$microdata = JMicrodata::htmlMeta($content = 'title', $property = 'name');
$document  = JFactory::getDocument();
$document->addCustomTag($microdata);

Documentation help

JMicrodata::htmlMeta() is used for output microdata semantics in a meta tag, this method does not add the meta tag in the <head> section.

I see you use $scope="itemprop", which is wrong, the scope is used to specify the Type of microdata, here you can find the full list of the available Types http://schema.org/docs/full.html

I suggest you to use an instance of JMicrodata, this way you don't need to worry that microdata is displayed properly.

$microdata = new JMicrodata('Article');
echo $microdata->content('title')->property('name')->display('meta');

다른 팁

In the <head> section add

<?php 
$property="name";
$content="title";
echo JMicrodata::htmlMeta($content, $property, '', false);
 ?>

That will definitely get you the metadata.

Elsewhere if you did

$property="name";
$content="title";
$microdata = JMicrodata::htmlMeta($content, $property, '', false);
$document  = JFactory::getDocument();
$document->addCustomTag($microdata);

That should do the trick.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top