从静态块链接到类别的最佳方法

发布于 2024-12-25 06:15:55 字数 290 浏览 1 评论 0原文

从静态块链接到类别和产品的最佳方式是什么?

我问这个问题是因为有时我们会更新类别等的 URL 键,这会破坏静态块中到给定类别和产品的链接。

有没有更好的方法使用 ids 等进行链接,以便无论 seo 友好的 url 是什么,链接都将处于活动状态?

目前,我使用的链接如下: link

当类别的 URL 更改时,上述链接将被破坏。

What is the best way to link to categories and products from static blocks.

I ask because sometimes we will update URL-keys for categories, etc, which will break links in static blocks to given categories and products.

Is there a better way to link using ids etc so the links will be active regardless of seo-friendly urls?

Currently, I use links such as:
<a href="store.com/generators/generators.html?"generator_package=6>link</a>

When the urls for the categories change the above link would be broken.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十六岁半 2025-01-01 06:15:55

这个怎么样?让我知道结果,也许我们可以采取其他方法。

+++ 编辑 - 新代码示例 +++
首先创建一个静态块,该块应该引用一个 phtml 文件,您可以将逻辑放入该文件中。

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/ListCategory.phtml"}}  

在 /app/design/frontend/[YOUR_THEME]/template/catalog/category/ 目录中创建 ListCategory.phtml。

<?php
// get current category id
$curCategory = $this->getCurrentCategory()->getId();

// instance of Mage_Catalog_Model_Category
$category = Mage::getModel(catalog/category)->load((int)$curCategory);

// child category id array
$childCategories = $category->getChildren();

?>

How about this? Let me know the result, maybe we can handle other ways.

+++ EDIT - New Code Sample +++
First create a static block which is this block should reference a phtml file that you can put your logic into this file.

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/ListCategory.phtml"}}  

Create ListCategory.phtml in the /app/design/frontend/[YOUR_THEME]/template/catalog/category/ directory.

<?php
// get current category id
$curCategory = $this->getCurrentCategory()->getId();

// instance of Mage_Catalog_Model_Category
$category = Mage::getModel(catalog/category)->load((int)$curCategory);

// child category id array
$childCategories = $category->getChildren();

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文