magento产品详细页添加返回分类链接,下一件,上一件产品链接

magento产品详细页返回分类链接,上一个,下一个产品链接
magento产品详细页返回分类链接,上一个,下一个产品链接

google了半天,找到了magento产品详细页添加返回分类目录链接,下一件,上一件产品链接的代码,贴在这里共享下。

我在magento 1.4.1.0上简单测试了下,没有发现什么问题,大家试试,有问题告诉我。

magento产品详细页返回分类链接,上一个下一个产品链接
magento产品详细页返回分类链接,上一个下一个产品链接

部分代码来源:http://www.magentocommerce.com/boards/viewthread/9946/P30/

此代码放在你的产品的view.phtml文件中即可。至于css自己补上吧,可以按照我的截图的样子放,比较方便。

代码如下:

<!--for next & prev link-->
<?php // prev- / next-link...
    $_helper = $this->helper('catalog/output');
    $_product = $this->getProduct();
    $prev_url = $next_url = $url = $_product->getProductUrl();

    if ($this->helper('catalog/data')->getCategory()) {
        $category = $this->helper('catalog/data')->getCategory();
    } else {
        $_ccats = $this->helper('catalog/data')->getProduct()->getCategoryIds();
        $category = Mage::getModel('catalog/category')->load($_ccats[0]);
    }

    $children = $category->getProductCollection();
    $_count = is_array($children) ? count($children) : $children->count();
    if ($_count) {
        foreach ($children as $product) {
            $plist[] = $product->getId();
        }

        /**
         * Determine the previous/next link and link to current category
         */
        $current_pid  = $this->helper('catalog/data')->getProduct()->getId();
        $curpos   = array_search($current_pid, $plist);
        // get link for prev product
        $previd   = isset($plist[$curpos+1])? $plist[$curpos+1] : $current_pid;
        $product  = Mage::getModel('catalog/product')->load($previd);
        $prevpos  = $curpos;
        while (!$product->isVisibleInCatalog()) {
            $prevpos += 1;
            $nextid   = isset($plist[$prevpos])? $plist[$prevpos] : $current_pid;
            $product  = Mage::getModel('catalog/product')->load($nextid);
        }
        $prev_url = $product->getProductUrl();
        // get link for next product
        $nextid   = isset($plist[$curpos-1])? $plist[$curpos-1] : $current_pid;
        $product  = Mage::getModel('catalog/product')->load($nextid);
        $nextpos  = $curpos;
        while (!$product->isVisibleInCatalog()) {
            $nextpos -= 1;
            $nextid   = isset($plist[$nextpos])? $plist[$nextpos] : $current_pid;
            $product  = Mage::getModel('catalog/product')->load($nextid);
        }
        $next_url = $product->getProductUrl();
    }
?>
<div class="prevNextcategoriesNavigation">
	<div class="for-next">
		<?php if ($url != $prev_url):?>
			<a class="next-product" href="<?php echo $prev_url; ?>">
				<?php echo $this->__('<- Prev') ?>
			</a>
		<?php endif; ?>
	</div>
	<div class="for-categories">
		<ul>
			<li> <?php echo $this->__('Back to Categories:') ?></li>
			<?php $categories = $_product->getCategoryIds(); ?>
			<?php foreach($categories as $k => $_category_id): ?>
			<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
			<li><a class="back-to-catalog" href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a></li>
			<?php endforeach; ?>
		</ul>
	</div>
	<div class="for-prev">
		<?php if ($url != $next_url):?>
			<a class="prev-product" href="<?php echo $next_url; ?>">
				<?php echo $this->__('next ->') ?>
			</a>
		<?php endif; ?>
	</div>
</div>
<!--for next & prev link-->

参考文章:http://inchoo.net/ecommerce/magento/simple-helper-class-for-previous-next-products-in-magento/

请大家注意自己的magento版本,可能因为版本原因需要调试代码。

转载表明出处:hellokeykey.com

《magento产品详细页添加返回分类链接,下一件,上一件产品链接》有14个想法

  1. 我想请教一个问题。

    我想要在产品详细页里加入购买记录和已售出数量。

    请问magento本身有没有这个功能呢?

  2. 如何实现点击产品连接到某个分类的页面,就像这个http://www.10uggstore.com/women-womens-classic-short-c-48_60.html

  3. 你好key。我是magento新手。刚刚接触magento就让我喜欢上了它。但我又开始讨厌他。因为我是其他语言过来的,所以什么都不懂,我想问个问题,可以的话帮我解答一下好吗!
    http://www.soqo.com/diecast-car.html这是我网站的一款车的目录。但是直接显示的是根目录下了。这对于SEO不好吧。
    我想让他显示成为:
    http://www.soqo.com/car/diecast-model-car.html这种形式。就是说地址栏显示类别目录。请问这个怎么实现。非常感谢帮帮我吧。

    1. magento的设置中可以设置是否将分类的名字加到产品页面的url中,修改此选项设置即可。应该在后台的system–》config里面找找可以找到这个。

  4. 太感谢key.gg。问题已经解决了。就是URL重写的问题。是类产品的途径设置问题。我会一直关注你的动态。真的很谢谢。

      1. key怎么在下一件,上一件产品改成下一件,上一件产品名。不想要那上一夜下一页的,想直接该成名

评论已关闭。