I am using ordered list with php and its working fine and showing the numbers 1-10 correctly but in the next page its starting again from 1 for different list. I have tried some solutions found in this site, but not working. Given below is my code so far. Here $startpoint =10;
<ol start="<?php echo $startpoint;?>">
<li>
<?php echo $objA->stringtag($question); ?>
</li>
</ol>
Try to something like this. I think in your File not getting $startpoint value. So, it's start with 1.
<?php $startpoint = 10; ?>
<ol start="<?php echo $startpoint;?>">
<li><?php echo 'teastesest' ?> </li>
<li><?php echo 'teastesest' ?> </li>
<li><?php echo 'teastesest' ?> </li>
<li><?php echo 'teastesest' ?> </li>
</ol>
I have few menu items in header.php file.
and calling "header.php" file in few pages like About us, Contact Us....
How can i highlight the selected menu item using php?
<ul>
<li><?php echo get_string('home'); ?></li>
<li><?php echo get_string('courses'); ?></li>
<li>About Us</li>
<li>Blog</li>
<li>Gallery</li>
<li>Contact Us</li></ul>
This is my header.php
Get the page URL from the URL as below -
<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
//get components of url
$parts = parse_url($url);
//echo $parts['path'];
?>
and then add the condition to your HTML element as
<li <?php if($parts['path']=="/course/index.php") { echo "class='active'";} ?>><?php echo get_string('courses'); ?></li>
<li <?php if($parts['path']=="/about.php") { echo "class='active'";} ?>>About Us</li>
<li <?php if($parts['path']=="/contact.php") { echo "class='active'";} ?>>Contact Us</li>
Change the page name and URL accordingly
I'm creating a website..When it comes to the navigation menu, I listed it and need the nav bar class to be active when that menu is clicked. It's fine to give class="active" for the list tag. But I need it to be active only when clicked. How can I achieve this .?
My list is :
<div class="menu">
<ul class="nav" id="nav">
<li class="active">
<?php echo anchor("cntrl/index","Home"); ?>
</li>
<li><?php echo $this->session->userdata('user_name'); ?></li>
<li>About</li>
<li>
<?php echo anchor("cntrl/jobs","Jobs"); ?>
</li>
<li>
<?php echo anchor('cntrl/logout','Logout'); ?>
</li>
<div class="clearfix"></div>
</ul>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/responsive-nav.js"></script>
</div>
Well, I handle this sort of issue as follows:
set the active link (which is resided in the url when the link is clicked) into an variable in the controller function which is called by the link
$data['active_link'] = 'home'; # for example
check it in the view file (JS):
$(document).ready(function(){
var active_link = "<?php echo $active_link;?>";
$("li").removeClass('active');
$("#"+active_link).addClass('active');
});
Use the following code.
<li class="<?php echo (endsWith($_SERVER['REQUEST_URI'], 'cntrl/jobs')? 'active':''); ?>">
<?php echo anchor("cntrl/jobs","Jobs"); ?>
</li>
Main part of this code is
endsWith($_SERVER['REQUEST_URI'], 'cntrl/jobs')
Where $_SERVER['REQUEST_URI'] is your current URL. and 'cntrl/jobs' is your menu which is being checked with current URL.
I'm trying to highlight the winner in a basketball game by comparing the scores of two team, and highlighting the winner (highest score) team, by adding a class "winner" to the HTML element like this:
<ul class="game-result">
<li class="winner"><span>Team 1</span><?php echo $team1_points; ?></li>
<li class=""><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>
I'm using wordpress and php, any help would be appreciated!
Thanks
Like so
<ul class="game-result">
<li <?php echo (($team1_points>$team2_points)?'class="winner"':''); ?>><span>Team 1</span><?php echo $team1_points; ?></li>
<li <?php echo (($team2_points>$team1_points)?'class="winner"':''); ?>><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>
<ul class="game-result">
<li <?=($team1_points > $team2_points ? "class='winner'" : "")?> ><span>Team 1</span><?php echo $team1_points; ?></li>
</ul>
<ul class="game-result">
<li <?php echo (($team1_points>$team2_points)?'class="winner"':'class=""'); ?>><span>Team 1</span><?php echo $team1_points; ?></li>
<li <?php echo (($team2_points>$team1_points)?'class="winner"':'class=""'); ?>><span>Team 2</span><?php echo $team2_points; ?></li>
</ul>
Even though Flyer's answer is correct, this one will make your code look exactly as you posted it in the question description.
I'm editing a theme named AquaCart, installed in OpenCart 1.5.5.1. I also integrated Twitter Bootstrap's fixed top navbar. I already modified the navbar and put the Login / Logout menu there, and it's doing fine. This project is for my own online store.
I don't have any PHP skills yet, only HTML+CSS. I have managed to put the login/logout button on my new navbar menu by copying codes from my current theme's header.tpl file and editing the header.php file (from the catalog\english\common\header.php).
Now, I am polishing the menu and wanted to add some custom menu/link named Sign Up!.
I want this Sign Up! menu link to show as Logout link when a user is already logged in.
My current edit shows the logged-in user's name in a <li>, and a logout menu in a second <li>. This is not what I really want. I want to show the Logout link in place of the Sign Up! link when a user is logged in.
Here is my current header.tpl edit:
<ul>
<ul>
<li>
My Account<!--Shall be shown only when user is logged in-->
<ul>
<?php if (!$logged) { ?>
<?php echo $text_welcome; ?>
<?php } else { ?>
<?php echo $text_logged; ?>
<?php } ?>
<li class="divider"></li>
<li>Store Front</li>
<li>Blog Page</li>
</ul>
</li>
<li>Sign Up!</li>
</ul>
</ul>
My header.php from the catalog\language folder of opencart. text_logged and text_welcome was already edited.
<?php
// header.php from catalog\language\english\common\header.php
$_['text_home'] = 'Online Shop';
$_['text_wishlist'] = 'Wish List (%s)';
$_['text_shopping_cart'] = 'Shopping Cart';
$_['text_search'] = 'Search';
$_['text_welcome'] = '<li>Login</li>
<li>Sign Up!</li>';
$_['text_logged'] = '<li>%s</li>
<li>Logout</li>';
$_['text_account'] = 'My Account';
$_['text_checkout'] = 'Checkout';
?>
The above code is rendered like so...
..and I wanted to make the sign Up! link to become Logout when a user is logged in.
I don't know PHP yet, but I'm struggling on studying the PHP files of OpenCart installation, and I've found this string from my header.php file found in catalog\controller\common:
$this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
I am thinking of duplicating that, but don't know what to duplicate and modify. And what are other files involved?
UPDATE:
I've now added a new Text name "Sign Up" and "Login", so I may not be confused, and I can easily substitute it to my Text Link.
So far.. I've added: In my catalog\english\common\header.php:
$_['text_login'] = 'Login';
$_['text_signup'] = 'Sign Up!';
And in my catalog\controller\header.php.
$this->data['text_login'] = $this->language->get('text_login');
$this->data['text_signup'] = $this->language->get('text_signup');
UPDATE 2:
I've re-marked up my Menu, based from shadyxx opinion, I've changed the menu a bit. So for "not Logged-in Users"... This menu should be echoed...
Marked up like this:
<div class="nav-collapse collapse">
<ul>
<li>Login</li>
<li>Register</li>
</ul>
</div>
And for LOGGED-IN USERS, this menu should be echoed...
Marked up like this:
<div>
<ul>
<ul>
<li>
Account></b>
<ul>
<li>%s</a></li>
<li class="divider"></li>
<li>Shopping Cart</a></li>
<li>Checkout</a></li>
</ul>
</li>
<li>Logout</a></li>
</ul>
</ul>
</div>
In my catalog\controller\common\header.php:
$this->data['signup'] = sprintf($this->language->get('text_signup'), $this->url->link('account/register', '', 'SSL'));
$this->data['login_register'] = sprintf($this->language->get('text_login_register'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
$this->data['logged_in'] = sprintf($this->language->get('text_logged_in'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->data['text_shopping_cart'] = $this->language->get('text_shopping_cart'), $this->data['shopping_cart'] = $this->url->link('checkout/cart'), $this->url->link('account/logout', '', 'SSL'));
In my catalog\language\english\common\header.php
$_['text_login_register']
= '<div>
<ul>
<li>Login</a></li>
<li>Register</a></li>
</ul>
</div>';
$_['text_logged_in']
= '<div>
<ul>
<ul>
<li>
Account<b class="caret"></b>
<ul>
<li>%s</li>
<li class="divider"></li>
<li>Shopping Cart</li>
<li>Checkout</li>
</ul>
</li>
<li>Logout</li>
</ul>
</ul>
</div>';
In my header.tpl
<?php if (!$logged) { ?>
<?php echo $login_register; ?>
<?php } else { ?>
<?php echo $logged_in; ?>
<?php } ?>
So, what's not working, using the above codes is the checkout menu. The checkout menu is redirecting a user to the Shopping Cart Page.
I've just copy pasted the above codes. I've tried to understand the use of the existing code and by trial and error.
IMHO, you do not want to have My Account link when there is no user logged in...as it would make no sense to be shown for the visitors (not-logged-in users).
I would show only the Sign Up! link, and after logging in, I would show only the My Account menu that would have the desired Logout link (so as it is right now).
So keep your current template as is, and using this code block (you have given us):
<?php if (!$logged) { ?>
<?php echo $text_welcome; ?>
<?php } else { ?>
<?php echo $text_logged; ?>
<?php } ?>
We can modify your top navbar slightly... The condition <?php if (!$logged) { ?> applies if there is no user logged in, so inside it we will show the Sign Up! link, then the <?php } else { ?> gets applied if there is a user logged in. Thus we will move the My Account menu there. This code is just an example (as you didn't provide us with the navbar source code...):
<ul id="top-navbar>
<?php if (!$logged) { /* only visitor */?>
<li><?php echo $text_signup;?></li>
<?php } else { /* logged in user */?>
<li><span>My Account</span>
<ul class="sub-menu">
<li><span><?php echo $text_logged; ?> <?php echo $logged_username; ?></span></li>
<li><a href="<?php echo $logout; ?>><?php echo $text_logout; ?></a></li>
</ul>
</li>
<?php } ?>
</ul>
In your controller you would have to push the language strings, URLs and username to the template and in language file you would have to add the text strings needed for your menu (if you hadn't done so far...).
EDIT:
Your thinking is good, but the approach not. Do not put HTML into language files, nor controllers, unless really necessary or no other way is possible (which may not occure and if yes, something is wrong).
So, put all the HTML into your template file (header.tpl) and use PHP variables:
<?php if (!$logged) { ?>
<div>
<ul>
<li><?php echo $text_login; ?></li>
<li><?php echo $text_signup; ?></li>
</ul>
</div>
<?php } else { ?>
<div>
<ul>
<li>
<?php echo $text_account; ?><b class="caret"></b>
<ul>
<li><?php echo $username;?></li>
<li class="divider"></li>
<li><?php echo $text_shopping_cart; ?></li>
<li><?php echo $text_checkout; ?></li>
</ul>
</li>
<li><?php echo $text_logout; ?></li>
</ul>
</div>
<?php } ?>
Now many of the URLs and texts are already defined thus we need to add only few of them.
Open your language file (catalog\language\english\common\header.php) and add/modify these:
$_['text_login'] = 'Log In';
$_['text_signup'] = 'Register';
$_['text_logout'] = 'Log Out';
You can remove the previous text_login_register and text_logged_in variables with its values.
Now open the controller (catalog\controller\common\header.php) and find the part that ends with this line:
$this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
And after it, add these lines:
$this->data['text_login'] = $this->language->get('text_login');
$this->data['text_signup'] = $this->language->get('text_signup');
$this->data['text_logout'] = $this->language->get('text_logout');
$this->data['login'] = $this->url->link('account/login', '', 'SSL');
$this->data['signup'] = $this->url->link('account/register', '', 'SSL');
$this->data['logout'] = $this->url->link('account/logout', '', 'SSL');
$this->data['username'] = '';
if($this->customer->isLogged()) {
$this->data['username'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
}
Now you should be done.