Jump to content

如何让home featured中的产品随机出现?


meditation

Recommended Posts

  • 6 months later...

下面是我1.4a3的mod。

备份后在modules/homefeatured/homefeatured.php里找到:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));




在其下面加入:

if ($products != false ) {
 shuffle($products);
 array_splice($products, ($nb ? $nb : 8));
}




就像下面这样:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));
if ($products != false ) {
 shuffle($products);
 array_splice($products, ($nb ? $nb : 8));
}

Link to comment
Share on other sites

我的版本是 Version 1.3.0.2。

按照 版主 的方法修改,可以正常实现这种功能。谢谢!

-----------------------------------------------------------------
if ($products != false ) {
shuffle($products);
array_splice($products, ($nb ? $nb : 8));
}
------------------------------------------------------------
这段代码能帮忙解释下???

两个函数是什么意思?($nb ? $nb : 8) ,中的 '8‘ 是什么意思??

Link to comment
Share on other sites


-----------------------------------------------------------------
if ($products != false ) {
shuffle($products);
array_splice($products, ($nb ? $nb : 8));
}
------------------------------------------------------------
这段代码能帮忙解释下???

两个函数是什么意思?($nb ? $nb : 8) ,中的 '8‘ 是什么意思??


先判断$products里有没有产品(有没有产品在Home分类下);如果有,就将$products里面的产品随机排序 (shuffle)。接下来,如果在homefeatured模块里设置了显示多少个产品($nb),那么,就按照设置的数量来显示这些产品 (array_splice);如果没有设置,就默认按照8个产品(如果够8个的话)来显示。

我的homefeatured模块是一行4个,显示两行,所以我设置为8个。

另外,如果已勾选Home分类的产品比较多的话,也可以将
$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));



修改为:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);



最后,像下面这样:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);
if ($products != false ) {
 shuffle($products);
 array_splice($products, ($nb ? $nb : 8));
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...