0

I'm using Fishpigs Wordpress integration module in a Magento store. When I set it to use a custom Wordpress menu, which I've set up in Wordpress with some category hierarchies, it doesn't add any active states if you've clicked a link and are on an "active" page. After digging about, /app/code/community/Fishpig/Wordpress/Model/Menu/Item.php has the following:

public function isItemActive()
{
    return false;
}

So it seems like they've just skipped this bit? Anyone any idea how to set active states here?

3 Answers 3

0

OK, this seems to do the job, bit of a workaround but hey!

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

Get the current url, get the blog url, if they match set active state to true. I then used a bit of jQuery to set states of parents to active as the above only sets the current link:

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

...where li.nav-3 is the parent blog link

0

Replace the isItemActive function with following code in /app/code/community/Fishpig/Wordpress/Model/Menu/Item.php. This is working for me.

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;
        }
    }
1
  • Thanks Sport for making my answer in perfect structure.
    – Chandresh
    Apr 7, 2015 at 6:29
0

The problem is just a simple miss.. Magento uses a "/" in all urls,$currentUrl never matches $currentUrl because of this. The correction is just to trim the "/" I know a late response, but thought it may help someone.

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(), '/');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.