如何制作带图片价格的销售排行挂件?

2016-07-07 16:50 来源:www.chinab4c.com 作者:ecshop专家

默认的是没有图片跟价格的。我现在想弄一个横的带图片,标题还有价格的挂件。
写出来的只有标题,没有价格跟图片。
  1. <?php

  2. /**
  3. * 销售排行前8挂件
  4. *
  5. * @returnarray$goods_list
  6. */
  7. class Sales_listWidget extends BaseWidget
  8. {
  9. var $_name = 'sales_list';
  10. var $_ttl= 86400;

  11. function _get_data()
  12. {
  13. $cache_server =& cache_server();
  14. $key = $this->_get_cache_id();
  15. $data = $cache_server->get($key);
  16. if($data === false)
  17. {

  18. $goods_mod =& m('goods');
  19. $data = $goods_mod->find(array(
  20. 'conditions' => "if_show = 1 AND closed = 0",
  21. 'order' => 'sales',
  22. 'fields' => 'g.goods_id, g.goods_name, g.default_image',
  23. 'join' => 'has_goodsstatistics',
  24. 'limit' => 8,

  25. ));

  26. $cache_server->set($key, $data, $this->_ttl);
  27. }

  28. return $data;
  29. }
  30. }

  31. ?>
复制代码
出来的效果

我想要的效果


还请论坛上的高手们帮个忙

回答:
用JS调用不好吗?套上样式就可以了.

如果要手动设置的话.用精品推荐的挂件就可以了

JS怎么调用啊?在哪设置?

最好是直接从数据库里直接读出来的,这样效率也高,SEO也好

模板的内容怎么不给出来?

  1. <div class="best_goods_title">
  2. <div class="bg_title1"><h3>热销商品</h3></div>
  3. <div class="bg_title2"><span>
  4. <a target="_blank" href="index.php?app=search&order=sales desc">更多>></a>
  5. </span></div>
  6. <div class="bg_title3"></div>
  7. </div>
  8. <div class="best_goods_text">
  9. <ul class="manufacture">
  10. <!--{foreach from=$widget_data item=goods name=fe_sales_list}-->
  11. <li>
  12. <a class="manufacture_pic" href="index.php?app=goods&id={$goods.goods_id}" target="_blank">

  13. <img src="<img src="{$goods.default_image}" width="100" height="100" />
  14. </a>
  15. <p><a href="index.php?app=goods&id={$goods.goods_id}" target="_blank" title="{$goods.goods_name|escape}">{$goods.goods_name|escape}</a><span>{$goods.price|price}</span></p>
  16. </li>
  17. <!--{/foreach}-->
  18. </ul>
  19. </div>
复制代码
这是模板的代码,还请biby高手指点一下

粗心、浮躁,能成大事吗?

<div class="best_goods_title">
<div class="bg_title1"><h3>热销商品</h3></div>
<div class="bg_title2"><span>
<a target="_blank" href="index.php?app=search&order=sales desc">更多>></a>
</span></div>
<div class="bg_title3"></div>
</div>
<div class="best_goods_text">
<ul class="manufacture">
<!--{foreach from=$widget_data item=goods name=fe_sales_list}-->
<li>
<a class="manufacture_pic" href="index.php?app=goods&id={$goods.goods_id}" target="_blank">

<img src="<img src="{$goods.default_image}" width="100" height="100" />
</a>
<p><a href="index.php?app=goods&id={$goods.goods_id}" target="_blank" title="{$goods.goods_name|escape}">{$goods.goods_name|escape}</a><span>{$goods.price|price}</span></p>
</li>
<!--{/foreach}-->
</ul>
</div>

制作带图片价格的销售排行挂件
代码部分没有任何问题
<?php

/**
* 销售排行前8挂件
*
* @returnarray$goods_list
*/
class Sales_listWidget extends BaseWidget
{
var $_name = 'sales_list';
var $_ttl= 86400;

function _get_data()
{
$cache_server =& cache_server();
$key = $this->_get_cache_id();
$data = $cache_server->get($key);
if($data === false)
{

$goods_mod =& m('goods');
$data = $goods_mod->find(array(
'conditions' => "if_show = 1 AND closed = 0",
'order' => 'sales',
'fields' => 'g.goods_id, g.goods_name, g.default_image',
'join' => 'has_goodsstatistics',
'limit' => 8,

));

$cache_server->set($key, $data, $this->_ttl);
}

return $data;
}
}

?>

楼上的教训的是,呵呵!
不过价格还是出不来啊

function _get_data()
{
$cache_server =& cache_server();
$key = $this->_get_cache_id();
$data = $cache_server->get($key);
if($data === false)
{

$goods_mod =& m('goods');
$data = $goods_mod->find(array(
'conditions' => "if_show = 1 AND closed = 0",
'order' => 'sales',
'fields' => 'g.goods_id, g.goods_name, g.default_image,g.price',
'join' => 'has_goodsstatistics',
'limit' => 8,

));

$cache_server->set($key, $data, $this->_ttl);
}

  1. <?php

  2. /**
  3. * 销售排行前8挂件
  4. *
  5. * @returnarray$goods_list
  6. */
  7. class Sales_listWidget extends BaseWidget
  8. {
  9. var $_name = 'sales_list';
  10. var $_ttl= 86400;

  11. function _get_data()
  12. {
  13. $cache_server =& cache_server();
  14. $key = $this->_get_cache_id();
  15. $data = $cache_server->get($key);
  16. if($data === false)
  17. {

  18. $goods_mod =& m('goods');
  19. $data = $goods_mod->find(array(
  20. 'conditions' => "if_show = 1 AND closed = 0",
  21. 'order' => 'sales',
  22. 'fields' => 'g.goods_id, g.goods_name, g.default_image,g.price',
  23. 'join' => 'has_goodsstatistics',
  24. 'limit' => 8,

  25. ));

  26. $cache_server->set($key, $data, $this->_ttl);
  27. }

  28. return $data;
  29. }
  30. }

  31. ?>
复制代码
修改完之后的完整代码是这样的,但是保存之后,去模板编辑里,插入挂件的时候,会一直显示加载中
如果去掉那个g.price则不会这样子

.
没有留意数据不在一个表里

function _get_data()
{
$cache_server =& cache_server();
$key = $this->_get_cache_id();
$data = $cache_server->get($key);
if($data === false)
{

$goods_mod =& m('goods');
$data = $goods_mod->find(array(
'conditions' => "if_show = 1 AND closed = 0",
'order' => 'sales',
'fields' => 'g.goods_id, g.goods_name, g.default_image,gs.price',
'join' => 'has_goodsstatistics',
'limit' => 8,

));

$cache_server->set($key, $data, $this->_ttl);
}

还是读不出来,一直载入中。

我有空了自己试下

谢谢了。试出来的话,第一个通知我哈