I have an opencart category page that I am trying to hide the title DIV for. Out of all the categories and sub cats there is (for now) only one that I am trying to hide.
The following code I have used does not work:
<?php if ($categories && $heading_title!="HEADING TITLE HERE") { ?>
<?php elseif : ?>
<div id="headerhide" style="width:800px;">
<h1><?php echo $heading_title; ?></h1>
</div>
<?php } ?>
<?php endif ?>
<?php if ($categories && $heading_title!="HEADING TITLE HERE") { ?>
<?php }
else {
?>
<div id="headerhide" style="width:800px;">
<h1><?php echo $heading_title; ?></h1>
</div>
<?php } ?>
<?php if ($categories && $heading_title!="HEADING TITLE HERE") { } else { ?>
<div id="headerhide" style="width:800px;">
<h1><?=$heading_title?></h1>
</div>
<?php } ?>
I have this setup on my OpenCart information.tpl page:
<?
// If FAQs page or content show AJAX
// We check for case sensitive titles - the title is case sensitive
if($heading_title=="FAQs" || $heading_title=="Faqs") { ?>
<script type="text/javascript">
$(document).ready(function(){
// ETC
});
</script>
<?
// Not the FAQs page so do nothing
}
?>
I've recently made a commercial vQmod that will be of use to you for this. It's called Custom Templates and will allow you to assign it to as many individual category pages as you want. It works for more than just categories too (manufacturer, product and info pages). While it may be a bit overkill for one page, if you plan on using it for multiple pages in the future it will be better in the long run in my opinion
Related
I would like to detect a certain category with ID=4 and then apply if/else to add div to display contents.
<?php
if (JRequest::getVar('view')=='categories' && JRequest::getVar('id')==4) { ?>
<?php } ?>
How do I achieve this?
I want to show this if the article belongs to category 4 else show another div.
Imagining this two be the different div
<div class="category4">text here</div>
<div class="categoryxxx">text here</div>
Do note that <?php echo $this->item->catid;?> shows the correct Category ID. I would like to apply if and else statement using catid==9 or something. Just not good at PHP.
You can also put directly the html code, avoiding echo. It may useful especially when html code is sizeable.
<?php if ($this->item->catid == 4): ?>
<div class="category4">text here</div>
<!--- any other html code --->
<?php else: ?>
<div class="categoryxxx">text here</div>
<!--- any other html code --->
<?php endif; ?>
Hey I got it working :)
<?php
if ($this->item->catid == 9) {
echo "yes, it exists";
}
else {
echo "no, it don't exist";
}
?>
For my new wordpress site I need some help. I got 4 pages and 2 different sidebars. On 2 pages there shouldn't be a border-left and on the other 2 pages there should be a border-left. So I got following code:
<div id="sidebar" class="sidebar">
<?php if(is_page('Willkommen') || is_page('Angebot'))
{
dynamic_sidebar('Angebot');
}
else
{
dynamic_sidebar('Anfahrt');
if(is_page('Anfahrt'))
{
echo "<script type='text/javascript'>
function removeBorder()
{
$(document).ready(function() {
if($('#sidebar').hasClass('sidebar'))
{
$(this).removeClass('sidebar')
$(this).addClass('secondsidebar')
}
});
}
</script>";
}
}
?>
</div><!-- sidebar -->
I want to remove the class "sidebar" and add the class "secondsidebar" if there is a div#sidebar on the page. But the code won't work. I wrote this code for myself and I'm a beginner in jQuery :) So please be patient.
I hope someone can give me a hint.
Cheers
A pure PHP solution should be possible as well.
<div id="sidebar" class="<?php if (is_page('Anfahrt')) : ?>secondsidebar<?php else : ?>sidebar<?php endif; ?>">
<?php
if (is_page('Willkommen') || is_page('Angebot')) {
dynamic_sidebar('Angebot');
}
else {
dynamic_sidebar('Anfahrt');
}
?>
</div>
NOTE: try not to use IDs and classes with the same name. #sidebar and .sidebar might get confusing.
Explanation for the classes:
<div id="sidebar" class="<?php if (is_page('Anfahrt')) : ?>secondsidebar<?php else : ?>sidebar<?php endif; ?>">
When the server reads this (PHP is code that is executed by the server before rendering the result back to the user) it comes to "class" and it notices an if-statement. "what text should I put in the class="" of this element?" The server then sees the instructions:
If the page is "Anfahrt": the text to return should be secondsidebar
Else (in all other cases): the text should be sidebar
"Text" isn't really a good name here. But you get what I mean. This "text" is then placed where the if-statement is. The result then is (as it is returned to a user):
If the page is "Anfahrt":
<div id="sidebar" class="secondsidebar">
If the page is anything else:
<div id="sidebar" class="sidebar">
I am sure this is a fairly simple question to answer, but I am new to PHP, so I was hoping someone could help me solve this problem.
I have a dynamic navigation menu that works really well, but I want to remove the link from the current page in the menu.
Here is my code:
<div id="navigation_menu">
<?
foreach($pagedata->menu as $menuitem){
$class = ($menuitem->uri == $requesteduri) ? 'navigation selection' : 'navigation page_select';
?>
<div id="<?=$menuitem->uri?>" class="<?=$class?>">
<img class="nav_icon" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/<?=$menuitem->uri?>.png">
<h1><?=$menuitem->title?></h1>
<h2><?=$menuitem->description?></h2>
<img class="go" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/go.png">
</div>
<?
}
?>
</div>
Any help would be greatly appreciated. Thanks!
UPDATED CODE: (this is what works for me now)
<div id="navigation_menu">
<?
foreach($pagedata->menu as $menuitem){
$class = ($menuitem->uri == $requesteduri) ? 'navigation selection' : 'navigation page_select';
?>
<div id="<?=$menuitem->uri?>" class="<?=$class?>">
<img class="nav_icon" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/<?=$menuitem->uri?>.png">
<h1>
<?php if ($menuitem->uri == $requesteduri):?>
<?=$menuitem->title;?>
<?php else: ?>
<?=$menuitem->title?>
<?php endif;?>
</h1>
<h2><?=$menuitem->description?></h2>
<img class="go" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/go.png">
</div>
<?
}
?>
</div>
I don't know what your loop is outputting, but you want to match your page name with the menuitem->uri. So you'd get your page name like.. (Put this outside the loop)
<?php echo base_name($_SERVER['REQUEST_URI']); ?>
find out what your loop is outputting (Put this in the loop):
<?php echo $menuitem->uri; ?>
Then you'd create an if statement to compare the current menuitem in the loop and the page request, this is just an example:
<h1>
<?php if (base_name($_SERVER['REQUEST_URI']) == $menuitem->uri):?>
<?=$menuitem->title?>
<?php else: ?>
<?=$menuitem->title;?>
<?php endif;?>
</h1>
Put a conditional around the anchor text to see if $menuitem->uri is equal to the current page URL, accessible from `$_SERVER['REQUEST_URI'] before outputting the anchor tags.
I created a conditional statement for my custom theme in Concrete5. My codes goal is to toggle layout. If the current page has a child pages under it, it will display an additional sidebar (<div class="grid_3">) to list the subpages items. If there's no child page it would display a full layout (<div class="grid_13">).
Unfortunately I get a different result. there's something I probably had missed on my condition statement. Instead of just display one layout, It is rendering the two layout.
Below is what my code look like:
<? if($c->getNumChildren()) { ?>
<div class="grid_3">
<?php
$bt_sidenav = BlockType::getByHandle('autonav');
$bt_sidenav->controller->orderBy = 'display_asc';
$bt_sidenav->controller->displayPages = 'below';
$bt_sidenav->controller->displaySubPages = 'all';
$bt_sidenav->render('view');
?>
</div>
<div id="main-content-container" class="grid_10">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } else { ?>
<div id="main-content-container" class="grid_13">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } ?>
While your content generation portions of PHP use proper PHP tags (<?php … ?>), your if/else statements use short tags (<? … ?>) which are often disabled.
Use <?php instead.
try to do like this may this will solve the issue
<?php if($c->getNumChildren()!='') { ?>
...
<?php } else { ?>
...
<?php } ?>
I have this code in top.phtml which displays my menu items in my Magento store:
<div class="header-nav-container">
<div class="header-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav">
<li <?php if(!Mage::registry('current_category')) { echo 'class="level0 active"'; } else { echo 'class="level0"'; } ?>><span><?php echo $this->__('Home') ?></span></li>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
<li <?php if(!Mage::registry('current_category')) { echo 'class="level0 active"'; } else { echo 'class="level0"'; } ?>><span><?php echo $this->__('Sale Items') ?></span></li>
</ul>
</div>
I have an extra li at the bottom which displays another page. The problem I have occurs when I click the ‘Sales Item’ page: its link becomes active but so does the home page link. How can I prevent the home page link from appearing active?
I’ve added a screenshot to show the problem:
Screenshot
The lines for Home and Sale Items are both outputting an active category link when the current category is not defined, via the code if(!Mage::registry('current_category')). Instead of checking the category, check the current controller/action.
Here's a list of URL functions (for getting the controller/action):
http://docs.magentocommerce.com/Mage_Core/Mage_Core_Model_Url.html
Code like this should work. It depends on whether or not catalogsale is the identifier for a custom controller or action, which depends on your setup:
if ($this->getRequest()->getControllerName() == 'catalogsale')
// Output active class declaration
/* Otherwise, try looking at the action name. */
if ($this->getRequest()->getActionName() == 'catalogsale')
// Output active class declaration
I ended up fixing this using some javascript. I added this to the new page:
<script type="text/javascript">
Event.observe(window, 'load', function() {
$$('li.active').invoke('removeClassName','active');
$$('li.newmenu').invoke('addClassName','active');
});
</script>
The new menu item should have a class of 'newmenu' for the above code to work.