0

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><a href="<?php the_permalink(); ?>" title="Läs mer" class="blogpost"><?php the_title(); ?></a></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('&laquo; Previous Posts'); ?></div>
   <div class="next"><?php previous_posts_link('Newer Posts &raquo;'); ?></div>
  </nav>

  <?php } else { ?>

  <nav id="nav-posts">
   <div class="prev"><?php next_posts_link('&laquo; 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!?

Jessie.J
  • 85
  • 2
  • 9
  • 1
    enable error reporting: http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php – Gordon Jan 08 '16 at 18:29
  • 1
    Take a look at [`error_reporting(E_ALL);`](http://php.net/manual/en/function.error-reporting.php) and [`ini_set('display_errors', 1);`](http://php.net/manual/en/function.ini-set.php), you have a syntax-error somewhere. – Qirel Jan 08 '16 at 18:29
  • First of all, you should not be calling wp-load manually. – moorscode Jan 08 '16 at 18:31
  • Thanks all of you for trying to help me! I've been testing everything, but unfortunately it's not working yet :( – Jessie.J Jan 10 '16 at 18:53

4 Answers4

1

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><a href="<?php the_permalink(); ?>" title="Läs mer" class="blogpost"><?php the_title(); ?></a></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('&laquo; Äldre inlägg'); ?></div>
   <div class="next"><?php previous_posts_link('Nyare inlägg &raquo;'); ?></div>
  </nav>

  <?php } else { ?>

  <nav id="nav-posts">
   <div class="prev"><?php next_posts_link('&laquo; Äldre inlägg'); ?></div>
  </nav>

  <?php } ?>

  <?php wp_reset_postdata(); ?>   
  
<?php get_footer(); ?>
Jessie.J
  • 85
  • 2
  • 9
0

Your template tag is outside of the block.

<!-- /*
Template Name: Blog Posts
*/ -->

<?php

It should be:

<?php
/*
Template Name: Blog Posts
*/
moorscode
  • 801
  • 6
  • 13
0

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'); ?>
Korgrue
  • 3,430
  • 1
  • 13
  • 20
0

Remove the following line from your code:

require_once('../../../wp-load.php');

Jason Roman
  • 8,146
  • 10
  • 35
  • 40
Shayan H.
  • 1
  • 1