Wordpress Custom pages - php

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 } ?>

Related

Set index.php file to only show posts from one category

Here is a copy of my index.php file, which i gather governs what is shown on the posts page. Im wanting the posts page to only show the posts from my "blog" category. Can someone help with the code changes that i need to make, to implement this?
Thanks heaps guys
Erin
<?php
$archive_page_layout = esc_attr(of_get_option('archive_page_layout'));
?>
<main id="main" class="site-main clearfix <?php echo esc_attr($archive_page_layout); ?>">
<?php if($archive_page_layout == 'both-sidebar'): ?>
<div id="primary-wrap" class="clearfix">
<?php endif; ?>
<div id="primary" class="content-area">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content' , 'blog' );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #primary -->
<?php
if($archive_page_layout == 'both-sidebar' || $archive_page_layout == 'left-sidebar'):
get_sidebar('left');
endif;
?>
<?php if($archive_page_layout == 'both-sidebar'): ?>
</div>
<?php endif; ?>
<?php
if($archive_page_layout == 'both-sidebar' || $archive_page_layout == 'right-sidebar'):
get_sidebar('right');
endif;
?>
</main><!-- #main -->
<?php get_footer(); ?>
you have to use argument parameters to specify a posts categorie/s please refer to
https://wordpress.stackexchange.com/questions/145125/display-content-from-a-specific-category for the code you will need.
:)

How to add post format to theme?

For classipress theme. I can register post_formats the normal way in functions (works - I can select "link" type in the editor), but I can't figure out how to get it to actually use a template file for link posts.
I have used the get_template_part('content', get_post_format()); in the past successfully,
but I can't figure how to inject that into the single.php's code for this theme:
Single.php
<?php
/**
* The Template for displaying all single posts.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 1.0
*/
?>
<div class="content">
<div class="content_botbg">
<div class="content_res">
<div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
<div class="content_left">
<?php appthemes_before_blog_loop(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php appthemes_before_blog_post(); ?>
<?php appthemes_stats_update( $post->ID ); //records the page hit ?>
<div class="shadowblock_out">
<div class="shadowblock">
<div class="post">
<?php appthemes_before_blog_post_title(); ?>
<h1 class="single blog"><?php the_title(); ?></h1>
<?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<?php appthemes_before_blog_post_content(); ?>
<?php if ( has_post_thumbnail() ): ?>
<div id="main-pic">
<?php cp_get_blog_image_url(); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<div class="dotted"></div>
<div class="pad5"></div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- .post -->
</div><!-- .shadowblock -->
</div><!-- .shadowblock_out -->
<?php appthemes_after_blog_post(); ?>
<?php endwhile; ?>
<?php appthemes_after_blog_endwhile(); ?>
<?php else: ?>
<?php appthemes_blog_loop_else(); ?>
<?php endif; ?>
<div class="clr"></div>
<?php appthemes_after_blog_loop(); ?>
<div class="clr"></div>
<?php comments_template(); ?>
</div><!-- .content_left -->
<?php get_sidebar( 'blog' ); ?>
<div class="clr"></div>
</div><!-- .content_res -->
</div><!-- .content_botbg -->
</div><!-- .content -->
Content.php
<?php
/**
* Post loop content template.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 3.4
*/
?>
<div <?php post_class( 'shadowblock_out' ); ?> id="post-<?php the_ID(); ?>">
<div class="shadowblock">
<?php appthemes_before_blog_post_title(); ?>
<h3 class="loop"><?php the_title(); ?></h3>
<?php appthemes_after_blog_post_title(); ?>
<?php appthemes_before_blog_post_content(); ?>
<div class="entry-content">
<?php if ( has_post_thumbnail() ) the_post_thumbnail( 'blog-thumbnail' ); ?>
<?php the_content( __( 'Continue reading ...', APP_TD ) ); ?>
</div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- #shadowblock -->
</div><!-- #shadowblock_out -->
Tried a lot of things, unsuccessful in doing anything but breaking the page.
Thanks
Post formats are used to customize the presentation of post items. If you check out some theme that supports post formats (For example Twenty Fifteen), you will see that the single.php file is not used to output the contents of the post - which is delegated to content-*.php files. (For example, the the_content() function, which outputs a post's content is not in single.php, but in content.php (and content-link.php and others).
Your single.php does not seem to be built this way, so it does not support post formats, but it can be refactored easily, just split it into two files (in single.php you should keep the "frame" code that is common for every post format, then move the rest into a new content.php file, which will be used as the default format):
single.php
<?php
/**
* The Template for displaying all single posts.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 1.0
*/
?>
<div class="content">
<div class="content_botbg">
<div class="content_res">
<div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
<div class="content_left">
<?php appthemes_before_blog_loop(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php appthemes_before_blog_post(); ?>
<?php appthemes_stats_update( $post->ID ); //records the page hit ?>
<?php
// Note the below line which loads the desired content*.php
get_template_part('content', get_post_format());
?>
<?php appthemes_after_blog_post(); ?>
<?php endwhile; ?>
<?php appthemes_after_blog_endwhile(); ?>
<?php else: ?>
<?php appthemes_blog_loop_else(); ?>
<?php endif; ?>
<div class="clr"></div>
<?php appthemes_after_blog_loop(); ?>
<div class="clr"></div>
<?php comments_template(); ?>
</div><!-- .content_left -->
<?php get_sidebar( 'blog' ); ?>
<div class="clr"></div>
</div><!-- .content_res -->
</div><!-- .content_botbg -->
</div><!-- .content -->
content.php
<div class="shadowblock_out">
<div class="shadowblock">
<div class="post">
<?php appthemes_before_blog_post_title(); ?>
<h1 class="single blog"><?php the_title(); ?></h1>
<?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<?php appthemes_before_blog_post_content(); ?>
<?php if ( has_post_thumbnail() ): ?>
<div id="main-pic">
<?php cp_get_blog_image_url(); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<div class="dotted"></div>
<div class="pad5"></div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- .post -->
</div><!-- .shadowblock -->
</div><!-- .shadowblock_out -->
Now, for additional post formats, for example gallery, you will have to create a file named content-gallery.php and implement it. You can derive it from the default content.php, but you decide how it should look like.

Loading custom pages with get_template_part()

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(); ?>

WordPress Blog Not Displaying Posts

I've created a custom template using the twentythirteen template. When I activate the template the blog posts disappear from the front page. I've used the same process to make the new template as I did for my own.
You can see my blog page here, http://www.gnarlydigital.com/blog/ and the new blog that I'm working on is here, http://www.flowdirectpumps.com/news/.
I've tripled checked all the code and both templates are identical. I've uploaded the Gnarly Digital template and it works.
Can anyone see anything obvious?
This is the index.php file
<?php get_header(); ?>
<div class="container pageContent">
<div class="row">
<div class="col-md-12">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentythirteen_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div>
</div>
</div>
<?php get_footer(); ?>

issue with post format in wordpress on a custom page template

Hey guys so I am trying to have a loop run to get all the post that are within a certain category on a page, for some reason nothing happens though?
Code :
<?php
/*
Template Name: djequip
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /*query_posts('test');uncategorized*/
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Let me know if you can help, thanks a ton!
<?php /* Template Name: TEMPLATE NAME */ ?>
<?php get_header();?>
<?php query_posts('category_name=CATEGORY NAME'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_excerpt(); ?>
<?php endwhile; ?>
Is this what you mean?
the_excerpt
can be changed to
the_content
Also I'd just like to add that you can put divs in there around the WP PHP.

Categories