我想在 Magento 站点的所有页面上插入跟踪代码,如果页面是 CMS 页面、类别浏览页面或产品查看页面,则需要使用不同的语法.我有一个自定义模块,其中设置了一个块,现在可以在每个页面上插入通用跟踪代码.从区块内部,如何区分CMS页面、分类页面和产品页面?
I want to insert tracking codes on all of the pages of a Magento site, and need to use a different syntax if the page is a CMS page, a category browsing page, or a product view page. I have a custom module set up with a block that inserts a generic tracking code on each page for now. From within the block, how can I distinguish between CMS pages, category pages, and product pages?
我开始于:
Mage::app()->getRequest();
我可以看到
Mage::app()->getRequest()->getParam('id');
返回产品和类别页面上的产品或类别 ID,但不区分这些页面类型.
returns the product or category ID on product and category pages, but doesn't distinguish between those page types.
Mage::app()->getRequest()->getRouteName();
CMS 页面返回cms",但类别浏览和产品查看页面都返回catalog",所以我不能用它来区分类别和产品页面.
return "cms" for CMS pages, but returns "catalog" for both category browsing and product view pages, so I can't use that to tell category and product pages apart.
请求中是否有我可以安全使用的指示符?或者有没有更好的方法来实现我针对不同页面类型使用不同跟踪代码的目标?
Is there some indicator in the request I can use safely? Or is there a better way to accomplish my goal of different tracking codes for different page types?
使用路由器可能有更好的方法来做到这一点,但一种快速的方法是检查注册表以查看我们是否有我们正在使用的单个产品看着:
There may be an even better way to do this using routers, but one fast way is to check the registry to see if we have a single product that we are looking at:
<?php
$onCatalog = false;
if(Mage::registry('current_product')) {
$onCatalog = true;
}
希望有帮助!
谢谢,乔
这篇关于在 Magento 中以编程方式确定是否在产品页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)