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">
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";
}
?>
I am working on OpenCart 1.5.6.4. I want to add dynamic CSS class in content box. I want the following options for the content box layout:
left panel + main content + right panel
only left panel + main content
only main content + right panel
only main content (without left & right panels)
With the following code each case except the main content + right panel is working:
<?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; ?>">.....</div>
I get this results:
What is wrong here with the last option? How can I fix it?
Would appreciate the help.
Your code looks completely fine and should be working. The reason it seems it is not is because most probably you have some data in the $column_left even if it should be empty (thus considered as false).
The best bet is to either check the $column_left variable when there should be only main content + right column displayed (print_r($column_left)) or check the left column's template immediately (catalog/view/theme/<YOUR_THEME>/template/common/column_left.tpl).
Normally the code in column_left.tpl should be
<?php if ($modules) { ?>
<div class="column_left">
<?php /* ... */ ?>
</div>
<?php } ?>
It is possible that You have something like this instead:
<div class="column_left">
<?php if ($modules) { ?>
<?php /* ... */ ?>
<?php } ?>
</div>
therefore there is empty <div> and your code correctly uses col-sm-6 for main content.
After fixing the column_left.tpl you should have col-sm-9 for main content + col-sm-3 for right column if there is no left column data.
I have a template for all my web pages but i want a div class not to be seen on certain pages. I use the URL to get the content out of a database with php so an example of my URL
= index.php?categorie=navigatie_bar&onderwerp=startpagina
I need a code to say get catagory from the url and if catagory is not navigation_bar
echo '<div class"fb-comments"></div>';
can someone help ?
<div id="container">
<div id="pagina_text">
{{ CONTENT }}
</br>
<div class="rw-ui-container"></div>
</br></br>
<?php
if(strcmp($_GET['categorie'], "navigatie_bar") != 0)
{
echo '<div class="fb-comments" data-href="http://alledaagsetips.nl" data-numposts="10" data-colorscheme="light"></div>';
}
?>
</div> <!-- end pagina_text -->
</div><!-- end container -->
You can access the URL variables via $_GET['name_of_parameter'].
if(strcmp($_GET['category'], "navigation_bar") != 0)
{
echo '<div class="fb-comments"></div>';
}
In this case, only if index.php?category=navigation_bar the div will be echoed.
Take attention to your spelling, in your example you wrote catagory instead of category
EDIT:
You can do $_GET['category'] == 'navigation_bar', but for string comparisons it is sometimes safer to use the strcmp (string compare) function.
See String comparison using == vs. strcmp
try this
<?php
if($_REQUEST['category'] != 'navigation_bar'){
echo '<div class="fb-comments"></div>';
}else{ //do this }
?>
I think this is just basic PHP, a simple condition. But you seem to have also errors in our template. I would suggest running a w3c validator check, so you can see what you have wrong (wrongly nested tags, syntax mistakes etc..)
W3C Validator Online
UPDATE:
<div id="container">
<div id="pagina_text">
{{ CONTENT }}
<br />
<div class="rw-ui-container"></div>
<br /><br/>
<?php
if(strcmp($_GET['categorie'], "navigatie_bar") != 0)
{
echo '<div class="fb-comments" data-href="http://alledaagsetips.nl" data-numposts="10" data-colorscheme="light"></div>';
}
?>
</div> <!-- end pagina_text -->
</div><!-- end container -->
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
I have a PHP page with HTML content in it. Now I run some PHP codes between HTMLs and I get some results. The fact is, when I try to get a respond from this page by AJAX it'll show me the whole page content and plus the result I was looking for. What can I do to prevent the page from writing extra content. I know whenever something get printed on page it'll go as respond to the AJAX call but I want a way to somehow fix this.
My page file (name: page.php):
<?php echo $Content->GetData('HEADER'); ?>
<div id="Content">
<div id="Page">
<?php if($Content->GetData('PAGE','IS_TRUE')) : ?>
<?php if(NULL !== $Content->GetData('PAGE','TITLE')) : ?>
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",BeforeTitle"); ?>
<div id="Title" dir="rtl">
<?php echo $Content->GetData('PAGE','TITLE'); ?>
</div>
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",AfterTitle"); ?>
<?php endif; ?>
<div id="Content" dir="rtl">
<div style="float: right; width: 966px; padding: 6px">
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",BeforeContent"); ?>
<?php echo $Content->GetData('PAGE','CONTENT'); ?>
<?php echo $Content->GetPlugins("Page:" . $Content->GetData('PAGE','ID') . ",AfterContent"); ?>
</div>
</div>
<?php else : ?>
<div id="Content" dir="rtl">
<div style="float: right; width: 966px; padding: 6px">
There is no page like this in our archives.
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php echo $Content->GetData('FOOTER'); ?>
If I write an address in my browser like this localhost/cload/blog?action=rate it'll go through my redirection list and show the page.php with blog plugin loaded. The problem is I want to call my blog plugin by AJAX through this address but it will first render the page data.
Sorry if this is messy.
I'd suggest modifying page.php to be some functions, primarily a data processing function, and then an output function. Then, when you load the page, put a check in for whether it's an AJAX request, and if so, echo the data you want as JSON, otherwise render the page using the output function.
Alternatively, you could create a second, separate page, but that could be more difficult to maintain than a single file.
Yes, you should check whether your request is a ajax request, if it is so you should change your response to return only the result whatever want.
This php code will give an rough idea on this.
if($request->isXmlHttpRequest()){
return new Response(json_encode($data_array));
}
Hope this will help.