Magento - check if cms page - php

i want to check via php if a page is a cms_page in Magento. I need diffrent breadcrumbs for cms pages, so im trying to this with a condition, but i have no idea how to or where to look at.
Heres my breadcrumbs.phtml so far.
<?php if(this is a cms page): ?>
<p>some content</p>
<?php else: ?>
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php $charsges = 0; ?>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<?php
$charsges = strlen($_crumbInfo['label']) + $charsges;
if($charsges > 40){
$chars = 18;
if(strlen($_crumbInfo['label']) > $chars){
$_crumbInfo['label'] = substr($_crumbInfo['label'], 0, $chars);
$_crumbInfo['label'] = $_crumbInfo['label'].'..';
}
}
?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span> > </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
greets rito

The following should give you what you want
//from a block or phtml script
$this->getRequest()->getModuleName()
When this returns the string 'cms', you're on a CMS page.
When Magento's frontend and admin routers can't find a match on your URL, the CMS router takes over. If the CMS router finds a match (based on the CMS pages you've setup), it hands off the request to the cms module and Mage_Cms_IndexController controller.

Related

Magento PHP if statement "load both blocks" , else load only one?

maybe it is something simple but i am not really good with php
With this code i am able to load the static blocks styled in top of category in Magento and the subcategories in the bottom when the top category has child
What i am trying to do is that when there is no child category it should only load the block
otherwise because of styling it will hold the place that the subcat had position.
Please have a look on my code and maybe you understand:
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<div class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></div>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
$_catHtml = $this->getChildHtml('catalog.inline.subcat');
?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
// load the blocks styled with ul and il backgrounds
<ul class="inline-categories">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId( $this->getCurrentCategory()->getLandingPage() )->toHtml() ?>
<?php foreach ($_categories as $_category): ?>
<li<?php if($_i == 1):?> class="first"<?php endif ?>><a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>>
<?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)</li>
<?php endforeach ?>
<?php endif; ?>
</ul>
// here i need something like an "else" because the if($count) allready understand that this is not on count so should only load this that is without style //
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId( $this->getCurrentCategory()->getLandingPage() )->toHtml() ?>
//end of this else thing, now should only load the cms/block alone without anything / end of page we are done...
You can use PHP's if/else statements like this:
<?php if ($_count): ?>
stuff if $_count is non-zero
<?php else: ?>
other stuff if $_count is zero
<?php endif; ?>

How to add "tags" in joomla 3.x blog layout

I would like to add the article tags in my blog layout in joomla 3.x.
I overwrote the joomla layout files and tried to add the code below in blog_style_default_item_title.php as it is in article
<?php if ($params->get('show_tags', 1) && !empty($this->item->tags)) : ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
<?php endif; ?>
but it did not work. I guess variable name is not the good one. Any ideas?
My knowledges in php language are pretty weak but I had a look and tried a few think.
I finaly got something by adding code below in /com_content/category/blog_items.php
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
but i would like to add "tags" on the title line so in blog_style_default_item_title.phpfile
<?php
defined('_JEXEC') or die;
// Create a shortcut for params.
$params = $displayData->params;
$canEdit = $displayData->params->get('access-edit');
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
JHtml::_('behavior.framework');
?>
<?php if ($params->get('show_title') || $displayData->state == 0 || ($params->get('show_author') && !empty($displayData->author ))) : ?>
<div class="page-header">
<?php if ($params->get('show_title')) : ?>
<h2>essai
<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>">
<?php echo $this->escape($displayData->title); ?></a>
<?php else : ?>
<?php echo $this->escape($displayData->title); ?>
<?php endif; ?>
</h2>
<?php endif; ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
<?php if ($displayData->state == 0) : ?>
<span class="label label-warning"><?php echo JText::_('JUNPUBLISHED'); ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
But i have a error???
Here is how they are added to individual weblinks
<?php $tagsData = $item->tags->getItemTags('com_weblinks.weblink', $item->id); ?>
<?php if ($this->params->get('show_tags', 1)) : ?>
<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($tagsData); ?>
<?php endif; ?>
What you would want to do is something similar but for com_content.article and make sure the $item and $this->params references match what you have.
Here a picture of the design I would like
And he below the way the page id made of (as i understood it)
in blog_item.php there is this line which call the
...
<?php echo JLayoutHelper::render('joomla.content.blog_style_default_item_title', $this->item); ?>
....
and so in blog_style_default_item_title.php
....
<div class="page-header">
<?php if ($params->get('show_title')) : ?>
<h2>essai
<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>">
<?php echo $this->escape($displayData->title); ?></a>
<?php else : ?>
Did I make a mistake??

show cms pages in header navigation magento

Hi I need in my project to show the CMS pages link dynamically in header,
Can anybody suggest me How I can do this ?
with this code we can show magento cms page dynamically in magento navigation
which have status enabled. We just need to place this code in header or in topnav file
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()->where('is_active = 1'); ?>
<ul id="nav">
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php// print_r($PageData);?>
<?php if($PageData['identifier']!='no-route' && $PageData['identifier']!='enable-cookies' && $PageData['identifier']!='home2') { ?>
<li>
<span><?php echo $PageData['title'] ?></span>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>

PHP - limiting the output of a plugin

I'm using a plugin titled "WP Recent Links" which I first learned about via Eric Meyer's site. Eric uses to display a Link Log within his site and I'm doing the same on my test site - http://matala.jorgeledesma.net/ but I'm running into a little situation and that is that I don't know how to limit the output either on the sidebar or the actual page - http://matala.jorgeledesma.net/recent-links/
My goal is to have it echo only the first 5 entries on the sidebar and for the recent-links page only echo the current month. The code below displays the sidebar properly
<?php if (!is_page('48')) { ?>
<aside id="meta" class="widget">
<h1 class="widget-title">Link Log</h1>
<?php if ($links = rp_recentlinks_home()) { ?>
<ul>
<?php foreach ($links as $link) { ?>
<b><li><?php echo wptexturize($link->link_text); ?></b>
<?php if ('' != $link->link_caption) { ?>→
<?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</aside>
<?php } ?>
and this code display the actual recent-links page
<h1 class="page-title"><?php rp_recentlinks_archive_header(); ?></h1>
</header>
<div class="entry-content">
<?php $links = rp_recentlinks_archive_page(); ?>
</div>
<?php if ($links) { ?>
<ul>
<?php foreach ($links as $link) { ?>
<p id="rlink-<?php echo $link->ID; ?>"><?php echo wptexturize($link->link_text); ?>
<?php if ('' != $link->link_caption) { ?>→
<?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
</p>
<?php } ?>
</ul>
<?php } ?>
I tried putting the following code in the body.
$list = array_slice($input, 0, 5); // $list now only having first 5 item.
But I don't know how to apply it, if that's the command at all. So perhaps, someone can guide in the right direction. Thanks in advance, Jorge.
Looks like all you have to add is this before you pass $links to the foreach loop:
$links = array_slice($links,0,5);

Magento: Display sub-category list

I'm building a Magento store and want to be able to display a list of categories and have each category link to its own page.
I have a 'Brands' category with an ID of 42 and I want to display a list of the sub-categories and ensure that each one links to the designated URL key in the CMS.
Has anyone had experience of doing this with Magento?
If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/theme_name/template/catalog/category/view.phtml
<?php
$_category = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper = Mage::helper('catalog/category');
?>
<ul>
<?php foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
<?php
$cur_category = Mage::getModel('catalog/category')->load($cat->getId());
$_img = $cur_category->getImageUrl();
?>
<li>
<a href="<?php echo $helper->getCategoryUrl($cat);?>">
<img src="<?php echo $_img?>" title="<?php echo $cat->getName();?>"/>
<cite><?php echo $cat->getName();?></cite>
</a>
</li>
<?php endif?>
<?php endforeach;?>
</ul>
If You want to Display top level categories and subcategories U can do Like This..
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
For Displaying Top Level Categories and Current Categories SubCategories you can Do like ....
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php if ($currentCategory && $currentCategory->getId() == $_category->getId()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
This question requires a long answer. I will point you to the right places.
1) Best solution is to use the free extension. I haven't tried it, but it will suit the purpose. You will have to do some CSS to achieve the right look and feel.
http://www.magentocommerce.com/extension/1562/magento-easy-catalog-images
Demo: http://extension01.templates-master.com/gb/electronics.html
2) I do not trust in modules as it might become difficult to upgrade if the vendor decided to stop supporting it. I have used the information from the following forum thread to create a vew sites. Have a look... Might not be straight forward. You might have to make some copies of core files to the local directory.
http://www.magentocommerce.com/boards/viewthread/3770/P30/
Hopefully this will be of help to you :)
I made this little video on how I create custom category listing blocks with Magento.
I am sure there are better ways of achieving this or even something I could have done better, but it’s just my method. I only created this it in hopes that it helps explain somethings to some people out there.
Magento Custom Category Listing Block
Thanks!
after looking at all the solutions on the magento site, i found that wookiehangover's solution above worked and took about 8 seconds to implement.
creates a UL that you can style. thanks.
After creating static block you can get any list of the subcategories by this script:
$_helper = Mage::helper('catalog/category');
$_category = Mage::getModel('catalog/category')->load(5);
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) <= 0) { return; }
$count = 0;
foreach($_subcategories as $_category) {
$category = Mage::getModel('catalog/category')->load($_category->getId());
$ret->{"object_".$count} ->url = $_helper->getCategoryUrl($_category);
$ret->{"object_".$count} ->name = $_category->getName();
$ret->{"object_".$count} ->id = $_category->getId();
$ret->{"object_".$count} ->image = $category->getImageUrl();
$count++;
}
return $ret;
}
$list = list_subcategories(5);
echo "<pre>"; print_r($list); echo "</pre>";
?>
How about listing only the categories belonging to the current item. Not all the categories on the page.
But in a tree like view.
CATEGORIE - sub cat 1
CATEGORIE 2 - sub cat 1 - sub sub cat 1
BR Cveto

Categories