I need to create a page which is an exact copy of my index.php page. I have duplicated index.php and renamed it page-newindex.php and included
/*
Template Name: homepage
*/
at the top of the page so I can select it as a template when creating a new page.
The problem occurs when the page is rendered. Becuase it is a 'page', a containing div which looks like this: <div id="page" class="hfeed"> in included which all of the other html is inserted into. This is causing major formatting problems.
How do I get rid of this containing div??
<div id="page" class="hfeed"> this is added in header.php.
If you remove it from header.php then it will affect all the pages. So create a custom header for homepage template.
Copy header.php and paste in a new php file & name it as header-home.php
In the header-home.php, remove page id and hfeed class from div. ie just keep <div>.
In homepage template, instead of get_header() call get_header('home');
With this you have a separate header from which you can remove page id from div.
Hope this helps.
Related
In my Wordpress Theme, I have a "default" footer I use for every page, but I created a new footer I want to display only on the home page.
How do I hide the old footer and display my new footer on the home page?
There are a number of ways you could solve this, and none are more or less correct than the others. The way I would suggest is this;
Assuming you don't have it already, create front-page.php template and copy the content of page.php into it (if that's the template you're using).
Replace get_footer() at the end of front-page.php with get_footer('home') (assuming your new footer is called 'home-footer.php' (see the docs for more on that one)
As an alternatively, you could simply edit page.php and replace get_footer() with something like:
if(is_front_page()) { //check if current page is the home page
get_footer('home');
} else {
get_footer();
}
Which utilises the is_front_page conditional. (see conditional tags)
Open the header.php
Edit the <body> tag and make it <body <?php body_class(); ?>>
now in your homepage your body tag will render <body class="home">
then write css like:
body.home footer {
display: none;
}
add new footer in your homepage content
You can create custom template for homepage and call the new footer from that template using the function get_footer( $name ), here $name is the name of the new footer that you have created. Then select the homepage template from dashboard home page.
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.
Backstory: I've been dealing with this website for the past 5 months. I didn't have previous experience with Wordpress, but I had some with HTML, CSS and PHP.
I have two different ways to display posts on my custom Wordpress template.
On the "Services" page, a post is loaded onto a dynamic content div by clicking on different buttons. Each button loads a different post on the same div by calling specific post ID's:
<a
href="#contentBox1"
class="dem_buttons"
onclick="loadPage1('<?php the_permalink(361) ?>')"
target="#contentBox1">
</a>
<div class="text-center clearfix" id="contentBox1"></div>
On the "Search" page there is no dynamic content div. Each search result consists on an image, the title and the excerpt of the post. The posts are acessed by clicking on their respective titles after the search results come up.
Here's the problem: If I don't include the header and the footer on single.php, the post will be loaded without styles, navigation bar and footer after clicking the title of the search result. I need to load the header and the footer on single.php because of this search page, but this means there will be a second header and footer on the dynamic content div of the "Services" page, as well.
I've tried starting single.php with:
<?php
if ( is_page([page id]) ) { ?>
[single.php's content]
<?php
} else {
get_header(); ?>
[single.php's content]
<?php get_footer();
} ?>
to no success. I've also tried out !is_page, but no luck on that either.
Please don't recommend plugins. I really need to code everything by hand. The written reason for that would be longer than this post.
The final solution was to rearrange the parts of single.php so that it used include (or require) for showing the given post's content (named here: postcontent.php).
// Pseudo code
get_header()
// postcontent.php is the body of the post
include_once( postcontent.php )
get_footer()
This way the single.php had its header and footer, but the "Services" template could include the post's content directly:
// Pseudo code
// Template: Services
get_header()
// the content of the "Services" template
services_content()
// postcontent.php is the body of the post referenced
include_once( postcontent.php )
get_footer()
This way headers and footers are there on both pages, and there are only one header and footer on each of them.
I'm not 100% sure on the Wordpress side of all this, but could you perhaps wrap the second/first header in a div with a specific id, then give that id a style of display none? Like below:
HTML
<header class='header'> ..... </header>
<div id='hidden-header'>
<header class='header'> ..... </header>
</div>
CSS
#hidden-header {
display: none;
}
Let me know if that helps or not and maybe I can see if I can find something else.
I have an HTML template which I am trying to convert into PHP for WordPress.
The homepage has been converted and is shown properly. Next, the menu in navbar is about, the page that needs to be converted in PHP.
I have just added get_header() at the top and get_footer() below. In between these two I have added the HTML content for my entire page.
Then I tried to provide the link for the menu that I created, but the content of about page is not visible.
Do I need to add any other line for that page apart from get_header and get_footer? Or is something wrong with the link?
Clearly I can't understand what your are trying to say. I think you want to create a page that will show your about menu content.
So in your theme directory create a page name page.php and use get_header(); in first and below get_footer and where you want to show page content write the_content();. like this
<?php
get_header(); ?>
<div><?php the_content(); ?></div>
<?php get_footer(); ?>
after that follow the url of # Sajid Anwar. because for dynamic data you have to create pages(home,about etc) from wordpress dashboard and in menu section add these pages as navigation menu to menu.
I wanted to ask a quick question. I have two websites running on the same domain. The homepage is in complete HTML and it can be accessed by going to http://xyz.com/home while as for the inner pages, I have installed wordpress on the same domain and the pages can be accessed by going to http://xyz.com/sample-page. Now I have created a footer in wordpress and it's appearing correctly on the inner pages which is running wordpress but i want to show that very same footer on my HTML page too which isn't running wordpress. To do this, I added the following code to the index.php file of my homepage:
<footer>
<?php include '../wp-content/themes/metro/footer.php'; ?>
</footer>
Doing so is now showing me this error on the homepage:
Fatal error: Call to undefined function get_option() in /homepages/12/d378078258/htdocs/txtimpact-main/wp-content/themes/metro/footer.php on line 1
Can anybody please let me know that how can I modify the footer.php file so that the footer starts to appear on my homepage. I read a tutorial on the internet where the guy told to add this piece of code to the footer.php file but it didn't help in my case:
require( '../my_wordpress_install_root/wp-load.php' );
This is the code why my footer.php file contains:
<?php $options = get_option('metro'); ?>
</div><!--#page-->
</div><!--.container-->
</div>
<footer>
<div class="container">
<div class="footer-widgets">
<?php widgetized_footer(); ?>
<img style="position:absolute; visibility:show; left: -6px; top: 84px; } " src="http://cms.360ivr.com/wp-content/themes/metro/images/callout-bubble.png" width="22px" />
</div><!--.footer-widgets-->
</div><!--.container-->
<h12><?php mts_copyrights_credit(); ?></h12>
<div style="float: left; margin-top: 20px; margin-left: 153px;"><font size="2px">Copyright © 2006-12 TXTImpact - All Rights Reserved.<br/>Message and Data Rates may apply.<br/>To unsubscribe, text 'STOP' to 27126 or Contact Support.<br/>Powered by Wire2Air<br/>Proudly Made In NYC</font></div>
<div style="margin-right: 83px; margin-top: 91px;"><img src="http://cms.360ivr.com/wp-content/uploads/2013/03/mma1.png" width="450px" align="right" /></div>
</footer><!--footer-->
<?php mts_footer(); ?>
<?php wp_footer(); ?>
</body>
</html>
Your homepage http://xyz.com/home can't use WordPress functions (if you want them you have to include them manually). I advise you to use WordPress in showing homepage. WordPress have setting to show specific page as homepage.
Quote from the WordPress codex:
What Template is Used to Display a Particular Page?
WordPress looks for several Page template files in your active WordPress Theme based upon the Template Hierarchy. The first one it finds will be used to display any given Page. WordPress will look for files in the following order:
The Page's selected "Page Template"
page.php
index.php
The WordPress Template Hierarchy also recognizes specific Pages or Posts automatically without the need to assign them to a specific Page template file. If the Page with ID or slug in the template file name is created by the user, the appropriate Page template file is automatically used.
page-{id}.php
page-{slug}.php
If the Page ID number is 42, the page-42.php template file is automatically used. If the Page slug is "About", the page-about.php template file is used.
Supposing that the following file, http://example.com/connect-wp.php is located at the same level as WordPress root files (http://example.com/):
<?php
define( 'WP_USE_THEMES', false );
require( './wp-load.php' );
// Optional, maybe necessary for logged in users
// add_filter( 'show_admin_bar', '__return_false' );
include get_stylesheet_directory() . '/footer.php';
Of course, what comes before footer.php in your custom file must match the HTML structure that the footer will create.
References:
get_stylesheet_directory
What is the constant WP_USE_THEMES for?
Integrating WordPress with Your Website