1

I already know how to get a specific URL in Magento and show something. It was already resolved in this page: https://stackoverflow.com/questions/25192212/get-current-url-in-magento-and-show-something

However, I noticed that it will only show what I want to show in the page alone. If I browse through its subpages, it doesn't show anymore.

For example the URL of my magento site is magento.com. And want to show something in magento.com/blog, thus I'll use this method:

$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$path = $url->getPath();
$blogPaths = array('/blog', '/blog/', '/index.php/blog/');
if(in_array($path, $blogPaths))
{
    //Do something on /blog
}

However, when I browse to a specific page on that subpage, for example, magento.com/blog/another-page-within-the-blog-page, the element that I'm trying to show disappears. It only appears in magento.com/blog

How can I let it appear in /blog, and all the pages under /blog?

I have tried array /blog/* but it didn't work. I guess what I did is simply not right. :(

1

I also posted this question in stackoverflow and it was resolved using this solution.

function startsWith($haystack, $needle)
{
    return $needle === "" || strpos($haystack, $needle) === 0;
}

$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$path = $url->getPath();
if (startsWith($path, '/blog/') || (strcmp($path, '/blog') == 0))
{
    //Do something on /blog and all pages underneath
}

This are for those who are having the same problem like me. :D

SOURCE: https://stackoverflow.com/questions/25297270/show-something-in-a-subpage-and-all-pages-under-that-subpage-in-php/25298390#25298390

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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