如何使用WooCommerce获取当前页面的标题

时间:2015-11-17 23:20:18

标签: php wordpress woocommerce breadcrumbs

大家早上好,
我有WooComerce面包屑的问题。我想在左侧添加带有当前页面/产品标题的breadcrumbs栏。但我不知道我怎么能得到这个头衔。我能够添加一些自定义文本并使用以下代码将其移至右侧:

>>> i00['Resources'] = "A" * 66848; len(json.dumps(i00))
68481
>>> i = Item(ct.table, data=i00); i.save()
True
>>> i.delete()
True
>>> i00['Resources'] = "A" * 66849; len(json.dumps(i00))
68482
>>> i = Item(ct.table, data=i00); i.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/var/www/virtualenv/ken/local/lib/python2.7/site-packages/boto/dynamodb2/items.py", line 455, in save
    returned = self.table._put_item(final_data, expects=expects)
  File "/var/www/virtualenv/ken/local/lib/python2.7/site-packages/boto/dynamodb2/table.py", line 835, in _put_item
    self.connection.put_item(self.table_name, item_data, **kwargs)
  File "/var/www/virtualenv/ken/local/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 1510, in put_item
    body=json.dumps(params))
  File "/var/www/virtualenv/ken/local/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 2842, in make_request
    retry_handler=self._retry_handler)
  File "/var/www/virtualenv/ken/local/lib/python2.7/site-packages/boto/connection.py", line 954, in _mexe
    status = retry_handler(response, i, next_sleep)
  File "/var/www/virtualenv/ken/local/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 2882, in _retry_handler
    response.status, response.reason, data)
ValidationException: ValidationException: 400 Bad Request
{u'message': u'Item size has exceeded the maximum allowed size', u'__type': u'com.amazon.coral.validate#ValidationException'}

你能否建议我获得一些解决方案?

编辑: Okey我设法得到一些临时结果,但它只返回WooComerce页面名称(商店,类别名称),它不显示产品名称。有什么建议吗?

这是代码:

'wrap_before' => '<nav class="woocommerce-breadcrumb"><h1 id="name">Some text</h1>',
 'wrap_after'  => '</nav>',

1 个答案:

答案 0 :(得分:2)

我会使用woocommerce_get_breadcrumb过滤器来修改发送到模板的数组的内容。您可以从最后获取页面名称并将其放在开头,或添加您想要的任何其他面包屑。每个元素都是一个数组,第一个元素是文本,第二个元素是链接。

// filter the array that is sent to the breadcrumbs template
add_filter( 'woocommerce_get_breadcrumb', function( $crumbs ){
    // remove the last element (this is the page name by default)
    $page_crumb = array_pop( $crumbs );

    // add it back to the beginning of the array. 
    // you can change this to whatever you want, it's an array( 'Text', '/link' )
    array_unshift( $crumbs, $page_crumb );

    // return the modified array
    return $crumbs;
} );