How to call .hmtl file inside the header.php in wordpress? - php

I have finish all my html pages and now I want to add them inside the header.php.
Please see the code below:
<li class="menu-item"> AboutUs </li>
As you can see Iam using the_permalink function to call the html file , but when I click in the navbar the aboutus nothing happen , I dont get the aboutus.html.
Can you please tell me how to ge to my point?

You do not output anything from PHP. Change <?php to <?=:
<li class="menu-item"> AboutUs </li>

<li class="menu-item"> AboutUs </li>
$location_of_file will contain address to aboutus.html file without slash at the end.

Related

Set active link on page using includes

I have written some code that will highlight a link in the header based on: class="active". The class is connected to some CSS code to style it.
I am currently adding the class="active" the specified link for each page. However, since I want to move my header into it's own file and include it on each page, I will lose the ability to set the class for each page. I could of course add a variable that will allow me to sort of do the same thing.
What I wish to know is if there is a better and secure way to automatically set the class="active" to the page that I am on. I have seen some posts that suggest using: ($_SERVER['PHP_SELF'] but I have read that it could cause some security issues.
Lastly the main problem that I have is that I need to set two links to
class="active" if I am viewing a page that is in the portfolio list item. For instance, if games.html is currently viewed, both the games and the portfolio page should have the code: class="active".
(All of my .html files are read as .php)
Here is the html code I have so far:
<ul>
<li>Home</li>
<li><a class="active" href="portfolio.html">Portfolio</a>
<ul>
<li><a class="active" href="games.html">Games</a></li>
<li>2D Art</li>
<li>3D Models</li>
<li>Particles</li>
<li>Shaders</li>
<li>Environments</li>
<li>Programming</li>
<li>Substance Designer</li>
<li>Music</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>Store</li>
</ul>
Any help will be appreciated!
PHP_SELF is safe when you only use it to compare values and don't directly use it in your html:
The portfolio menu can be made active by nested all related pages in a folder called portfolio and checking if the path starts with that folder.
<?php
$currentPage = $_SERVER['PHP_SELF'];
$portfolioFolder = 'portfolio/';
$isPortfolioFolder = substr($currentPage, 0, strlen($portfolioFolder)) == $portfolioFolder);
?>
<ul>
<li>Home</li>
<li><a class="<?= $isPortfolioPage ? 'active' : '' ?>" href="portfolio.html">Portfolio</a>
<ul>
<li>Games</li>
<li>2D Art</li>
<li>3D Models</li>
<li>Particles</li>
<li>Shaders</li>
<li>Environments</li>
<li>Programming</li>
<li>Substance Designer</li>
<li>Music</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>Store</li>
</ul>

i am trying to get to the root url in php

I have this link in my db.php. I want everytime the dropdown menu is clicked it redirect to the corresponding page.
$ROOT_URL = '192.167.1.67/office/';
I want to go to this root url on the navigation every time i click on the link.
Home
<ul class="dropdown-menu">
<li>Add Product</li>
<li>View Product</li>
<li>Removed Product</li>
</ul>
instead the page is redirecting as
192.168.1.67/admin/192.168.1.67/admin/product/addproduct.php
How can i solve this problem??
use protocol before your url like..
$ROOT_URL = 'http://192.167.1.67/office/';
OR if having https $ROOT_URL = 'https://192.167.1.67/office/';
If the link points to a local location, you can just use / as root.
This, for examples will work:
Home
If $ROOT_URL is dynamic and you want to include the variable, define it as:
$ROOT_URL = '/office/';
Then you can do:
Home
Also, the links in the list
<ul class="dropdown-menu">
<li>Add Product</li>
<li>View Product</li>
<li>Removed Product</li>
</ul>
point to a relative URL, so when your current URL is /office, the links will point to: /office/addproduct.php. But if this navigation is also included on a page where the URL is /some/other/url, this link will point to: /some/other/url/addproduct.php.
Unless you are really sure the HTML with the link will only show at a certain path, try to avoid relative URLs.

codeigniter's controller to main controller in a specific div

<li>SERVICES</li>
<li>ABOUT</li>
<li>CONTACT</li>
I'm using CodeIgniter and this code was in a different controller. suppose http://localhost/defctrl/function1
I want to return to my homepage "maine/home" in a specific div when you click on the list but the above code doesn't work. neither ../maine/home#services.
How can I solve this problem?
if it's on the same page you can use
<li><a href="#services"
if another page
<li><a href="<?php echo base_url() ?>{route or controller name}#services"
Make sure URL helper is loaded and site load with index.php

How do I assign a CSS class based on if it's the current page?

I've created a modular web page in which each component is within it's own html/php file. Example, index.html calls up header.html, content.php, etc. The reason, so I can keep each section clean, and separate.
My header.php includes a navigational bar (which also uses CSS3 to provide drop down menu (ex, DEF):
<div id="nav">
<ul><li class="navlist"ABC</li>
<li class="navlist">DEF
<ul>
<li><li>GHI</li>
<li>JKL</li>
</ul></li>
<li class="navlist">MNO</li>
</ul>
My dilemma is that I want the 'li class' to equal 'nav_active_menu' if it is the current page being viewed.
I'm assuming that PHP can take care of this, but unsure as to how. Can anyone provide any examples, or links on how to do this?
Hopefully this makes sense.. words....
You can do that by making $activePage variable before you include the header.php page
in you abc.php file:
$activePage = "abc";
include('header.php');
and in your header.php file:
<li class="<?php if ($activePage == "abc") echo 'nav_active_menu'; ?>">ABC</li>
The same way for other pages but with a different value with $activePage variable.
This is another solution, using javascript with jquery.
Add a specific CSS class to each parent li:
<div id="nav">
<ul>
<li class="navlist abc">ABC</li>
<li class="navlist def">DEF
<ul>
<li>GHI</li>
<li>JKL</li>
</ul>
</li>
<li class="navlist mno">MNO</li>
</ul>
</div>
Then add jquery javascript to your <head> in the HTML.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
Add this to your CSS:
.nav_active_menu {your css for active_item goes here}
And in each HTML page add the relevant jquery selector to activate:
<script>
$(".def a").first().addClass('nav_active_menu');
</script>
See fiddle: http://jsfiddle.net/tmfncbb7/2/ (fiddle updated with the correct class)

codeigniter linking to another page

i am new to codeigniter framework. i am having problem with href link. in my home page i have some menu, that goes to different page. for example in normal php if i want to go Sell Books page then i just put sellBook.php in href link. now in codeigniter how can i do this. do i need write something in controller ?
<li >Home </li>
<li>Buy Books </li>
<li>Sell Books </li>
<li>Books on Demand </li>
<li>Request a Book </li>
<li>About Us </li>
as per MVC pattern each of your url is a controller so:
if you, for example, want to link to
http://www.site.com/users
so the controller will look like:
class Users extends CI_Controller{
function index(){
//do somenthing here
}
function list(){
//list your users
}
}
then in your views linking to that controller is simple:
this will link to your users controller and index() method
this will link to your users controller and list() method
the site_url(); method will helps you finding the right link both if
you are using index.php or not in your urls
<a href="<?php echo base_url() ?>controller_name/function_name">
If you are using mod_rewrite to remove the index.php from the URL, you can write your URL as href="/sellbook" otherwise you will have to include it, such as href="/index.php/sellbook".
This assumes, of course, that you have a properly configured route name sellbook. See http://ellislab.com/codeigniter/user-guide/general/routing.html for details on how to achieve this.
If the links are to other pages on your site, then I think your best bet will be to use the url helper, assuming you're using the standard seo friendly format and not query strings. This way, you don't have to take into consideration whether you'll be using .htaccess or not. For example:
echo anchor('your_controller_name/your_function_name/param_1/param_2', 'Sell Books', 'title="Sell Books"');
// or for your home page
echo anchor('/', 'Home', "title='Home'");
If it's an external link, you can use the same function or just a plain html tag:
echo anchor('http://google.com', 'Google Me', 'title="Google Me"');
// OR
<a href="http://google.com" title="Google Me" >Google Me</a>
Note: make sure you load your url_helper in your controller if you'll be using the anchor function:
$this->load->helper('url')
// or add to autoload.php
You can also do it the way #sbaaaang suggested.
Account Details
You can use like this
<li>Home</li>
<li>Buy Books </li>
<li>Sell Books </li>
<li>Books on Demand </li>
<li>Request a Book </li>
<li>About Us </li>
//use
site_url in link with controller name and method
and
$this->load->view('page_name');

Categories