Loading


Advertisement:

Author Topic: Rich snippet , Microdata, Structered Data simple code insert for items  (Read 2324 times)

Normalu

  • Newbie
  • *
  • Posts: 23
Hi, I hope I'm posting in the right place.

I'm using this code for SEO and Structured data, I inserted it in ../oc-content/themes/bender/item.php

I tested it using Google Structured Data Testing Tool and it gave me the green light :)

Code: [Select]
<div id="metadata" itemscope itemtype="http://schema.org/Product">
<meta itemprop="name" content="<?php echo osc_item_title(); ?>" />
<meta itemprop="image" content="<?php echo osc_resource_url(); ?>" />
<meta itemprop="description" content="<?php echo osc_item_description(); ?>" />
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<meta itemprop="price" content="<?php echo $value=(osc_item_price()/1000000); ?>" />
<meta itemprop="pricecurrency" content="<?php echo osc_item_currency(); ?>" />
<link itemprop="availability" href="http://schema.org/InStock" />
</div>
</div>

My questions are:
1. Is my code good? Do you suggest any improvements?
2. How to get the currency code using php done using osc_item_currency()
3. Is it possible to have product availability depending on Ads expiry date?

I've read http://forums.osclass.org/tips-and-tricks/%28tip%29-adding-metadata-rich-snippets/ which is about similar subject

Thank you
« Last Edit: March 21, 2015, 10:21:50 pm by Normalu »

Normalu

  • Newbie
  • *
  • Posts: 23
Seems like there is conflict between this configuration and Social Bookmarks plugin. Social bookmark seems to jump after the "description" tag. So it break my code.

And I couldn't get the full URL to the main image. How I can do that?

Normalu

  • Newbie
  • *
  • Posts: 23
Any help please?

Normalu

  • Newbie
  • *
  • Posts: 23
I got this to work wiith help from teseo here http://forums.osclass.org/3-5-x/how-to-get-image-url/msg118633/#msg118633

Code: [Select]
<!-- Structered data Starts here -->
<div id="metadata" itemscope itemtype="http://schema.org/Product">
            <meta itemprop="name" content="<?php echo osc_item_title(); ?>" />
            <meta itemprop="image" content="<?php if( osc_count_item_resources() > )  echo osc_resource_url(); ?>" />
            <meta itemprop="description" content="<?php echo osc_item_description();?>" />
<?php if(osc_item_price() != '') { ?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
                                     <meta itemprop="price" content="<?php echo $value=(osc_item_price()/1000000); ?>" />
                                     <meta itemprop="pricecurrency" content="<?php echo osc_item_currency(); ?>" />
                                     <link itemprop="availability" href="http://schema.org/InStock" />
                               </div>   
<?php ?>
           
</div>
<!-- Structered data Ends here -->

teseo

  • Hero Member
  • *****
  • Posts: 5747
Hi,

Thanks for the mention. :)

***CORRECTED***

Regarding this:

Quote
Is it possible to have product availability depending on Ads expiry date?

Following the documentation, I think something like this:

Code: [Select]
<link itemprop="availability" href="http://schema.org/<?php echo (osc_item_is_expired() ? 'Discontinued"/>Unavailable' 'InStock"/>Available'); ?>
You may change "Available" and "Unavailable" to your liking, I think.

Regards

« Last Edit: April 05, 2015, 02:41:12 pm by teseo »

Normalu

  • Newbie
  • *
  • Posts: 23
Hi,

Thanks for the mention. :)

Regarding this:

Quote
Is it possible to have product availability depending on Ads expiry date?

Following the documentation, I think something like this:

Code: [Select]
<link itemprop="availability" href="http://schema.org/<?php echo (osc_item_is_expired() ? 'Discontinued"/>Unavailable' 'InStock"/>Available'); ?> />
You may change "Available" and "Unavailable" to your liking, I think.

Regards

Thank you. The code you added didn't work as is. I think I have to modify something. I don't know much about PHP.

Another update, it seems that Osclass script uses osc_esc_html(meta_title()) and osc_esc_html(meta_description()). So I modified my code.

Code: [Select]
<!-- Structered data Starts here -->
<div id="metadata" itemscope itemtype="http://schema.org/Product">
            <meta itemprop="name" content="<?php echo osc_esc_html(meta_title()); ?>" />
            <meta itemprop="image" content="<?php if( osc_count_item_resources() > )  echo osc_resource_url(); ?>" />
            <meta itemprop="description" content="<?php echo osc_esc_html(meta_description()); ?>" />
<?php if(osc_item_price() != '') { ?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
                    <meta itemprop="price" content="<?php echo $value=(osc_item_price()/1000000); ?>" />
                    <meta itemprop="pricecurrency" content="<?php echo osc_item_currency(); ?>" />
                      <link itemprop="availability" href="http://schema.org/InStock" />
                </div>   
<?php ?>
           
</div>

teseo

  • Hero Member
  • *****
  • Posts: 5747

Thank you. The code you added didn't work as is. I think I have to modify something. I don't know much about PHP.

Another update, it seems that Osclass script uses osc_esc_html(meta_title()) and osc_esc_html(meta_description()). So I modified my code.

Code: [Select]
<!-- Structered data Starts here -->
<div id="metadata" itemscope itemtype="http://schema.org/Product">
            <meta itemprop="name" content="<?php echo osc_esc_html(meta_title()); ?>" />
            <meta itemprop="image" content="<?php if( osc_count_item_resources() > )  echo osc_resource_url(); ?>" />
            <meta itemprop="description" content="<?php echo osc_esc_html(meta_description()); ?>" />
<?php if(osc_item_price() != '') { ?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
                    <meta itemprop="price" content="<?php echo $value=(osc_item_price()/1000000); ?>" />
                    <meta itemprop="pricecurrency" content="<?php echo osc_item_currency(); ?>" />
                      <link itemprop="availability" href="http://schema.org/InStock" />
                </div>   
<?php ?>
           
</div>

Yes, the correct line would be:

Code: [Select]
<link itemprop="availability" href="http://schema.org/<?php echo (osc_item_is_expired() ? 'Discontinued"/>Unavailable' 'InStock"/>Available'); ?>
Also, you want to alter your code. As it is now, "availability" wouldn't be shown if the ad has no Price:

Code: [Select]
<!-- Structered data Starts here -->
<div id="metadata" itemscope itemtype="http://schema.org/Product">
            <meta itemprop="name" content="<?php echo osc_esc_html(meta_title()); ?>" />
            <meta itemprop="image" content="<?php if( osc_count_item_resources() > )  echo osc_resource_url(); ?>" />
            <meta itemprop="description" content="<?php echo osc_esc_html(meta_description()); ?>" />
<?php if(osc_item_price() != '') { ?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
                    <meta itemprop="price" content="<?php echo $value=(osc_item_price()/1000000); ?>" />
                    <meta itemprop="pricecurrency" content="<?php echo osc_item_currency(); ?>" />
                </div>   
<?php ?>
                                <link itemprop="availability" href="http://schema.org/<?php echo (osc_item_is_expired() ? 'Discontinued"/>Unavailable' 'InStock"/>Available'); ?>
           
</div>

Regards


p206ab

  • Full Member
  • ***
  • Posts: 231
  • No one will read this text with Cameron above :)
Re: Rich snippet , Microdata, Structered Data simple code insert for items
« Reply #7 on: August 07, 2015, 03:58:15 pm »
Hi Normalu, can you provide an example (screenshot, link..) on how does your results look in Google after you added this?
Thanks