Links are not fully working after adding active class with php - php

I'm using php to add active link state to my navigation menu which is shared dynamically across all my website pages. But when I go to other links from homepage it works fine but when I go back to homepage its give me "object not found" error.
<!--start vertical menu-->
<?php
$index="menu-items";
$top_albums_default="menu-items";
$Topartists="menu-items";
$Toplists="menu-items";
$Charts="menu-items";
$menuLinkid=basename($_SERVER['PHP_SELF'],".php");
if($menuLinkid=="index"){
$index='active';
}else if ($menuLinkid=="top_albums_default"){
$top_albums_default='active';
}else if ($menuLinkid=="Topartists"){
$Topartists='active';
}else if ($menuLinkid=="Toplists"){
$Toplists='active';
}else if ($menuLinkid=="Charts"){
$Charts='active';
}
?>
<div id="vertical-menu">
<!--<h2 class="logo">LOGO</h2>-->
<img class="logo" src="../Graphics/icons/logo.png" alt="LOGO"/>
<h6 class="logo-desc">Arcade Music Repository</h6>
<ul class="menu-items">
<li>
<a class="<?php echo $index; ?>" href="index.php" ><i class="arcd-archive" ></i></br>Browse</a>
</li>
<li>
<a class="<?php echo $top_albums_default; ?>" href="Top-albums/top_albums_default.php"><i class="arcd-music97"></i></br>Top albums</a>
</li>
<li>
<i class="arcd-microphone52"></i></br>Top artists
</li>
<li>
<i class="arcd-numbered8"></i></br>Top lists
</li>
<li>
<i class="arcd-rising9"></i></br>Charts
</li>
</ul>
</div>
<script type="text/javascript" src="../js/jquery-1.11.3.min.js"> </script>
Please check this in video
Here is my site folders structure

You are missing a forward slash on your homepage link.
Make it like this:
<ul class="menu-items">
<li>
<a class="<?php echo $index; ?>" href="/index.php" ><i class="arcd-archive" ></i></br>Browse</a>
</li>

Related

How to make a href class=active on my php code

I have following php code for horizontal menu, where I am calling the respective page from this php file, but I want whenever I call that page, that a href page become active.
<li class="mt">
<li class="sub-menu">
<a class="active" href="main.php">
<i class="fa fa-dashboard"></i>
<span>Dashboard</span>
</a>
<ul class="sub">
<li><a href='?url=profile/profile.php'><span>My Profile</span></a></li>
<li><a href='?url=profile/editprofile.php'><span>Edit my profile</span></a></li>
<li><a href='?url=profile/welcome-letter.php'><span>Welcome Letter</span></a></li>
<li class='last'><a href='?url=profile/change-password.php'><span>Change Password</span></a>
</li>
</ul>
</li>
</li>
<?php if ($epin_module == TRUE) { ?>
<li class="sub-menu">
<a href="javascript:;">
<i class="fa fa-cogs"></i>
<span>My e-PIN</span>
</a>
<ul class="sub">
<li ><a href='?url=epin/used.php'><span>Used e-Pin</span></a></li>
<li><a href='?url=epin/un-used.php'><span>Unused e-Pin</span></a></li>
<li><a href='?url=epin/request.php'><span>Request e-Pin</span></a></li>
<li><a href='?url=epin/transferreport.php'><span>E-PIN Transfer report</span></a></li>
<?php if ($autowithdraw == FALSE) { ?>
<li class='last'><a href='?url=epin/epingenerate.php'><span>E-PIN generate report</span></a>
</li>
<?php } ?>
</ul>
</li>
I want when the MY e-Pin page is visited, that page became active. currently if I visit that page main.php stays active always.
You can test url GET parameter for each links like that :
Where you have to replace both {MyUrl} by the real url value.

wordpress custom theme using php

I need a help in WordPress custom theme using PHP development, I was created language dropdown with images and in configure with Gtranslator Plugin, it`s work properly but when I select other language flag can't change in Dropdown.
my Code is given below:
<li class="dropdown">
<a href="JavaScript:void(0)" class="dropdown-toggle" data-toggle="dropdown"><img class="lang_icon" src="<?php echo get_stylesheet_directory_uri();?>/images/usaicon.png">
<i class="fa fa-angle-down" aria-hidden="true"></i>
</a>
<ul class="dropdown-menu dropdown_language">
<li><a onclick="doGTranslate('en|en')" href="JavaScript:void(0)">
<img class="lang_icon" src="<?php echo get_stylesheet_directory_uri();?>/images/usaicon.png">
</a>
</li>
<li id="cn"><a onclick="doGTranslate('en|zh-CN')" href="JavaScript:void(0)">
<img class="lang_icon" src="<?php echo get_stylesheet_directory_uri();?>/images/chinaicon.png">
</a>
</li>
<li><a onclick="doGTranslate('en|es')" href="JavaScript:void(0)">
<img class="lang_icon" src="<?php echo get_stylesheet_directory_uri();?>/images/mexiconicon.png">
</a>
</li>
</ul>
</li>

Why doesn't open my link?

I have that code for two tabs
<li>
<a href="#gallery_place" role="tab" data-toggle="tab">
<i class="fa fa-picture-o"></i>
<?php _e("Gallery", ET_DOMAIN); ?>
</a>
</li>
<li>
<a href="http://romanianusa.com/post-place?id=<?php the_ID(); ?>">
<i class="fa fa-history"></i>
<?php _e("Repost", ET_DOMAIN); ?>
</a>
</li>
Why of the second <li> does not open, Chrome display my link in bottom but when i click doesn't open the page. What is wrong?
If the function the_ID() returns the ID, you need to use echo to get the ID into the URL:
<a href="http://romanianusa.com/post-place?id=<?php echo the_ID(); ?>">
I resolved with that function:
<script>
function openWindow()
{
window.open('http://romanianusa.com/post-place?id=<?php the_ID(); ?>');
}
</script>
And in my <li>
<i class="fa fa-history" onclick="openWindow()"></i><?php _e("Repost", ET_DOMAIN); ?>
Thanks a lot #Barmar

How do I keep the current tab active?

I use bootstrap theme bs-admin-bcore and I want to make menu in file "menu.php" to be more dynamic.
For example, I have this code :
<ul id="menu" class="collapse">
<li class="panel">
<a href="index.php" >
<i class="icon-table"></i> Dashboard
</a>
</li>
<li class="panel ">
<a href="#" data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav">
<i class="icon-tasks"> </i> UI Elements<span class="pull-right"><i class="icon-angle-left"></i></span> <span class="label label-default">10</span>
</a>
<ul class="collapse" id="component-nav">
<li class=""><i class="icon-angle-right"></i> Buttons </li>
</ul>
</li>
</ul>
when I call index.php <li class="panel"> becomes <li class="panel active"> and when I call button.php EU Elements becomes active.
You have to add "active" class to the parent li of buttons as well n it will work.

html navigational menu in wordpress

I am using html nav bar in wordpress
my html nav bar code
<li class="active">
<a href="http://www.siteurl.com/shop/" class="active">
<i class="icon-nav icon-home"></i>
Home
</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=172">
<i class="icon-nav icon-star"></i>
About </a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=176">
<i class="icon-nav icon-th-large"></i>
Gallery</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=174">
<i class="icon-nav icon-comments"></i>
Services</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=4">
<i class="icon-nav icon-shopping-cart"></i>
Shop</a>
</li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=187">
<i class="icon-nav icon-pencil"></i>
Blog</a></li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=145">
<i class="icon-nav icon-plus-sign"></i>
Events</a></li>
<li>
<a href="http://www.siteurl.com/shop/?page_id=178">
<i class="icon-nav icon-map-marker"></i>
Contact</a>
</li>
</ul>
</nav>
I have tried to create a conditional tags for each page like below
example for home
<?php if ( is_home() ) { ?>
<li class="active">
<a href="http://www.siteurl.com/shop/" class="active">
<i class="icon-nav icon-home"></i>
Home
</a>
</li>
<?php } else { ?>
<li>
<a href="http://www.siteurl.com/shop/" >
<i class="icon-nav icon-home"></i>
Home
</a>
</li>
But this is not working
how to active the menu icons when we view the respective pages
If i use direct html navigational menu
Only way to do this is by using the wordpress navigation system
http://codex.wordpress.org/Function_Reference/wp_nav_menu
A lot of work has gone into their system, so there's no reason why you would want to replicate it.
Appart from reading the Codex (essential), you can search for tutorials, articles and Q&A's, there are plenty of them.
WordPress Wp_Nav_Menu with Icons and Active Item Highlight
We will be doing:
Home link in our wp_nav_menu that always gets current blog url
Customize each menu item as you want
Put pretty icons in our menu
Active item highlight
Function Examination: wp_nav_menu
In this tutorial, we’ll dive deep into everything that the
wp_nav_menu function can do, use the Walker Class to add a sub
description, and touch on some of its related functions.

Categories