I came across this function the get_template_part by talk to other person about what easy why to load custom page on front-end page he told me the get_template_part and i think its awesome for reuse of code. But him use it to loaded all my custom pages on front-page but when I view the site some content loads and some does not load on the site here screenshot.
<?php
/**
* Template Name: Front-Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-photography'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
<?php endwhile; ?>
</main><!-- #main -->
</div><!-- #primary -->
The problem is most likely either in the template files themselves, you're missing the template files, or your file names don't match your function call. For example to show your About page this code
<?php get_template_part('templates/page-about'); ?>
Means you should have a directory in your theme folder named 'templates' and a file in that directory called page-about.php. If all your files are present and correctly named you need to look in the template files themselves and check the code there
Based on the additional info you've posted on Linkedin, about the site being a one-page website, your problem is most likely because you're using the wrong file to load the homepage.
To solve this, do the following in the theme's folder:
Create a file called "home.php"
Move the contents of "page-home.php" to "home.php"
Remove the while loop so that home.php will look like this:
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-photography'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
Related
My Wordpress blog works fine on the main page that shows all posts, however, when I click a category the most recent post's title becomes the main header and that post doesn't even show up in the blog post list of that category.
https://ibb.co/ebReRV
I spied on other people with the same theme as me and they have the same problem so I believe this is a problem with the original code. My theme's creator seems to have disappeared and hasn't responded to any of my messages.
archive.php
<section id="wp-main-content" class="clearfix main-page title-layout-standard">
<?php do_action( 'naturalfood_before_page_content' ); ?>
<div class="container">
<div class="main-page-content row">
<!-- Main content -->
<div class="content-page <?php echo esc_attr($main_content_config['class']); ?>">
<div id="wp-content" class="wp-content">
<?php get_template_part('templates/layout/archive') ?>
</div>
</div>
You Need to Create Archive Page
Give Archive Page name is "archive.php".
Archive Page Structure Like this:
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
/* Custom Archives Functions Go Below this line */
/* Custom Archives Functions Go Above this line */
</div><!-- .entry-content -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Im a beginner in wordpress and while i was learning how to make themes I had a problem.
I use this code in my functions.php to add the css:
function learning() {
wp_enqueue_style('style', get_stylesheet_uri());
}
It works well for my index.php so i designed my default page as how I want. I wanted to change the look of my pages which I created in the WordPress GUI, so I created page-(otherpage).php file in my theme folder and copied the code etc, and gave different classes to the elements in page-(otherpage).php. Finally I made some changes in my style.css for my new classes but it doesn't change anything.
What should i do?
Attach a css file via function.php add following code into functions.php.
(Recommaded don't use function.php because its theme specific)
<?php
function mypage_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('stylesheet_directory').'/includes/mypage.css">'."\n";
}
add_action('wp_head', 'mypage_head');
?>
method use for add header into a template
<?php get_header(); ?>
Created Template Page here :
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I want to load all my custom pages on front-page by using the function get_template_part(); but whenever I save my code the page loads everything on front-page but is keeps on looping the content over and over and over again on the site.
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
<?php endwhile; ?>
</main><!-- #main -->
</div><!-- #primary -->
I'm also going to upload it to github https://github.com/brandonpowell/Test-Wordpress-Site/tree/master/danielschriersite
are calling the header in multiples times tries to remove each of the templates
also you call in frontpage template
try using wordpress pages templates
https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
<?php
/**
* Template Name: Front Page Template
*
* #package WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*/
?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
<?php endwhile; ?>
and the back you change the page template attr from the admin dashboard
you can also use is_front_page() function
<?php if( is_front_page() ) { ?>
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
<?php } ?>
How can i create a page in a directory like public_html/test1 that has a single blank page with the header/sidebar/footer of my actual template.
I can only see the header, no sidebar , no content ( by content i mean "Hello." ).
I'm using twenty fourteen template.
This is the php code i am using:
<?php
/*
* Template Name: My own page!
* Description: I made a page!
*/
require (dirname(dirname( __FILE__ )).'/wp-load.php');
get_header();
get_sidebar();
?>
Hello.
Note: if i delete the the_content(); get_footer(); , then the header ONLY appears but without format.
Any help deeply appreciated
The content isn't appearing because there's no loop inside your template. Please add this code inside your template and move your template file to the 'page-templates' folder inside the twentyfourteen theme.
<?php
/*
* Template Name: My own page!
* Description: I made a page!
*/
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
endwhile;
?>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_sidebar();
get_footer();
p.s. you can remove the div's if you'd like to.
I am needing some serious Wordpress expertise from others. I am in the process of building a custom theme, read about the get_template_part() method and decided that would help in cleaning up and organizing my code. I updated my theme to use this method several places and now the site is completely broken...not a single thing will load!! :( I would really appreciate any help! I will copy and paste a few of the php files below. Maybe someone with more experience with using this method can point out the problem. THANKS!
page.php
<?php get_header(); ?>
<div id="content" class="content">
<?php while ( have_posts() ) : the_post(); ?>
<!-- About page -->
<?php if (is_page('about')) ?>
<?php get_template_part( 'page', 'about' ); ?>
<!-- Media & Gallery page -->
<?php if (is_page('media-gallery')) ?>
<?php get_template_part( 'page', 'mediagallery' ); ?>
<?php endwhile; // end of the loop. ?>
</div> <!--/end content -->
<?php get_footer(); ?>
page-about.php
<div id="about">
<div class="text">
<h2 class="about"><?php echo get_the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
page-mediagallery.php
<div id="pic-gallery">
<?php include_once 'includes/pwaplusphp/albums.php'; ?>
</div>
index.php
<?php get_header(); ?>
<div class="content">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<br class="clr"/>
<?php endwhile; ?>
<?php content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h3 class="blog"><?php _e( 'Nothing Found' ); ?></h3>
</header> <!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.'); ?></p>
</div> <!-- .entry-content -->
</article> <!-- #post-0 -->
<?php endif; ?>
</div> <!--/end content -->
<?php get_footer(); ?>
content-gallery.php
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-date"><?php the_time(get_option('date_format')); ?></div>
<h3 class="blog"><?php the_title(); ?></h3>
<div class="post-content"><?php the_content(); ?></div>
</div>
Any thoughts why these may not be working? All of these files are under the root directory of the theme so the get_template_part() method should be finding all of the files. What's weird is no code is being spit out by Wordpress. aka. Since I've started using this method, not a single line of code is spit out in my browser when I inspect the source.
I am using the newest version of Wordpress and Google Chrome for my browser.
I also have this code at the top of each of my .php files, but that shouldn't mess up anything because it's commented as seen below:
<?php
/**
* I put a description of what the file does here.
*
* #package Keynote_WP_Themes
* #subpackage Rhymz_Suhreal
* #copyright Rhymz Suhreal, 2012
* #author Kyle Affolder <myemail#example.com>
*/
?>
I don't have the slightest clue as to what I'm doing wrong. :(
Ideas coding friends?!
Using your page-about.php as an example, you should be calling it like this in the template it's to be place in:
<?php get_template_part( "page-about" ); ?>
The template needs to be in the root of your theme directory so you can use "page-about" without the .php, and not have to indicate the location/directory the file would otherwise be located.
I've run into this a few times before as well - I can't really explain why yet as I'm still digging through the documentation, but it seems you can't call template parts this way when you are inside a post loop ;)
Anytime you are inside the loop, try using this instead:
<?php include(get_query_template('page-about')); ?>