Magento - 丰富的高度深度片段和&宽度尺寸

时间:2015-01-12 14:44:47

标签: magento height width depth rich-snippets

我已经使用教程https://www.byte.nl/blog/magento-rich-snippets-made-easy/来实现我想要的大部分丰富网页摘要,只需要在标记中加入高度,深度和宽度。

我正在编辑目录中的view.phtml文件: / HTML /应用程序/设计/前端/默认/ onlinebiz_store /模板/目录/产品

我认为需要编辑的代码部分是:

<div class="box-attribute row">             

                    <?php if ($_product->getHeight()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                        </div>  
                    <?php endif; ?>


                </div>

在此处检查此解决方案Product size: width, height and depth之后,我尝试使用高度代码,如果有效,我可以修改深度和宽度。

我将代码更改为:

<div class="box-attribute row" itemscope itemtype="http://schema.org/Product">              

                        <?php if ($_product->getHeight()): ?>
                            <div class="item col-xs-12">
                                <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                                <span itemprop="width" itemscope itemtype="http://schema.org/Distance" class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                            </div>  
                        <?php endif; ?>


                    </div>

不幸的是,经过测试,Google的结构化数据测试工具中根本没有显示高度值,它也没有显示任何错误,也就是说我说错了。

我知道Magento扩展为我做这个,但是总是很高兴尝试了解更多,我觉得我已经学到了很多其他丰富的片段,所以任何帮助都会非常感激

我的view.phtml的整个代码是:

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */
?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view" itemscope itemtype="http://schema.org/Product">
    <div class="product-essential">
    <form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
        <?php echo $this->getBlockHtml('formkey') ?>
        <div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>

        <div class="row">
            <div class="product-img-box col-sm-4 col-xs-12">
                <?php echo $this->getChildHtml('media') ?>

            </div>
            <div class="product-shop col-sm-7 col-xs-12">
                <div class="product-name">
                    <h1 itemprop="name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
<?php if($_product->isAvailable()): ?>
<div class="no-display" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<meta itemprop="priceCurrency" content="<?php echo $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); ?>"/>
     <span itemprop="price"><?php echo Mage::helper('core')->currency($_product->getFinalPrice()); ?></span>
     <link itemprop="availability" href="http://schema.org/InStock" />
</div>
<?php endif; ?>


                </div>

                <?php echo $this->getChildHtml('alert_urls') ?>                           
                <?php echo $this->getChildHtml('product_type_data') ?>
                <?php echo $this->getTierPriceHtml() ?> 
                <?php echo $this->getChildHtml('extrahint') ?>

                <?php if ($_product->getShortDescription()):?>
                    <div class="short-description">
                        <div class="std" itemprop="description"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
                    </div>
                <?php endif;?>
                <div class="box-attribute row">
                    <?php if ($_product->getData('period')): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('period') ?></span>
                            <span class="value col-xs-6"><?php echo nl2br($_product->getResource()->getAttribute('period')->getFrontend()->getValue($_product)) ?></span>
                        </div>  
                    <?php endif; ?>

                    <?php if ($_product->getData('country')): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('country of origin') ?></span>
                            <span class="value col-xs-6"><?php echo nl2br($_product->getResource()->getAttribute('country')->getFrontend()->getValue($_product)) ?></span>
                        </div>  
                    <?php endif; ?>

                    <?php if ($_product->getData('condition')): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('condition') ?></span>
                            <span class="value col-xs-6"><?php echo nl2br($_product->getResource()->getAttribute('condition')->getFrontend()->getValue($_product)) ?></span>
                        </div>
                    <?php endif; ?>

                    <?php if ($_product->getHeight()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                        </div>  
                    <?php endif; ?>
                    <?php if ($_product->getDepth()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Depth') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getDepth(); ?></span>
                        </div>  
                    <?php endif; ?>


                    <?php if ($_product->getLength()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Length') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getLength(); ?></span>
                        </div>  
                    <?php endif; ?>                                     

                    <?php if ($_product->getReferenceInfo()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Reference Info') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getReferenceInfo(); ?></span>
                        </div>  
                    <?php endif; ?> 

                    <?php if ($_product->getCirca()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Circa') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getCirca(); ?></span>
                        </div>  
                    <?php endif; ?>


                    <?php if ($_product->getMaterials()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Materials') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getMaterials(); ?></span>
                        </div>  
                    <?php endif; ?>

                </div>
                <div class="aditional-info">
                    <?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
                        <div class="box-collateral <?php echo "box-{$alias}"?>">
                            <?php if ($title = $this->getChildData($alias, 'title')):?>
                            <h2><?php echo $this->escapeHtml($title); ?></h2>
                            <?php endif;?>
                            <?php echo $html; ?>
                        </div>
                    <?php endforeach;?>
                </div>
                <?php if($_product->getReserveStatus()): ?>
                    <?php if (!$this->hasOptions()):?>
                        <div class="add-to-box">
                            <?php if($_product->isSaleable()): ?>
                                <?php echo $this->getChildHtml('addtocart') ?>
                            <?php endif; ?>
                        </div>
                    <?php echo $this->getChildHtml('extra_buttons') ?>
                    <?php endif; ?>
                <?php else:?>
                    <p></p>
                <?php endif; ?>

                <?php echo $this->getChildHtml('other');?>

                <?php if ($_product->isSaleable() && $this->hasOptions()):?>
                    <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
                <?php endif;?>
                <!-- AddThis Button BEGIN -->
                <div class="addthis_toolbox addthis_default_style ">
                <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                <a class="addthis_button_tweet"></a>
                <a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
                <a class="addthis_button_google_plusone" g:plusone:size="horizontal"></a>
                <a class="addthis_counter addthis_pill_style"></a>
                </div>
                <script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
                <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5138d1b905e0a287"></script>
                <!-- AddThis Button END -->
            </div>


        </div>

        <div class="clearer"></div>
        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
        <?php endif;?>
    </form>
    <script type="text/javascript">
    //<![CDATA[
        var productAddToCartForm = new VarienForm('product_addtocart_form');
        productAddToCartForm.submit = function(button, url) {
            if (this.validator.validate()) {
                var form = this.form;
                var oldUrl = form.action;

                if (url) {
                   form.action = url;
                }
                var e = null;
                try {
                    this.form.submit();
                } catch (e) {
                }
                this.form.action = oldUrl;
                if (e) {
                    throw e;
                }

                if (button && button != 'undefined') {
                    button.disabled = true;
                }
            }
        }.bind(productAddToCartForm);

        productAddToCartForm.submitLight = function(button, url){
            if(this.validator) {
                var nv = Validation.methods;
                delete Validation.methods['required-entry'];
                delete Validation.methods['validate-one-required'];
                delete Validation.methods['validate-one-required-by-name'];
                // Remove custom datetime validators
                for (var methodName in Validation.methods) {
                    if (methodName.match(/^validate-datetime-.*/i)) {
                        delete Validation.methods[methodName];
                    }
                }

                if (this.validator.validate()) {
                    if (url) {
                        this.form.action = url;
                    }
                    this.form.submit();
                }
                Object.extend(Validation.methods, nv);
            }
        }.bind(productAddToCartForm);
    //]]>
    </script>
    </div>

    <div class="product-collateral">
            <?php echo $this->getChildHtml('info_tabs') ?>
            <?php echo $this->getChildHtml('product_additional_data') ?>

    </div>

</div>
<?php echo $this->getChildHtml('related-products') ?>

我进一步发挥作用并设法让Google测试人员接受以下内容:

<?php if ($_product->getHeight()): ?>
                    <div class="item col-xs-12" itemprop="height">
                        <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                        <span class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                    </div>

0 个答案:

没有答案