I want to distribute my page contents in various files for a wordpress theme. As I can do with header, sidebar and footer.
Something like
<?php get_imageslidercontent(); ?>
or anything else.
You should put this function in the functions.php file that is in your theme root folder and then you can use your function in your theme
Related
I am pretty new to WordPress and I am trying to make a basic custom theme from scratch. The basic navigation menu is displayed and works on all of my pages except for the default blog page (which just appears as a blank white screen when clicked on). I have my theme split up into multiple files (header, footer, page, archives, etc). I think that the page.php file is what is supposed to display the blog, but it only works on the home, about, and test pages.
page.php:
<?php get header();?>
<div>
<h1><?php the_title();?></h1>
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<?php the_content();?>
<?php endwhile; endif;?>
</div>
<?php get_footer();?>
post.php is not for the post type post it is for static pages or custom post-types.
You are looking for single.php or index.php.
This template Hierarchy from the Wordpress docs will help you.
Also see: https://developer.wordpress.org/themes/basics/template-hierarchy/
Style.css
Go to the WordPress default theme folder, open the style.css file. Copy the commented code at the top and paste it to the GlossyBlue style.css file. Change the theme name and the author information as you desire.
Splitting The Files
Now you need to understand where to split the file into several files: header.php, sidebar.php, and footer.php. The image below shows a simplified version of my index file and how the markups should split.
Header.php
Open the index.html file. Cut from the top to where the ends, paste it in a new PHP file, and save the file as header.php.
Sidebar.php
Back to the index.html file, cut from where the start to the closing tag of and paste it in a new PHP file, save it as sidebar.php.
Footer.php
Back to the index.html file, cut from the tag to the end of and paste it in a new PHP file, save it as footer.php.
Index.php
Now in your index.html file, you should only have the wrap. Save the file as index.php. Insert the line:get_header, get_sidebar, and get_footer in the same order as your layout structure.
Single.php
Now, it is time to do the single.php template. If you want, you can go through the same process — cut & paste from the default theme. But, I find it easier to use the index.php that you just created and save it as single.php. Open the default theme single.php file and copy the Template Tags over. Then include the comments_template. The image below highlights what I’ve changed:
Page.php
With the single.php template you just created, save it as page.php. Remove the post date, comment form, next/previous link… and that’s it.. there goes your page.php template.
Detailed document here : http://webdesignerwall.com/tutorials/building-custom-wordpress-theme
You question answer :
Copy page.php and rename it to single.php file.
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 new in Wordpress. I am developing my own theme. I have included index.php, functions.php, header.php, footer.php, page.php, style.css etc.. Now my home page is working perfectly. When I am going to display category menu its showing only header and footer. Not inside the content. When displaying post also its showing Header and footer.
What are the steps included for displaying posts in theme development or is there any function I want to include in function.php ?
You need to use "the loop" to display the content from the page/post.
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article>
<header><h1><?php the_title();?></h1></header>
<?php the_content(); ?>
</article>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
Copy this code into a new file called single.php in your theme folder.
Best way is to copy the existing theme and change the theme name ( make changes in css , images , header , footer design ) and use that , it will work correctly.
If you are working with child theme.
than all pages display under default template. and default template is page.php.
for category there is a category.php or archive.php file in which you have to change code for more functions.
And for display post you have to change single.php
you can create template for additional functionality.
that's it.
You might be missing content.php, category.php,content-single.php and many more files which in result not displaying your content part and only displaying header and footer.
Best way is download fresh word press from :
https://wordpress.org/download/
It will include all supporting files for load website.copy one of theme from fresh themes folder and replace it with your theme and customise in it.
I'm using <a href="<?php the_permalink();?>" Take me to another page </a> to take the user to a permalink page.
However, when I do, it is saying No input file specified.
I have the following files in theme folder:
footer.php
functions.php
header.php
style.css
index.php
How come this is not working — am I missing another php template file?
Your template files have to be in a directory under /wp-content/thmes/your-theme/. After you inserted them into the theme dir you have to activate your theme in the wordpress administration.
You need also at least a index.php File. That's the file where you place the functions for your content. In the index.php your include the header.php and footer.php with the Wordpress functions get_header() and get_footer().
I think you should better read the Documentations:
http://codex.wordpress.org/Using_Themes
http://codex.wordpress.org/Theme_Development
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";