i have to header like.
header-first.php
header-second.php
i create two template like first and second. when the first template is load then i want to load header-first.php and this is working. then second like first.
i have problem with when i load second template then the header-second.php is load is working but not when i go to any page then i want to load header-second.php but not it load header.php.
when i load a second template then the header-second.php is loaded working. now i going any page and view post then the header.php file is load i want to load header-second.php file. please help how can i set globally.
i try to set globally in function.php like.
global $header;
if(is_page_template('page-second.php')){
header = 'second';
}else if(is_page_template('page-first.php')){
header = 'first';
}
it working it return only template page is load.
when i try to load any other like about page it return '' value. it not return any value.
i want to second whenever the first template is not visit.
thank you.
Each template file such as page.php, single.php, archive.php, etc, will have get_header() at the top of it.
This function loads the header (header.php).
If you pass in a string as the first argument it will try to load header-{argument}.php and if not found it will load header.php.
Anywhere you want to load header-second.php you need to change get_header(); to get_header( 'second' );
There is an action that fires when this function runs but there's no filter so you can't override it globally like you're attempting to do. Instead you need to update the template files individually with the function I showed you above.
To summarise change:
<?php get_header(); ?>
To:
<?php get_header( 'second' ); ?>
Further reading: http://codex.wordpress.org/Function_Reference/get_header
Related
I have a custom page template built in a child theme and I need to call out a custom header.
I have template-home.php page template calling out
<?php get_header('home'); ?>
for the header.
I have a saved wp-header-home.php with a little custom button that I need to get.
The page template is unsuccessful at calling out the custom header-home, rather it's calling out the default wp-header.php. I can see when I add my changes into that file, they're reflected.
So, what's going on? Why does my
<?php get_header('home'); ?>
not work to get the wp-header-home.php? What am I doing wrong?
This is the site in question: http://va.northwaydesigns.com
Create the file with header-home.php
Is there a way I can make the header and footer appear on all pages without placing get_header(); or get_footer(); in each of the separate page files? Is there something I can do in the loop or somewhere else that automatically does this?
You want to show get_header() and get_footer() to all the pages. For that you just mention get_header() and get_footer() in each custom template you have created. By default you can place it inside page.php file.
Also if you want to use custom header and custom footer , then you need to create header-custom.php and footer-custom.php file and call them inside any template like the following.
get_header('custom');
get_footer('custom');
It works with just placing them in the page.php file of your theme.
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 wish to display a variable that is stored in a session at the top of each page throughout my website. At the minute, on every single page, in the controller index() I have;
$data['credits'] = $this->session->userdata('credits');
I havve created a seperate view for the navigation bar (where the variable will be displayed). I have called it vNav.php. In vNav.php I then do echo $credits.
For every new view, I have to include the vNav.php, but that also means in the other view's controllers, I have to set the $data['credits'] variable in the index() function.
Is there a way in CI to do this automatically for me? So I don't have to have the same line of code in all my controllers?
Thanks
Okay here's a better design for your views.
First, create a folder called include/, in this folder create a header.php, footer.php, template.php.
header.php
<html>
<head>JS - CSS - META</head>
<body>
<div>COMMON MESSAGE</div>
footer.php
<footer>FOOTER GOES HERE</footer>
</body>
</html>
template.php
$this->load->view('include/header.php');
$this->load->view($main_page);
$this->load->view('include/footer.php');
any controller:
$data['main_page'] = "hello_world"; // view/hello_world.php
$this->load->view('include/template',$data);
So in that way, you can create a common section that will be displayed on all pages by adding it to the header or the footer. If you want, you can also create another file in the include folder and then include it in the template so that it will be loaded automatically every where by only modified one file
I tried adding a frontpage.php file to the content directory, but that wasn't being loaded. Now I've added the following snippet to assure I'm getting a context of 'frontpage':
add_filter('cfct_context', 'scompt_front_page_context');
function scompt_front_page_context($context) {
if( is_front_page() )
return 'frontpage';
return $context;
}
That is allowing me to create a frontpage.php file in the loop directory, but I'm still unable to get it to use my file for the content.
Not exaclty sure what you're trying to do, but in order to use a page template in Wordpress, you must have this at the top of the file:
<?php
/*
Template Name: mypage
*/
?>
and that goes before
<?php get_header(); ?>
And in order for Wordpress to use the template, you have to select it in the page editing area in admin.
So, for a "frontpage," use a template named home.php - with the template name as above - and select it as the template to use in the page editor.
you need two pages to get this to work.
page_example.php (make newfile in same directory as page.php)
pages/page_example.php (copy and rename page_default.php)
page_example.php
must have this header only
<?php
/*
Template Name: Page example
*/
if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
if (CFCT_DEBUG) { cfct_banner(__FILE__); }
cfct_page('page_example');
?>
and
pages/page_example.php is the page it calls so really all your changes need to be in here.
ie remove the side bar, get_sidebar();
now select this page as usual when you are creating a page.
The index.php file is used on the front page of your wordpress blog. Edit (or create) the index.php file to make changes for the front page of your blog.
The correct name of the file needed to replace the front page template is front-page.php not frontpage.php
This is actually a problem in the utility.php file (in the carrington core). There is a function that tells it how to get/determine the content for any given situation. The code looks like this (around line 500):
function swpt_choose_content_template($type = 'content') {
$files = swpt_files(swpt_PATH.$type);
$filename = swpt_choose_single_template($files);
if (!$filename && swpt_context() == 'page' && file_exists(swpt_PATH.$type.'/page.php')) {
$filename = 'page.php';
}
if (!$filename) {
$filename = swpt_default_file($type);
}
return apply_filters('swpt_choose_content_template', $filename, $type);
}
You need to add another case in there to have it check for the front page content template path...this would be the code (in this example, the front page is "front-page.php"):
//checks to see if this is the front page content - this fixes the error of the framework choosing the default content rather than the front page content
if (!$filename && swpt_context() == 'front-page' && file_exists(swpt_PATH.$type.'/front-page.php')) {
$filename = 'front-page.php';
}
I added that right above the default case, and it instantly solved the problem of Carrington calling the default content rather than the front page content template.