Single.php showing blank page - php

I'm trying to build a theme of my own and uploading it to Wordpress, but my single.php file it's not working at all. It's just showing a blank page. I've tried so many things to get it to work, but now I don't know what to do anymore. This is my php-file for the blog page:
<?php
/**
*Template Name: Blog Posts
*/
get_header('header4'); ?>
<section id="headerbox">
<header>
<h2 class="referensrubrik">Nyheter</h2>
</header>
<p class="referenstext">Det senaste från AL Konsult.</p>
</section>
<main id="blog">
<?php // Display blog posts on any page # http://m0n.co/l
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=5' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article id="blogpost" id="post-<?php get_the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
<h5><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></h5>
<?php the_excerpt(); ?>
<hr>
</article>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Previous Posts'); ?></div>
<div class="next"><?php previous_posts_link('Newer Posts »'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Previous Posts'); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
</main>
<?php get_footer(); ?>
Now my single.php just looks like this (I've tried the loop, but it's just not working...):
<?php
/**
* The Template for displaying all single posts.
*/
get_header('header3'); ?>
<section id="headerbox">
<header>
<h2 class="referensrubrik">Rubrik</h2>
</header>
<p class="referenstext">Text</p>
</section>
<?php
error_reporting(-1);
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article>
<?php endwhile; ?>
<?php get_footer(); ?>
What am I doing wrong!?

I fixed it! The single.php code that works for me looks like this:
<?php
/**
* The Template for displaying all single posts.
*/
get_header('header3'); ?>
<section id="headerbox">
<header>
<h2 class="referensrubrik">Rubrik</h2>
</header>
<p class="referenstext">Text</p>
</section>
<?php
$post = $wp_query->post;
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article id="blogpost" id="post-<?php get_the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
<h5><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></h5>
<?php the_content(); ?>
<hr>
</article>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Äldre inlägg'); ?></div>
<div class="next"><?php previous_posts_link('Nyare inlägg »'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Äldre inlägg'); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php get_footer(); ?>

Your template tag is outside of the block.
<!-- /*
Template Name: Blog Posts
*/ -->
<?php
It should be:
<?php
/*
Template Name: Blog Posts
*/

Make sure there are no blank spaces or carriage returns outside the tags (especially in WP page templates): The spaces/carriage returns will cause the page not to render by throwing an exception (which you are likely not seeing because you dont have reporting enabled).
Specifically I am referring to this:
<!-- /*
Template Name: Blog Posts
*/ -->
It needs to be inside the opening PHP tag, and there should be no empty lines at the top of the page.
It should look like (no empty line breaks):
<?php
/**
* The Template for displaying all single posts.
*/
require_once('../../../wp-load.php');
get_header('header3'); ?>

Remove the following line from your code:
require_once('../../../wp-load.php');

Related

Paginate a category page of posts in Wordpress

Is it possible to add next and previous post links to a page that is querying posts from one category and displaying one post of that category per page?
This is what I currently have:
<?php query_posts('cat=2&posts_per_page=1'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article class="overlay" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="inner">
<div class="gallery" style="background-image: url(<?php the_field('image'); ?>);">
<div class="close" data-home="<?php echo home_url(); ?>">
<span class="oi" data-glyph="x"></span>
</div>
</div>
<div class="copy">
<h2><?php the_title(); ?></h2>
<?php the_field('news_content'); ?>
Next
</div>
</div>
</article>
<!-- /article -->
<?php endwhile; ?>
You can try with next_post_link()
<?php next_posts_link(); ?>
This seemed to be the only solution that worked for me, if anyone needs a template:
<?php get_header(); ?>
<main role="main">
<!-- section -->
<section>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article class="overlay" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="inner">
<div class="copy">
<h2><?php the_title(); ?></h2>
<?php the_field('news_content'); ?>
<?php the_field('copy'); ?>
<br>
<br>
<?php next_post_link( '%link', 'Next', TRUE, 'post_format' ); ?> | <?php previous_post_link( '%link', 'Previous', TRUE, 'post_format' ); ?>
</div>
</div>
</article>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
</article>
<!-- /article -->
<?php endif; ?>
</section>
<!-- /section -->
</main>
<?php get_footer(); ?>

Wordpress - Why calling the_post_thumbnail() AFTER get_sidebar() doesn't show anything on my template

I'm actually trying to display the post thumbnail inside the loop just before the content by using the_post_thumbnail(); function.
It works like a charm in anywhere in my page before I call the function
<?php get_sidebar(); ?>
After that impossible to show the post thumbnail.
I've tried with
<?php the_post_thumbnail(); ?>
and also
<?php echo get_the_post_thumbnail(); ?> but nothing happens.
Here is my whole code :
<?php
/**
* The Template for displaying all single posts
*
* #package WordPress
*/
get_header(); ?>
<div id="pageHeader" >
<div id="pageHeader-inner"> <span class="shadow"></span><img src="<?php bloginfo('template_url'); ?>/images/header_01.jpg" /></div>
</div>
<div class="container" id="pageTitle">
<h1><?php the_title(); ?></h1>
</div>
<!--Begin of content-->
<div class="grey-bg">
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="row">
<div class="col-sm-3 sidebar">
<!-- Sub Nav -->
<?php if ( is_page() ) { ?>
<?php
if($post->post_parent)
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<div class="sidebar-module sub-menu">
<ul>
<?php echo $children; ?>
</ul>
</div>
<?php } } ?>
<!--Works perfectly till here -->
<?php get_sidebar(); ?>
<!--Broken till here-->
</div> <!-- /.sidebar -->
<div class="col-sm-9">
<div class="content-main">
<div class="content white-bg left-stroke <?php echo $post->post_name; ?>">
<?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
</div> <!-- /.content -->
</div><!-- /.content-main -->
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
<?php get_footer(); ?>
Thank's a lot for your responses.
You are trying to use function the_post_thumbnail() outside WordPress loop. To use this function outside loop you have to specify "post ID". Documentation for this function http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
For example to get thumbnail for post ID 4 you have to use function with parameter 4 like the_post_thumbnail(4) or store ID in variable.

Wordpress pagination issue with post_type('page')

I am having a great problem with pagination using a custom template(page-location.php).
I created a custom loop in that template to query child pages. Everything looks great so far except the pagination's not showing up. I tried both with plugins and wordpress default pagination functions. What am I doing wrong here? Can you please give me a moment and explain why it's not showing up? Thanks in advance! Please have a look at the codes! I tried every solutions out there.. This site is my last hope. ***Please note that post_type = 'page', not POST.
<?php
/*
Template Name: Location Template
*/
?>
<?php get_header(); ?>
<?php $options = get_option('katerina_custom_settings'); ?>
<div class="container main-content">
<h1><?php wp_title(''); ?></h1>
<div class="row">
<?php $this_page_id=$wp_query->post->ID; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$my_query = new WP_Query("post_type=page&post_parent=$this_page_id&posts_per_page=2&paged=$paged");
if ($my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('article span4 clearfix'); ?>>
<?php if (has_post_thumbnail()) : ?>
<figure class="article-preview-image">
<?php the_post_thumbnail(); ?>
</figure>
<?php endif; ?>
<article class="content clearfix">
<?php if (get_the_title() != '') : ?>
<h2><?php the_title(); ?></h2>
<?php else : ?>
<?php _e('Permalink to the post', 'adaptive-framework'); ?>
<?php endif; ?>
<?php the_content(); ?>
Details
</article>
<div class="meta-data clearfix">
<ul class="meta-comments pull-left">
<li class="article-meta-comments">
<?php
// Only show the comments link if comments are allowed and it's not password protected
if (comments_open() && !post_password_required()) {
comments_popup_link('0', '1', '%', 'article-meta-comments');
}
?>
</li>
<li class="article-meta-like">10</li>
</ul>
<ul class="social-share pull-right">
<li class="fb">Share on Facebooks</li>
<li class="google">Share via Google</li>
<li class="twitter">Share via Twitter</li>
</ul>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
<!-- end row -->
</div>
<div class="container">
<div class="pagination pull-right">
<?php if(function_exists('tw_pagination'))
tw_pagination();
?>
</div>
</div>
<!-- end main-content -->
<?php get_footer(); ?>
You should try this
<div class="pagination pull-right">
<?php if(function_exists('tw_pagination'))
tw_pagination($my_query);
?>
</div>

WordPress - pagination on template page?

I'm building my site with WordPress templates for granular control over how each of them looks.
I have my loop on my news page to pull in posts from, well, posts.
Working fine, or so I thought.
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<div id="main-content">
<?php get_sidebar(); ?>
<?php query_posts ("posts_per_page=4"); ?>
<?php if (have_posts()) : while ( have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in <?php the_category(', ') ?> |
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; endif; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
</div> <!-- end div main-content -->
<?php get_footer(); ?>
The older/newer entries show up, but after clicking on them it just takes me to the same page/newest 4 posts.
How do I get the pagination working with template pages like this?
You need to add the paged parameter to query_posts() to paginate the results:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=3&paged=' . $paged);
?>
http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »') ?></div>
Just put this line in your page.

Why isn't my Wordpress next_posts_link not working with exclude category loop?

I'm trying to setup a loop in Wordpress that will show all posts from one category, which is working just fine, however my problem is that my 'next_posts_link' and 'previous_posts_link' doesn't work. They navigate between pages just fine but the results are the same as the first page all the time.
<?php get_header(); ?>
<div id="main" role="main">
<?php
if (is_home()) {
query_posts("cat=-6");} //Exclude work posts (cat 6) from the news page
?>
<div class="inner">
<h1><?php trim(wp_title("")); ?></h1>
<?php include ('sidebartwo.php'); ?>
<section class="main-wrap twocol news">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="box-style">
<time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
<h2><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?>
</a></h2>
<?php the_content(''); ?>
</article>
<?php endwhile; ?>
<div class="next-prev-wrap">
<!-- This is what isn't working properly -->
<span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
<span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?>
<!-- /end -->
</span>
</div>
</section>
<?php endif; ?>
</div> <!-- /inner -->
</div> <!-- /main -->
<?php get_footer(); ?>
I don't think I'm using the right syntax, in fact according to the WP codex page, I don't even think my next/prev links are able to work the way I want it to. How should I approach this?
Fixed myself. This post is now resolved. After much (and I mean much) Googling, I found this article which solved my problem: http://www.dynamicwp.net/articles-and-tutorials/pagination-problem-when-excluding-certain-category-from-blog-main-page/
For reference my new code now looks like this:
<?php get_header(); ?>
<div id="main" role="main">
<?php
if (is_home()) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=-6&paged=$paged");
}
?>
<div class="inner">
<h1><?php trim(wp_title("")); ?></h1>
<?php include ('sidebartwo.php'); ?>
<section class="main-wrap twocol news">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="box-style">
<time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
<h2><?php the_title(); ?> </h2>
<?php the_content(''); ?>
</article>
<?php endwhile; ?>
<div class="next-prev-wrap">
<span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
<span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?></span>
</div>
</section>
<?php endif; ?>
</div> <!-- /inner -->
</div> <!-- /main -->
<?php get_footer(); ?>

Categories