After i changed our hosting (different php versions)
current hosting - PHP 5.3.3 (cli)
previous one - PHP 5.5.19 (cli)
Some code in our WP site stop working, try to make changes, but w/o any success. "If" and "else" works well, but when i try to add "elseif" it stops working.
Here is my code pastebin link
thanks
Maybe you missed { or } if it's longer than 1 line code after. Try add a space like this: "else if".
Good luck! I hope i helped you.
You were missing a ;, I don't know it that was the problem.
Anyways this is the same code (just with some indentation), it should work properly.
<?php if($page_id == 35) : ?>
111
<?php elseif($page_id == 55) : ?>
22
<?php else: ?>
Other
<?php endif; ?>
If that does still not work, you can try to use else: if way:
<?php if($page_id == 35) : ?>
111
<?php else:
if($page_id == 55) : ?>
22
<?php else: ?>
Other
<?php endif; ?>
<?php endif; ?>
Added indentation for clarification purposes
Related
I'm using Opencart 2.3.0.2 and would liek to show or hide the product code based on if the user is logged in.
in product.tpl I have tried changing:
<li><?php echo $text_model; ?> <?php echo $model; ?></li>
to
<?php if ($logged) { ?>
<li><?php echo $text_model; ?> <?php echo $model; ?></li>
<?php } ?>
but I get an error message stating that logged is not defined in product.tpl
I have also editing controller/common/header.php to include the following in various places with no luck.
$data['logged'] = $this->customer->isLogged();
What am I doing wrong?
Thank you
You must declare logged in corresponding controller file. So you nee add $data['logged'] = $this->customer->isLogged();
to:
catalog/controller/product/product.php file.
I'm looking to move "Submitted By" info from node.tpl to page.tpl however when I add the following from node.tpl I get errors. Im assuming I dont have access to those variables, but would like to know how I can set up a pre-proccess to get it to display as it does in the node.tpl
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
You can either use a preprocess function in the template.php of your theme, as explained here:
https://drupal.stackexchange.com/questions/40222/how-can-i-print-node-authors-last-login-date-on-page-tpl-php
In your case it would look like this (tested on Drupal 7):
function yourtheme_preprocess_page(&$variables) {
$variables['author'] = "";
if (isset($variables['node']) && ($account = user_load($variables['node']->uid))) {
$variables['author'] = $account->name;
}
}
And then in your page.tpl.php use this:
Submitted by: <?php print $author; ?>
If you don’t want to touch any of your theme’s files, but you need to output the author’s name in another region as the node content, you could create a view (block display) containing the node author, and assign it to the region.
While normally done in node.tpl.php, if the page is a node view page, the $node variable is also available in page.tpl.php
You can then use something like:
if (isset($node)) {
// Check if display submitted variable is set for this node type
if (variable_get('node_submitted_'. $node->type, 0)) {
// Do stuff
}
}
An alternative approach would be adding the required logic instead to an implementation of
hook_preprocess_page
Bonus update: You can see the $node variable added to page.tpl.php in core template_preprocess_page
if ($node = menu_get_object()) {
$variables['node'] = $node;
}
In page.tpl.php:
<div class="submitted">
<?php echo format_date($node->created, 'custom','d.m.Y'); ?><br />
<?php echo 'by ' . $node->name; ?>
</div>
I've been trying to create simple script that swaps table data based on the active currency code. It's for a size chart (on product.tpl).
PREMISE:
IF "USD" is active then display table "A" (Inches), ELSE display table "B" (Centimeters).
I'm a total hack with php/js, but enough to find my way into trouble. :)
I followed this thread to bring the currency code variable into "product.tpl": How to get currency to show on product page in opencart?
Now I'm just banging my head, I can't find the right variable to create the swap... I've tried multiple variations of a simple If/Else script, basically like this:
<?php if ($currency['code'] == $currency_code) { ?>
<td>15.5"</td>
<td>25"</td>
<?php } else { ?>
<td >40cm</td>
<td >64cm</td>
<?php } ?>
Anyone have a clue what the script might look like?
Or am I totally barking at the wrong cat here?? Thx
Just use the session value for the currency code...
<?php if($this->session->data['currency'] == 'USD') : ?>
<td>15.5"</td>
<td>25"</td>
<?php else: ?>
<td>40cm</td>
<td>60cm</td>
<?php endif; ?>
I'd like to use my product tags as meta keywords on every product page. Can anyone help me with this code?
Thaks
Below are some tips and they are general but give a direction of the different approaches to do this. Step 4 is a bit obvious. I am sorry but this not a module request forum, your question I think is fair so this direction set should get you in the right direction.
1 - Open catalog/view/theme/default/product/product.tpl
And do a find and replace with the header echo:
<?php
$getKeysandReplace=$header;
$getKeysandReplace=str_replace("<meta name=", "");
?>
Understand? Or use a regex to delete the Meta Keyword and Meta Description from the $header string and replace them with your own on the product.tpl - just grab the tags echo in the below code.
<?php if ($tags) { ?>
<div class="tags"><b><?php echo $text_tags; ?></b>
<?php for ($i = 0; $i < count($tags); $i++) { ?>
<?php if ($i < (count($tags) - 1)) { ?>
<?php echo $tags[$i]['tag']; ?>,
<?php } else { ?>
<?php echo $tags[$i]['tag']; ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
2 - You can edit header.tpl and do a IF($GET or if page is product type page then display this Meta Tag or display the normal tags.
3 - You can do an SQL crob job that copies the product tags, and places them as product keywords in your database everyday.
4 - Make sure staff copy and paste the tags as keywords to in the admin panel - stating the obvious
In the code below I'd like to show the created date, author and have them be linked but nothing for they do not show. I believe I need to be doing $node-> rather that row, haven't figured out the exact code. Or what if anything I need to change under Views in my Drupal 6 installation. Thanks in advance!
<?php if($node->type == 'blog'): ?>
<div class="blog-page">
<div class="title-post">
<div class="top-image">
<?php print $node->field_image[0]['view'] ?>
</div><!--TOP-IMAGE-->
<p>Posted on ?php $row['created'] ?>, by
<?php print $row['name'] ?></p>
</div>
<div class="content-page">
<?php print $node->content['body']['#value'] ?>
</div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>
Drupal has a node object with tons of related information in it. Basically if you ever need to use information from it like author, date, title, etc, you can easily determine the code by printing the node object.
echo '<pre>';
print_r($node);
echo '</pre>';
lets say it outputted something like this for simplicity's sake:
stdClass {
nid = 3
content = stdClass {
raw = " ... "
clean = " ... "
}
}
To output those bits of information in your template, you'd write in the following way.
for a field with no subclass:
<?php print $node->nid ?>
for a field with a subclass:
<?php print $node->content['raw'] ?>
Does that make sense? after you get that down, you literally can figure out anything when programming drupal templates.
so, if you wanted to construct a url, you'd just chain it up:
<?php
$nid = $node->nid;
$uri = "some/path".$nid;
print $uri;
?>