【问题标题】:Fishpig Magento/Wordpress Integration - Appending a WordPress custom menu doesn't set active statesFishpig Magento/Wordpress 集成 - 附加 WordPress 自定义菜单不会设置活动状态
【发布时间】:2023-03-04 23:12:01
【问题描述】:

我在 Magento 商店中使用 Fishpigs Wordpress integration module。当我将其设置为使用自定义 Wordpress 菜单(我已在 Wordpress 中设置了一些类别层次结构)时,如果您单击链接并位于“活动”页面上,它不会添加任何活动状态。经过一番挖掘,/app/code/community/Fishpig/Wordpress/Model/Menu/Item.php有以下内容:

public function isItemActive()
{
    return false;
}

所以他们似乎只是跳过了这一点?有人知道如何在这里设置活动状态吗?

【问题讨论】:

    标签: wordpress magento fishpig


    【解决方案1】:

    好的,这似乎可以完成工作,有点解决方法但是嘿!

    public function isItemActive()
    {
        $currurl = Mage::helper('core/url')->getCurrentUrl();
        $linkurl = $this->getUrl();
        if(strstr($linkurl, $currurl)){
            return true;
        }
        else {
            return false;
        }
    }
    

    获取当前 url,获取博客 url,如果它们匹配,则将活动状态设置为 true。然后我使用了一些 jQuery 将父母的状态设置为活动,因为上面只设置了当前链接:

    $('#nav li.nav-3 ul li.level1.active').parent().parent().addClass("active");
    

    ...其中 li.nav-3 是父博客链接

    【讨论】:

      【解决方案2】:

      将 isItemActive 函数替换为 /app/code/community/Fishpig/Wordpress/Model/Menu/Item.php 中的以下代码。这对我有用。

      public function isItemActive() {
              $myblogUrl = Mage::helper('wordpress/abstract')->getBlogRoute();
              $mycurrentUrl = preg_replace('/\?.*/', '', Mage::helper('core/url')->getCurrentUrl());
              if (in_array($myblogUrl, explode("/", $mycurrentUrl))) {
                  return true;
              } else {
                  return false;
              }
          }
      

      【讨论】:

      • 感谢 Sport 让我的回答结构完美。
      【解决方案3】:

      问题只是一个简单的失误。Magento 在所有 url 中都使用“/”,因此 $currentUrl 永远不会匹配 $currentUrl。更正只是为了修剪“/”我知道响应较晚,但认为它可能对某人有所帮助。

      public function isItemActive()
      {
          $currentUrl = Mage::getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true));
      
          if (strpos($currentUrl, '?') !== false) {
              $currentUrl = substr($currentUrl, 0, strpos($currentUrl, '?'));
          }
      
          return $currentUrl === rtrim($this->getUrl(), '/');
      }
      

      【讨论】:

        猜你喜欢
        • 2012-09-26
        • 1970-01-01
        • 2017-01-31
        • 2012-08-30
        • 2017-12-20
        • 1970-01-01
        • 2012-07-05
        • 1970-01-01
        • 2015-12-20
        相关资源
        最近更新 更多