Php 在顶部菜单上预览子类别图像
在Prestashop中,我们可以将图像(拇指)添加到子类别菜单中Php 在顶部菜单上预览子类别图像,php,prestashop,prestashop-1.6,Php,Prestashop,Prestashop 1.6,在Prestashop中,我们可以将图像(拇指)添加到子类别菜单中 if ((int)$category['level_depth'] > 1 && !$is_children) { $files = scandir(_PS_CAT_IMG_DIR_); if (count(preg_grep('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $fi
if ((int)$category['level_depth'] > 1 && !$is_children) {
$files = scandir(_PS_CAT_IMG_DIR_);
if (count(preg_grep('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $files)) > 0) {
$html .= '<li class="category-thumbnail">';
foreach ($files as $file) {
if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1) {
$html .= '<div><img src="'.$this->context->link->getMediaLink(_THEME_CAT_DIR_.$file)
.'" alt="'.Tools::SafeOutput($category['name']).'" title="'
.Tools::SafeOutput($category['name']).'" class="imgm" /></div>';
}
}
$html .= '</li>';
}
}
if((int)$category['level\u depth']>1&&!$is\u子项){
$files=scandir(\u PS\u CAT\u IMG\u DIR);
如果(计数(preg_grep('/^'.$category['id_category'].-([0-9])?_thumb.jpg/i',$files))>0){
$html.=';
foreach($files作为$file){
if(preg_match('/^'.$category['id_category'].-([0-9])?_thumb.jpg/i',$file)==1){
$html.='context->link->getMediaLink(\u THEME\u CAT\u DIR.$file)
“.alt=”.Tools::SafeOutput($category['name'])。”title=“”
.Tools::SafeOutput($category['name'])。“class=“imgm”/>”;
}
}
$html.=' ';
}
}
不幸的是,这段代码不适用于我,虽然我为子类别设置了拇指图像,但图像不会显示。
有什么帮助吗?这是我的解决方案,它与我一起工作
protected function generateCategoriesMenu($categories, $is_children = 0)
{
$html = '';
foreach ($categories as $key => $category) {
if ($category['level_depth'] > 1) {
$cat = new Category($category['id_category']);
$link = Tools::HtmlEntitiesUTF8($cat->getLink());
} else {
$link = $this->context->link->getPageLink('index');
}
/* Whenever a category is not active we shouldnt display it to customer */
if ((bool)$category['active'] === false) {
continue;
}
$html .= '<li'.(($this->page_name == 'category'
&& (int)Tools::getValue('id_category') == (int)$category['id_category']) ? ' class="sfHoverForce"' : '').'>';
$html .= '<a href="'.$link.'" title="'.$category['name'].'">';
if($category['level_depth'] == '3' AND Tools::file_exists_cache(_PS_CAT_IMG_DIR_.(int)$category['id_category'].'_thumb.jpg'))
$html .= '<img src="/img/c/'.(int)$category['id_category'].'_thumb.jpg'.'" class="imgm" height="30" /><br>';
$html .= $category['name'];
$html .='</a>';
if (isset($category['children']) && !empty($category['children'])) {
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);
$html.= '<li class="sfHoverForce">'.$category['promo_right'].'</li>';
$html .= '</ul>';
}
$html .= '</li>';
}
return $html;
}
受保护函数generateCategoriesMenu($categories,$is\u children=0)
{
$html='';
foreach($key=>$category的类别){
如果($category['level_depth']>1){
$cat=新类别($Category['id_Category']);
$link=Tools::HtmlEntitiesUTF8($cat->getLink());
}否则{
$link=$this->context->link->getPageLink('index');
}
/*当类别不活动时,我们不应向客户显示它*/
if((bool)$category['active']==false){
继续;
}
$html.='';
$html.='';
if(设置($category['children'])和&!empty($category['children'])){
$html.='';
$html.=$this->generateCategoriesMenu($category['children',1);
$html.='- 。$category['promo_right'].
;
$html.='
';
}
$html.='';
}
返回$html;
}
我想通过编辑ps_主菜单模板文件,与您分享我在Prestashop 1.7上的解决方案:
<div {if $depth === 0} class="popover sub-menu js-sub-menu collapse"{else} class="collapse"{/if} id="top_sub_menu_{$_expand_id}">
{menu nodes=$node.children depth=$node.depth parent=$node}
{if $node.image_urls}
{foreach from=$node.children depth item=mychild}
{foreach from=$mychild.image_urls item=image_url}
<img src="{$image_url}" title="" alt="" />
{/foreach}
{/foreach}
{/if}
{菜单节点=$node.children深度=$node.depth父节点=$node}
{if$node.image_url}
{foreach from=$node.children depth item=mychild}
{foreach from=$mychild.image\u url item=image\u url}
{/foreach}
{/foreach}
{/if}
请看我的文章:
启用类别缩略图后是否重新生成图像?每个类别的缩略图是否在img/c/文件夹中?