Following this tutorial:
http://blog.teamtreehouse.com/responsive-wordpress-bootstrap-theme-tutorial
The tutorial instructs me to create an index.php with the contents:
<?php get_header(); ?>
<!-- loop-->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
This creates a template with my header on top and footer at the bottom. Then, the tutorial instructs me to create a front-page.php with the contents:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Basically, the same thing as index.php minus a few lines of code, most importantly the <?php get_header(); ?> and <?php get_footer(); ?> commands. The problem is that, when I create this page, my front page no longer has either its header or its footer, or the formatting that lives within the header and footer.
Yet, on the tutorial, the header, footer, and formatting still apply on the front page. What am I doing wrong?
You are doing nothing wrong. The developer probably forgot to mention adding it, that's all.
When you use front-page.php, WordPress doesn't use index.php when rendering the front page and there is no way to include the header and the footer unless you add get_header() and get_footer() to front-page.php.
Add the header and the footer and you should see your front page as the screenshot in the tutorial, and notify the developer to fix this in his tutorial
hi Matt create a page home template and call header and footer in it then you an call posts its worked.
You can create your custom header and footer as well.
Create your custom header like "header-custom.php"
to include this header you need <?php get_header('custom'); ?> after - is the name of your custom header, when you call the header you need to insert name inside the function like i did above.
for footer also same login & sider bar also same logic.
footer-custom.php, sidebar-custom.php
<?php
get_footer('custom');
?>
<?php
get_sidebar('custom');
?>
Thanks.
Related
I am new to PHP and WordPress and I want to develop my theme from scratch.
From the reading settings on WordPress Dashboard I have set for the Front page displays option to 'Your latest posts', but the homepage is blank with no header or footer, although every other page works just fine.
Here is my code for index.php:
<?php get_header(); ?>
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<h3><?php the_title(); ?></h3>
<small>Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
<p><?php the_content(); ?></p>
<hr>
<?php endwhile;
endif;
?>
<?php get_footer(); ?>
Can anyone explain why this is happening?
Thank you.
You may be loading another template which is a blank fil. WordPress has a hierarchy of templates set out in https://developer.wordpress.org/themes/basics/template-hierarchy/#front-page-display.
For your situation the hierarchy is front-page.php, home.php, index.php, so check those first two.
Can you test to register again the permalinks ? You go i nthe dashboard on settings menu > permalinks and you click save.
Sometimes Wordpress need to register again permalinks te reset htaccess when you developp some action ( like create custom post type or others )
I'm new to wordpress and i'm trying to create a custom template. I'm using the default twentyfifteen theme. I went to wp-content/themes/twentyfifteen and copied page.php to a new file called page_with-contact.php and added this comment on the top :
/*
Template Name: Page with contact
*/
I made no other changes to the template.
I then went to the admin site and changed one of the pages to "page with contact".
When I open the page I see that the affix on the left menu is not working and the responsive menu is not working either.
I followed a pretty simple tutorial here so I'm just wondering what am I doing wrong.
EDIT
Following #masiorama's answer and the comments below is crated a child theme, moved the template file to the child theme and renamed it to page-with-contact.php, This is the content of the template
<?php
/*
Template Name: Page with contact
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main my-content-page" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
?>
<div class="hentry entry-content contact-form">
<?php
echo do_shortcode('[contact-form-7 id="19" title="contact form 1"]');
?>
</div>
<?php
// End the loop.
endwhile;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php
get_sidebar();
get_footer();
?>
Now I have several problems :
As you can see the sidebar, heading and footer are all included but the affix and responsive menu are still not working.
The contact form (which previously worked fine) is now not showing at all.
I'm unable to enqueue the parent's rtl.css file.
Appreciate any further guidance.
As far as I know your page file should be named:
page-with-contact.php
and not:
page_with-contact.php
Be sure that it contains at least some wordpress function calls like:
<?php get_header(); ?>
<!-- stuff -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Check this for more details: http://codex.wordpress.org/Page_Templates
Looks like you are calling a template within a template. 'get_template_part( 'content', 'page' );' should be the_content();. Good chance that's whats messing you around.
Need this WordPress hooke to call in your template
get_header();
get_sidebar();
get_footer();
I am new to wordpress and wordpress loop. I am trying to understand the loop but without any success. Baer with me I will try to explain what I am not understanding ...
I using a template called 'graphy'. When I create a 'Page' there is an option to create a page with no side bar the template is called 'nosidebar.php' and this is its code:
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
1- Why this template contains a loop ? where it only displays a single page content without side bar ! Obviously it is not looping through posts and displaying them !
I tried to create my own template page which will be used only for front-page and here is what I came up with
<?php
/**
* Template Name: Main_Page
* Description: A page template without sidebar.
*
* #package Graphy
*/
get_header();
?>
<!--<div id="primary" class="content-area">-->
<!--<main id="main" class="site-main" role="main">-->
<div id="main_content">
<?php
the_content(); // the content
?>
</div>
<!--</main> #main -->
<!--</div> #primary -->
<?php get_footer(); ?>
However when I installed this plugin which is used to insert widgets to pages and posts
with the main_page no widget is displayed but when I switched to "no sidebar page" it worked.
I then copied the loop into my main page and it worked.
2- What is the secret that this loops makes the plug-in work, while calling only <?php the_content() ?> does not ?! Obviously this loop makes some other things than what 90% of the posts on the internet explain.
On your first question, page templates does output information, that is why you see the loop. This information that is shown is the information entered in the page editor screen inside the tinymce editor.
For better understanding, go and read these two posts I've done recently on WPSE
Guidance with The Loop for CMS
The Loop in Static Page
On question two, the_content() does not output sidebars and widgets, but the content entered into the post editor. Sidebars are displayed with specific calls.
You will need to go and look how your theme register sidebars. I also suspect that your sidebar's behavior is manipulated by body_classes. Unfortunately here I can't help as this is quite very specific to your theme
Its all about the_post(); ,there is no need for any while loop there.
Try this
<?php
the_post();
the_content();
?>
It will work. the_post() is the function that retrieves a post content.
The while loop is needed only when retrieved are called from a category.
I'm working on a Wordpress landing page template and the way I want it to work is that each content-xxxxxx contains a different block of text/images etc. Then on the Front Page I can call them like;
<?php get_header(); ?>
<div class="container">
<?php get_template_part( 'content', 'featuredcontent'); ?>
<?php get_template_part( 'content', 'textblock'); ?>
</div>
<?php get_footer(); ?>
Which is great and works fine, but I want to be able to choose the order of the blocks from within WordPress without having to edit the front-page.php file, does anyone have any idea or code that can help with this?
Thanks
I just got jQuery to be able to load a page into a body div.
Now I'm trying to get wordpress functionality into various pages that I can then load into that body div.
Everything loads and I know the right pages are being accessed but I've run into a very unexpected problem.
Fatal error: Call to undefined function wp_head() in /home/nighthav/public_html/GENOMESTUDIOS.CA/wp-content/themes/GenomeStudios2013/news.php on line 2
I realize now that because the page is separate from the main site when it loads that it doesn't have any access to anything.
The page that needs to load is super simple:
This is a body blah blah
<?php wp_head();
global $query_string;
define('WP_USE_THEMES', false);
query_posts( $query_string . '&posts_per_page=1&order=ASC&cat=2');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1>Title: <?php the_title(); ?></h1>
Body: <?php the_content(); ?>
Time: <?php the_time(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Is there a way to regain the connection to my WP functions? Everything is in the same location.
I haven't used Wordpress very much and am out of practice so please make it as clear as you can.
Added:
If I remove the header call I get this:
Fatal error: Call to undefined function query_posts() in /home/nighthav/public_html/GENOMESTUDIOS.CA/wp-content/themes/GenomeStudios2013/news.php on line 5
I have no connection to the Wordpress system from this page I'm trying to load.
You should add the following code at the start of your file(before calling wordpress functions):
require('../../../wp-blog-header.php');
You adjust the ../ to match the wp-blog-header.php file of your wordpress installation(found in the top level folder).
Replace wp_head(); with get_header(); or if you don't need the header there, just erase it.