0
votes

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

3 Answers

0
votes

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
votes

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;
        }
    }
0
votes

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