Actions

Difference between revisions of "Microdata"

From Joomla! Documentation

(How do I use Microdata?)
Line 9: Line 9:
  
 
Microdata can be used to explain just about anything you would ever want to explain, and there are more 'schemas' being added on a regular basis.  There are several vocabularies in existence, however at present the system favoured by search engines is that of [https://schema.org schema.org].
 
Microdata can be used to explain just about anything you would ever want to explain, and there are more 'schemas' being added on a regular basis.  There are several vocabularies in existence, however at present the system favoured by search engines is that of [https://schema.org schema.org].
 +
<br>
 +
Take a look at [https://www.youtube.com/watch?v=A-kX0Aut-18 this short video] to see how search engines use the Microdata information.
  
 
==How do I use Microdata?==
 
==How do I use Microdata?==
 
Microdata can be added to Joomla! using template overrides or with the use of plugins which allow you to insert microdata into specific resources.
 
Microdata can be added to Joomla! using template overrides or with the use of plugins which allow you to insert microdata into specific resources.
 
<br>
 
<br>
As of '''Joomla! 3.2''' there is a [https://github.com/joomla/joomla-cms/tree/master/libraries/joomla/microdata library] within Joomla! which allows developers to pull in microdata without needing to format it correctly. The following resources are available by the author of the microdata library introducing the library and how to use it:
+
<u>As of '''Joomla! 3.2''' there is a [https://github.com/joomla/joomla-cms/tree/master/libraries/joomla/microdata library] within Joomla! which allows developers to pull in microdata without needing to format it correctly</u>. The following resources are available by the author of the microdata library introducing the library and how to use it:
 
*http://magazine.joomla.org/issues/issue-oct-2013/item/1551-what-about-microdata-rich-snippets-in-joomla
 
*http://magazine.joomla.org/issues/issue-oct-2013/item/1551-what-about-microdata-rich-snippets-in-joomla
 
*https://gist.github.com/PAlexcom/6339949
 
*https://gist.github.com/PAlexcom/6339949
  
 +
==JMicrodata==
 +
[https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/microdata/microdata.php JMicrodata] (since version 3.2) is a [https://github.com/joomla/joomla-cms/tree/master/libraries/joomla/microdata library] to implement http://schema.org microdata semantics.
 +
<br>
 +
The JMicrodata class uses the [https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/microdata/types.json types.json] file which contains all available http://schema.org Types and Properties.
 +
<br>
 +
The types.json was automatically created with the https://github.com/PAlexcom/Spider4Schema web crawler.
 +
<br>
 +
<br>
 +
For some usage examples you can see the library test file https://github.com/joomla/joomla-cms/blob/master/tests/unit/suites/libraries/joomla/microdata/JMicrodataTest.php
 +
<br>
 +
<br>
 +
For a more detailed documentation of the library see the gist created by the author:
 +
<br>
 +
https://gist.github.com/PAlexcom/6339949
 +
 +
==How to use the JMicrodata library?==
 +
First of all you need to make an instance of the library in your extensions:
 +
<source lang="php">
 +
$microdata = new JMicrodata('Article');
 +
</source>
 +
So let's suppose that we have the following string which is part of your article and the current scope is <i>Article</i>:
 +
<source lang="php">
 +
echo 'Written by Alexandru Pruteanu';
 +
</source>
 +
And the microdata you need to add is an <i>author</i> property:
 +
<source lang="php">
 +
echo 'Written by' . $microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();
 +
</source>
 +
The library will display:
 +
<source lang="html4strict">
 +
Written by
 +
<span itemprop='author' itemscope itemtype='https://schema.org/Person'>
 +
    <span itemprop='name'>
 +
        Alexandru Pruteanu
 +
    </span>
 +
</span>
 +
</source>
 +
What happens if the current scope is something else than <i>Article</i>, for example a <i>Product</i> scope, and the current scope doesn't have an <i>author</i> property?
 +
<br>
 +
Well it will fallback in:
 +
<source lang="html4strict">
 +
Written by
 +
<span itemscope itemtype='https://schema.org/Person'>
 +
    <span itemprop='name'>
 +
        Alexandru Pruteanu
 +
    </span>
 +
</span>
 +
</source>
 +
If I want to disable the microdata semantics output?
 +
<br>
 +
You can simply disable the microdata output by calling the following function:
 +
<source lang="php">
 +
$microdata->enable(false);
 +
</source>
 +
The library will display the following:
 +
<source lang="html4strict">
 +
Written by Alexandru Pruteanu
 +
</source>
 
==How To implement Microdata yourself==
 
==How To implement Microdata yourself==
 
* [[How To Implement Rich Snippet for Breadcrumbs]]
 
* [[How To Implement Rich Snippet for Breadcrumbs]]
 
[[Category:Search Engine Optimisation]]
 
[[Category:Search Engine Optimisation]]

Revision as of 16:21, 12 December 2013

Quill icon.png
Content is Incomplete

This article or section is incomplete, which means it may be lacking information. You are welcome to assist in its completion by editing it as well. If this article or section has not been edited in several days, please consider helping complete the content.
This article was last edited by P.Alex (talk| contribs) 8 months ago. (Purge)


Contents

What is Microdata?

Documentation all together tranparent small.png
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by P.Alex (talk| contribs) 8 months ago. (Purge)

Microdata is a way of adding contextual information to your website and its contents, allowing search engines to better understand the information you provide them with.

Contextual information allows search engines to understand the meaning of the information presented on your website, which allows it to better answer more verbose 'natural language' queries where an understanding of the meaning helps to interpret the most relevant content to be displayed.

Microdata can be used to explain just about anything you would ever want to explain, and there are more 'schemas' being added on a regular basis. There are several vocabularies in existence, however at present the system favoured by search engines is that of schema.org.
Take a look at this short video to see how search engines use the Microdata information.

How do I use Microdata?

Microdata can be added to Joomla! using template overrides or with the use of plugins which allow you to insert microdata into specific resources.
As of Joomla! 3.2 there is a library within Joomla! which allows developers to pull in microdata without needing to format it correctly. The following resources are available by the author of the microdata library introducing the library and how to use it:

JMicrodata

JMicrodata (since version 3.2) is a library to implement http://schema.org microdata semantics.
The JMicrodata class uses the types.json file which contains all available http://schema.org Types and Properties.
The types.json was automatically created with the https://github.com/PAlexcom/Spider4Schema web crawler.

For some usage examples you can see the library test file https://github.com/joomla/joomla-cms/blob/master/tests/unit/suites/libraries/joomla/microdata/JMicrodataTest.php

For a more detailed documentation of the library see the gist created by the author:
https://gist.github.com/PAlexcom/6339949

How to use the JMicrodata library?

First of all you need to make an instance of the library in your extensions:

$microdata = new JMicrodata('Article');

So let's suppose that we have the following string which is part of your article and the current scope is Article:

echo 'Written by Alexandru Pruteanu';

And the microdata you need to add is an author property:

echo 'Written by' . $microdata->content(“Alexandru Pruteanu”)->property('author')->fallback('Person', 'name')->display();

The library will display:

Written by
<span itemprop='author' itemscope itemtype='https://schema.org/Person'>
    <span itemprop='name'>
        Alexandru Pruteanu
    </span>
</span>

What happens if the current scope is something else than Article, for example a Product scope, and the current scope doesn't have an author property?
Well it will fallback in:

Written by
<span itemscope itemtype='https://schema.org/Person'>
    <span itemprop='name'>
        Alexandru Pruteanu
    </span>
</span>

If I want to disable the microdata semantics output?
You can simply disable the microdata output by calling the following function:

$microdata->enable(false);

The library will display the following:

Written by Alexandru Pruteanu

How To implement Microdata yourself