在没有结果的搜索页面上显示特定类别的产品 [英] Display specific category products on no results search page

查看:108
本文介绍了在没有结果的搜索页面上显示特定类别的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在magento网站中搜索错误的关键字(如"sdfsdf")时,它显示您的搜索未返回结果".在这里,我要显示任何类别的产品,例如相似产品"类别,因为我们在首页上显示畅销书".我已经尝试通过调用catalogsearch.xml中的块来进行尝试. BU Catalogue.xml确实包含任何块,没有结果.因此,如何在没有结果的页面上显示任何类别的产品.

When we search for a wrong keyword like "sdfsdf" in magento site, it displays that "your search returns no results". Here I want to display any category products like "similar products" category as we display "best sellers" on home page. I have tried by calling the block in the catalogsearch.xml. BUt catalogsearch.xml doent contain any block for no results. So how can I display any category products on no results page.

我有一个想法,例如我们可以在.phtml页面上显示特定类别的产品吗?如果我们可以显示产品的特定类别,则可以从"result.phtml"中调用该类别.有帮助吗?

I have an idea like can we display a specific category products on .phtml page? If we can display specific category of products then we can call that category from "result.phtml". Any help?

我的result.phtml

my result.phtml

<?php if($this->getResultCount()): ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title category-title">
    <?php if ($this->helper('rss/catalog')->getTagFeedUrl()): ?>
        <a href="<?php echo $this->helper('rss/catalog')->getTagFeedUrl() ?>" class="nobr link-rss"><?php echo $this->__('Subscribe to Feed') ?></a>
    <?php endif; ?>
    <h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
    <?php if ($messages = $this->getNoteMessages()):?>
    <p class="note-msg">
        <?php foreach ($messages as $message):?>
            <?php echo $message?><br />
        <?php endforeach;?>
    </p>
    <?php endif; ?>
    <?php echo $this->getProductListHtml() ?>
<?php else: ?>
<div class="page-title category-title">
    <h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<p class="note-msg">
    <?php echo ($this->getNoResultText()) ? $this->getNoResultText() : $this->__('Your search returns no results.') ?>
    <?php if ($messages = $this->getNoteMessages()):?>
        <?php foreach ($messages as $message):?>
        <br /><?php echo $message?>
        <?php endforeach;?>

    <?php endif; ?>
 </p>
<div class="search-noresults">
<h1>Meanwhile, You may go through our featured categories:</h1>  
</div>
<?php echo $this->getLayout()->CreateBlock('catalog/product_list')->setCategoryId(18)->setTemplate('catalog/product/list.phtml')->toHtml();?>

<?php endif; ?>

推荐答案

在catalogsearch/result.phtml模板中有一个简单的解决方案,您需要设置没有结果时会发生什么

A simple solution is within catalogsearch/result.phtml template you would need to setup what happens when there are no results

<?php if($this->getResultCount()): ?>
SHOW RESULTS
LEAVE DEFAULT
<?php else: ?>
NO RESULTS
<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(4)->setTemplate('catalog/product/list.phtml')->toHtml() ?>
<?php endif; ?>

这篇关于在没有结果的搜索页面上显示特定类别的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆