I downloaded menu from:
http://www.stunicholls.com/menu/pro_dropline_2.html
And used in my application.
But when I am clicking on a menu it is not highlighting as active menu.
That means i want give an active class to a menu which i clicked .
How can i do this by using this menu code.
My application is in php.
You could accomplish this using the dirname function or FILE global variable to get the file name/path. Thereby, being able to find which tab should be highlighted.
Imagine this directory tree
html_root/
video/
file.php
music/
anotherfile.php
...
Say that each tab is organized into its own directory.
Inside your header file
<?php
if (dirname(__FILE__) == "video") {
// Set css to video tab
} // etc.
?>
Related
I am creating a custom CMS for learning. I have the plan to have the following pages,
Login page
All Posts page
Edit Post page
index page
header.php (the website's header)
footer.php (the website's footer)
sidebar.php (the website's sidebar)
I am confused how would the index page link header, footer and sidebar. Please guide me how can I link these php files in index.php.
You can simply add an Array of files you want to include:
$array = ('header.php', 'footer.php', 'sidebar.php');
Then add some HTML Code structure...
and then you can access the Array and load files.
include_once($array[0]);
.. to include the header.php
include_once($array[1]);
.. to include the footer.php
....
you can use the require_once function to make your site not loading other content if the file does not exists.
if you want to add these files automaticly just add a loop.
foreach($array as $file){
if(file_exists($file)){
require_once($file);
}
else{
die($file.' does not exist!');
}
}
You can use either require_once or include.
I personally use require once option cause it only needs to be include once and not again on later stage.
Inside your body tags:
require_once('/path/to/header.php');
require_once('/path/to/breadcrumb.php');
require_once('/path/to/content.php');
require_once('/path/to/footer.php');
require_once('/path/to/copyright.php');
I have created html pages and trying to convert into wordpress theme,how to link html one page to other page in wordpress menu bar
sample code :
Features
this code is not working,it 's showing page not found.how to make this link in wordpress using php code.
Firstly Create Page "Features" from wp-admin.
Create template for this page.
http://codex.wordpress.org/Stepping_into_Templates
To set this page in menu Go in "Menu" section in WordPress.
http://codex.wordpress.org/Appearance_Menus_Screen
To view this menu in fronted use wp_nav_menu()
Take example template from your theme.
This is file in theme ending with -page.
Change template name in head of a file.
Then remember about the_loop all should be inside a loop to work correctly with many pages.
Put html there, also in header.php attach css to this html.
Page structure is like, header in the up, then page and then footer.
Remember to preserve good html structure - divs beginning and ending.
Then you create a page with content ( which is presented in the_loop ) , which has its own url address.
You can set url naming of pages in settings -> permalinks, you may need to write to .htaccess file.
Then you have direct url to page. You can use it in code like this:
echo bloginfo('url'). 'nameofpage';
All to do is create a template and assign it to page ( on page edit page template option ).
You can use pages or posts for this, i prefer pages.
Create new pages or posts and get their ID.
For linking its:
Get link with this:
get_permalink( $yourPostOrPageID ); // only get; not echo
Otherwise
Wordpress homepage link:
get_bloginfo('home');
Category or custom taxonomy term link:
get_term_link( $term, $taxonomy );
I have a menu but I'm including it on every page because I don't have to copy and paste the whole code on every page. So I'm including it by this way
require "menu.php";
This is what menu.php contains
Home
.....
News
And I want when I'm on Index page the background of the link in the menubar to be gray for example and not just for the index.php but for every other page. I know how to do it when I'm not including it, just add class and I stylize the class. But now I can't think how it could happen.
I would be appreciated if someone help me.
Thank you in advance
The way I would do it would be to add a class to your main <body> (or other parent container) tag that indicates the current page:
<body class='page-home'>
Then add classes to every single menu item:
Home
.....
News
Now you can write CSS styles that target your menu links differently depending on the current page:
.page-home .nav-home {
/** styles for the home link when you are on the homepage **/
}
Now you're handling all your styling in pure CSS, and it doesn't matter that your menu is an include. It's just up to you now to decide how much styling you want to do based on the current page and the specific menu links.
You can use this tricks:
get your file by file_get_contents() and replace your class name according to your file name.
In your menu.php file:
return
'<a class=[+index] href="index.php">Home</a>
.....
<a class=[+news] href="news.php">News</a>';
In your index.php
$strMenu = file_get_contents("menu.php");
$strMenu = str_replace('[+index]','is-active',$strMenu);
echo $strMenu;
In your news.php
$strMenu = file_get_contents("menu.php");
$strMenu = str_replace('[+news]','is-active',$strMenu);
echo $strMenu;
I am a newbie in Yii Framework and creating a CRM which is module based.
Using different tutorials I am able to create my own theme, but now I am stucked at one point.
In my theme, the upper <nav> and left <nav> remains the same throughout the app, until user is logged in. That's why I made it a part of my main.php, but in the login page there are no buttons to show, just simple login form with 2 textfields.
How can I implement this form in my application using custom themes?
I have tried to define a layout in that particular action but not succeeded. Any help would be appreciated.
Using a custom layout for your view is the right way to go.
You can either set the layout in the controller action or in the view.
$this->layout = "//layouts/mylayout";
Note that the default layouts column1.php and column2.php also use the main.php layout file.
Try this step by step :
Create New theme
You can create a new theme and add this to the directory
Application_Root/themes.
Look at the themes/classic directory to get an an idea of the structure of the directory.
The important file (at this stage) is :-
Application_Root/themes/views/layouts/main.php
Customise your theme contents
Copy the css, image, js files etc to the correct directory and change the main.php file to your liking. For example, if your main.php says
<link href="css/mystyle.css" rel="stylesheet">
Then you will have a file
Application_Root/css/mystyle.css
Create the content placeholder.
Somewhere in your main.php, there will be a placeholder for dynamic text, which is specified by.
<?php echo $content; ?>
Tell yii to use the theme.
Change the file Application_Root/protected/config/main.php by adding the following line just before the last line (containing the closing bracket).
'theme'=>'surveyhub'
Create the layout placeholders.
Create an HTML segment that will be written into the $contents portion of main.php. Call it for example one_column.php. The file path will therefore be Application_Root/themes/views/layouts/one_column.php In that file, where you want the dynamic text to be placed, create a placeholder.
<?php echo $content; ?>
Tell Yii to use the layout.
In the file Application_Root/protected/components/Controller.php, add or modify the layout variable to read :
public $layout='//layouts/one_column.php';
Refresh the page
I need to include a custom PHP page in Wordpress.
So what I need to do is just to show this custom php page using the Wordpress theme installed on that Wordpress.
Does not mind which theme is up, the custom php page will have to be shown under any theme is installed in that moment.
How do I do it in Wordpress?
I am new to Wordpress development.
Thanks
Creating a custom php page that will be able to be viewed in any theme (and have the theme applied) would be considerably difficult.
Each wordpress page calls specific theme functions of that particular theme, as well as referencing files of that theme to generate header, footer, css files, javascript files, etc.. Your custom page would need to plan for all of these contingencies, for each possible theme used.
Here's a alternative solution: inject PHP code directly into a standard wordpress page via this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/
Meaning: you make a normal wordpress page, but are able to add php to it. When this page is rendered, the proper page template is used, and all the theme references are taken care of for you.
You could do this easily with a page template. WordPress allows you to create page templates which can be assigned to a page via the 'Page Attributes' panel within the page editor. These templates are php files inside your theme directory which begin with some code like (see this page in The Codex for more info):
<?php
/*
Template name: Custom PHP Page
*/
?>
<?php // begin custom PHP page ?>
Typically a template is a variation on the regular theme files (such as page.php) and would call the get_header() and get_footer() functions and have an instance of the loop. However if you simply want to use a custom PHP page, then all you need to do is create the file you want inside the current theme directory and add the above code at the very top of the file.
To output the custom PHP page on your site, you would need to add a new page via the admin area and then assign your new page template to this page.
Alternatively, if you want to include a custom PHP page inside an existing theme file, you use the code:
<?php include(TEMPLATEPATH . '/includes/file.php'); ?>
in this case your custom PHP file would be located inside a directory called 'includes' within your current theme directory.
Tim.
It's not that difficult. Here's what you need:
Once you include the main wordpress blog header, the entire armamentarium of wordpress functions is available to you, which allows you to get the active theme's directory. Once you get that, just include the header and the footer of the theme.
// If title is not displayed before loading the header, Wordpress displays "Page not found" as the title
echo "<head>
<title>Your page title</title>
</head>";
// Include the Main Wordpress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
//Now, you need to get the active theme's folder, and get a relative path to that folder
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path;
//Once you have the path, include the header and footer, adding your custom php code in between.
// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";
// Your custom PHP code STARTS here
// Add anything you want to display to the user
echo "
<h2>
Your form has been submitted
</h2>";
// END of custom code
?>
<?php
}
// Now end with the theme's footer
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";
?>
Was very helpfull (even if dated of 2011-13)
Also, as a thank you, i'm sharing the version i made
it's usefull if your wordpress folder is not located at ROOT
PasBin Link - wordpress custom php page
just change the value of $wplocalpath in :
// Wordpress path (if wordpress is not located at ROOT
// $wplocalpath="/Wordpress1";