根据在 magento 中添加的日期对类别进行排序

发布于 2024-09-18 07:58:08 字数 171 浏览 3 评论 0原文

在我的magento项目中..我想根据custom_design_from或custom_design_to对所有产品类别进行排序....

就像

最新添加的类别必须首先连续显示一样..根据堆栈概念,

任何人都可以帮我吗..我怎样才能在页面上显示类别。

谢谢! 里查

In my magento project..I want to sort all product category according to custom_design_from or custom_design_to....

like

latest added category must be display at first in a row than so on..as according to stack concept

can anyone please help me out..how can I do display categories on the page.

Thanks!
Richa

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

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

发布评论

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

评论(2

泪冰清 2024-09-25 07:58:08

如果您希望获取网站中的所有类别并按创建日期对它们进行排序,那么您可以使用以下内容:

$categoryCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->setOrder('created_at', 'DESC')
->load();

您可能希望通过明确说明来替换 ->addAttributeToSelect('*')您想要恢复的属性 - 只是为了加快速度。

我根据您的要求在这里使用了 DESC,但您也可以使用 ASC 来达到相反的效果。

上面的代码将为您提供整个集合。要获得实际的类别,您需要使用如下所示的内容迭代该集合:

foreach($categoryCollection as $category) {
echo($category->getCreatedAt() . "<br/>");
}

这应该为您提供一个很好打印的每个类别创建日期的列表。

要获取每个类别的更多信息,您可以使用 $category->getName()、$category->getId() 等。你明白了。

此代码很可能会放入您的块或帮助程序中,您可以将其包装在一个函数中,您可以从模板中调用该函数来访问所需的类别信息。

希望这有帮助。

if you are looking to grab all of the categories in your site and order them by the date they were created then you can use something along the lines of:

$categoryCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->setOrder('created_at', 'DESC')
->load();

You will probably want to replace ->addAttributeToSelect('*') by explicitly stating the attributes you want back - just to speed things up a little.

I have used DESC here as per your request but you could also use ASC for the opposite effect.

The code above will give you a whole collection. To get to the actual categories you will need to iterate over that collection with something like the following:

foreach($categoryCollection as $category) {
echo($category->getCreatedAt() . "<br/>");
}

This should give you a nicely printed out list of dates that each category was created.

To get more info on each category you can use things like $category->getName(), $category->getId() and so on. You get the idea.

This code will more than likely go in your block or helper and you can wrap it in a function which you will be able to call from your template to get access to the required category information.

Hopefully this helps.

泪是无色的血 2024-09-25 07:58:08

在简单的 PHP 脚本中,只需使用 MySql Select Query 即可完成。

根据 Megento Pattarn 使用此 SQL 选择查询:

mysql_query("select col_name from table_name ORDER BY time_col_name DESC");

检查此希望对您有所帮助。

In simple PHP script it can be done by simply using MySql Select Query.

Use this SQL Select Query According to Megento Pattarn :

mysql_query("select col_name from table_name ORDER BY time_col_name DESC");

Check this hope it will helpfull to you.

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