I'm using Magento 1.9 and struggling on one thing.
I have a CMS block in my category page but I want it to show only on the first page! So if I scroll down and move to page 2 on the same category I don't want to see that CMS block again.
I tried to put this code in the CMS block... but it ignores me
(category-accordion.accordion is the main div of the CMS block)
<script>
if (window.location.href.indexOf("?p=") >-1)
{document.getElementsByClassName('category-accordion accordion')[0].display='none';}
// ]]></script>
Any idea?
EDIT:
tried the following code on the category page:
<?php if($this->isContentMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php elseif($this->isMixedMode() && (strpos($_SERVER['REQUEST_URI'], '?=p') !== true)): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php echo $this->getProductListHtml() ?>
<?php elseif($this->isMixedMode() && (strpos($_SERVER['REQUEST_URI'], '?=p') !== false)): ?>
<?php echo $this->getProductListHtml() ?>
<?php else: ?>
<?php echo $this->getProductListHtml() ?>
<?php endif; ?>
you can set condition in Category View Template catalog\category\view.phtml.
<?php
$currentPage = (int) $this->getRequest()->getParam('p', 1);
if($currentPage <= 1) {
echo $this->getCmsBlockHtml()
} ?>
try this.
<script>
if (window.location.href.indexOf("?p=") >-1)
{
jQuery('.category-accordion.accordion').hide();
}
</script>
Related
I am trying to add the current node language to the div container of the template file ( I am using Drupal 7 ), here is the current content file I have override:
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<?php print $ds_content; ?>
I want it like so:
<div lang='en'>
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<?php print $ds_content; ?>
</div>
How can I get the language field where I have only $ds_content variable?
Any help, guide, example or reference appreciated!
You get the current node id through this way.
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
/** get node language **/
$language = node_load($nid)->language;
}
Then pass the language to div
<div lang='<?php print $language; ?>'>
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<?php print $ds_content; ?>
</div>
Hello everyone and thank you in advance that I will answer. I have this problem, I want to see the second page where I find a link that takes me home page blog if in other categories.
I developed this little code:
<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
<?php $link_address = "http://testjoomla0315.altervista.org/index.php?option=com_k2&view=itemlist&layout=category&Itemid=53" ?>
<?php $homeblog = "Blog" ?>
<?php $doc = JFactory::getDocument(); ?>
<?php $page_title = $doc->getTitle(); ?>
<?php echo $page_title; ?>
<?php if ($page_title != $homeblog) ?>
<?php echo "<a href='".$link_address."'>Home Blog</a>"; ?>
<?php endif; ?>
<?php echo $this->escape($this->params->get('page_title')); ?>
Unfortunately although not error the result is the same, or as if what I wrote was invisible. In homepage obviously sees the home page link (and that is the rule I)
Your code is missing a colon at the end of if statement.
Change
if ($page_title != $homeblog)
To
if ($page_title != $homeblog):
Also dont use <?php and ?> every line. You can have the code like this
<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
<?php
$link_address = "http://testjoomla0315.altervista.org/index.php?option=com_k2&view=itemlist&layout=category&Itemid=53";
$homeblog = "Blog";
$doc = JFactory::getDocument();
$page_title = $doc->getTitle();
echo $page_title;
if ($page_title != $homeblog):
echo "<a href='".$link_address."'>Home Blog</a>";
endif;
echo $this->escape($this->params->get('page_title'));
?>
I'm having an issue with open cart(v2.0.3.1) and the journal template (v2.4.9).
The issue: when I add a journal module like the Carousel, Banners etc. and try to place the module in the content section (either column_right, column_left or content_top, content_bottom) it won't show up on the site (not only home but all other pages aswell) However if I cange the position to "top" or "bottom" it does show up!
I've checked the file catalog/view/theme/journal2/template/common/home.tpl
to check if the columns are printed and saw this:
<div id="container" class="container j-container"><div class="row"><?php echo $column_left; ?> <?php echo $column_right; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?><?php echo $content_bottom; ?></div>
</div>
So they seem to be echoed however they don't show up on the website.
Actualy they do show up but only with the opencart elements not the custom elements made by the template.
I could use some help because i've been searching for 2 whole days and I can't seem to find a propper solution.
Need to figure this out for a client.
The problem was in the template after I updated it to a newer version the issue resolved!
I have created few static blocks just based on the category Id trying to display different blocks .
The problem being some times the block is displayed while some other times it is not .
I guess there is prob with code ? or the way magneto displays static blocks not sure ?
CODE:
<?php
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==14): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==15): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==16): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==18): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==19): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==86): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==25): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==13): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==98): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_fbyz')->toHtml();?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_others')->toHtml();?>
<?php endif; ?>
</div>
<?php endif; ?>
please resolve my problem.
If you put this code in product view page then it it not properly way to get current category in product page..
Used Mage::registry("current_category") instead of Mage::getModel('catalog/layer')->getCurrentCategory();
If you come to category directly then you can get current category id product page.then you used to fetch current product categories ids.
$categoryIds = Mage::registry('current_product')->getCategoryIds();
if(Mage::registry("current_category"))
{
$category = Mage::getModel('catalog/category')
->load(Mage::registry("current_category")->getId());
}elseif(is_array($categoryIds )){
//multiple categories id of product. that way i was taken on list category
$category = Mage::getModel('catalog/category')->load($categoryIds[0]);
}
elseif(!is_null($categoryIds)){
$category = Mage::getModel('catalog/category')->load($categoryIds);
}
else{
//no categoies
}
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; ?>