怎么调用woocommerce分类目录,指定分类下的指定商品

怎么调用woocommerce分类目录,指定分类下的指定商品,第1张

方法/步骤

在系统目录文件找到includes/lib_goodsphp 这个文件打开在此页最底部加入以下函数代码:

/

首页获取指定分类产品

@access public

@param string $cat_id53_best_goods

@param array $cat_id53_best_goods

@return array

/

function get_cat_id_goods_list($cat_id = '', $num = '') {

$sql = 'Select ggoods_id, gcat_id,cparent_id, ggoods_name, ggoods_name_style, gmarket_price, gshop_price AS org_price, gpromote_price, '

"IFNULL(mpuser_price, gshop_price '$_SESSION[discount]') AS shop_price, "

"promote_start_date, promote_end_date, ggoods_brief, ggoods_thumb, goods_img, "

"gis_best, gis_new, gis_hot, gis_promote "

'FROM ' $GLOBALS ['ecs']->table ( 'goods' ) ' AS g '

'LEFT JOIN ' $GLOBALS ['ecs']->table ( 'category' ) ' AS c ON ccat_id = gcat_id '

"LEFT JOIN " $GLOBALS ['ecs']->table ( 'member_price' ) " AS mp "

"ON mpgoods_id = ggoods_id AND mpuser_rank = '$_SESSION[user_rank]' "

"Where gis_on_sale = 1 AND gis_alone_sale = 1 AND gis_delete = 0 "

$sql = " AND (cparent_id =" $cat_id " OR gcat_id = " $cat_id " OR gcat_id " db_create_in ( array_unique ( array_merge ( array (

$cat_id

), array_keys ( cat_list ( $cat_id, 0, false ) ) ) ) ) ")";

$sql = " LIMIT $num";

$res = $GLOBALS ['db']->getAll ( $sql );

$goods = array ();

foreach ( $res as $idx => $row ) {

$goods [$idx] ['id'] = $row ['article_id'];

$goods [$idx] ['id'] = $row ['goods_id'];

$goods [$idx] ['name'] = $row ['goods_name'];

$goods [$idx] ['brief'] = $row ['goods_brief'];

$goods [$idx] ['brand_name'] = $row ['brand_name'];

$goods [$idx] ['goods_style_name'] = add_style ( $row ['goods_name'], $row ['goods_name_style'] );

$goods [$idx] ['short_name'] = $GLOBALS ['_CFG'] ['goods_name_length'] > 0 sub_str ( $row ['goods_name'], $GLOBALS ['_CFG'] ['goods_name_length'] ) : $row ['goods_name'];

$goods [$idx] ['short_style_name'] = add_style ( $goods [$idx] ['short_name'], $row ['goods_name_style'] );

$goods [$idx] ['market_price'] = price_format ( $row ['market_price'] );

$goods [$idx] ['shop_price'] = price_format ( $row ['shop_price'] );

$goods [$idx] ['thumb'] = empty ( $row ['goods_thumb'] ) $GLOBALS ['_CFG'] ['no_picture'] : $row ['goods_thumb'];

$goods [$idx] ['goods_img'] = empty ( $row ['goods_img'] ) $GLOBALS ['_CFG'] ['no_picture'] : $row ['goods_img'];

$goods [$idx] ['url'] = build_uri ( 'goods', array (

'gid' => $row ['goods_id']

), $row ['goods_name'] );

}

return $goods;

}

打开系统根目录下indexphp文件加入如下代码,如果要在别的页面调用加到别的页面:

$smarty->assign('cat_id_goods_list_86', get_cat_id_goods_list(86,9));

// 指定商品调用

//其中86指的调用的栏目ID,9指的是调用商品的数量。

在首页模版中调用即可,如下:

<!--{foreach from=$cat_id_goods_list_86 item=goods}-->

<li> <a href="{$goodsurl}" target="_blank"> <img src="{$goodsthumb}" alt="{$goodsname|escape:html}" /></a> <span class="a_title"> <a href="{$goodsurl}" title="{$goodsname|escape:html}" target="_blank"> {$goodsshort_style_name}</a> </span> <div style="text-indent: 5px;">市场价 <span class="del">{$goodsmarket_price}</span></div> <div style="text-indent: 5px;"><span class="red">售 价 {$goodsshop_price}</span></div></li>

<!--{/foreach}-->

Smarty2和Smarty3在实现上差不多,但是在smarty2升级到smarty3的时候还是要注意些许不同。

下面是已知的和smarty2不兼容的地方 == 语法 ==Smarty 3 API有些方面进行了更新。一些Smarty 2 API调用需要更新以便符合Smarty 3。你可能会得到提示,推荐你使用新的语法。可以查看Smarty 3附带的 README 文件获得更多信息。

{$array|@mod} 语法总是让人迷惑,加上@符号说明修饰符作用于数组而不是作用于数组的每个元素。通常你总是想让这个修饰符作用于这个变量而不必考虑它的类型。在 Smarty 3中,{$array|mod} 和 {$smary|@mod}

是等同的。去掉@符号,修饰符仍然作用于数组。如果你想修饰符作用于数据元素,你必须在模板中循环数组,或者使用自定义修饰符以支持数组遍历。

大多smrty函数已经在需要的地方例如{html_options}进行了转义。 == PHP版本 ==Smarty 3 仅支持PHP 5 在PHP 4将不能正常工作。 == {php} 标记 ==

Smarty 3 默认关闭 {php} 标记支持,不推荐使用。你可以通过设置$smarty->allow_php_tag=true来启用。{php} 块中的变量不再与同一页中的其它{php}块共享作用域,因此在使用的时候要注意。 == 定界符和空格 ==

Smarty 定界符 {} 有空格包围是不再认为是Smarty标记。因此,{ foo } 将被Smarty忽略,但是 {foo} 将被识别。这个变化使得 Javascript/CSS更容易在smarty中使用,而没有必要使用 {literal}

这个特性可以通过设置 $smarty->auto_literal = false; 禁用。 == 未用引号的字符串 ==

Smarty 2 对于参数中未用引号括起来的字符串有点宽容(并且模棱两可)。Smarty 3 比较严格。对于不包含特殊字符(A-Za-z0-9_之外的字符)的字符串仍然可以不用引号括起来。比如下面例子中文件名就必须用引号括起来。[xhtml]view plaincopy{assign var=foo value=baz} <-- works ok {include file="path/footpl"} <-- needs quotes! == 扩展Smarty类 ==

Smarty 3 遵循PHP5标准构造规则。扩展Smarty类的时候,使用 __construct() 作为类的构造函数的名称。如果你实现自己的构造函数,一定要先调用 parent::__construct() [php]view plaincopyclass MySmarty extends Smarty { function __construct() { parent::__construct(); // your initialization code goes here } } == 自动加载器 ==

Smarty 用spl_autoload_register函数 实现了它自己的自动加载器。如果想在自己的应用中使用自动加载器,就必须使用此方法注册。

使用 __autoload() 将失败。 这是PHP5标准自动加载函数。可以查看

>

可以,步骤如下:

1 Html中每个tag都是都将作为树中的一个节点存在的,每个tag都属于树中的某一层。

2 辅助数据结构:栈(stack)、List、HashTable。其中HashTable[i](i属于int类型)是一个List,用于临时存储第i层子Tag。

3 顺序扫描Html文本,当遇到”<A~Z”这样的标志,表示可能是一个Tag,调用GetTag()函数对此段代码进行解析,解析出Tag名,Tag属性等等。

直接上代码,中间那行,就是获取第一个循环的值,

<{foreach from=$list item=li name=listName key=Listkey}>

    <{$smartyforeachlistNamefirst}>

<{/foreach}>

还可以获取最后的值

<{foreach from=$list item=li name=listName key=Listkey}>

    <{$smartyforeachlistNamelast}>

<{/foreach}>

<script type="text/javascript">

$(function(){

$ajax({

type: "get",//使用get方法访问后台

dataType: "json",//返回json格式的数据

url: "get_jsonphp",//要访问的后台地址

data: "id=<!--{$id}-->&r="+Mathrandom(),//要发送的数据,Mathrandom()随机,防止访问缓存

success: function(msg){//msg为返回的数据,在这里做数据绑定

//成功处理

}

});

});

</script>

get_jsonphp返回值格式如下:

echo json_encode($date);

$date可以是字符串、数字、数组等

仅仅举例说明,我这里举的是打开即运行,自己需要什么时候触发,传递到什么地址、传递什么参数,成功返回后需要怎么处理等根据情况修改

以上就是关于怎么调用woocommerce分类目录,指定分类下的指定商品全部的内容,包括:怎么调用woocommerce分类目录,指定分类下的指定商品、php中smarty模板中如何使用preg_match_all和preg_replace函数、smarty 在html中能解析html标签吗等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9281591.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存