0
votes

I have updated my wordpress and now my wordpress single posts are not showing. Header and post title are showing up but post title and sidebar are missing.

When I switch to some other theme everything works fine, but with my theme there is a problem. I tried to manually reinstall sigle.php of the theme but nothing changed. I tried changing permalinks structure, deleting all inactive plugins and turning off and on all active plugins but still nothing changed.

I am using a Sharp Magazine theme from Gabfire. Here is an example: http://www.turizamiputovanja.com/nis-dobija-novi-hotel-u-centru-grada/.

Here is my single.php

<?php get_header(); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post();

    /* post template defined on custom fields? */
    $post_layout = get_post_meta($post->ID, 'gabfire_post_template', true); 

    /* Any subtitle entered to post? */
    $subtitle = get_post_meta($post->ID, 'subtitle', true);
     ?>

    <?php /* Post lead */ ?>
    <section class="row">
        <div class="col-md-12">
            <div class="post-lead">
                <p class="post-category"><?php the_category(' &middot; '); ?></p>
                <h1 class="post-title"><?php the_title(); ?></h1>
                <p class="post-datecomment"> 
                    <?php
                    $authorlink = '<a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.  get_the_author() . '</a>';
                    printf(esc_attr__('%2$s Autor: %1$s','gabfire'), $authorlink, get_the_date());
                    ?>
                    <?php
                    /* get the number of comments */
                     $num_comments = get_comments_number();
                     if ( comments_open() ){
                          if($num_comments == 0){  $comments = __('Nema komentara', 'gabfire');  }
                          elseif($num_comments > 1){ $comments = $num_comments. __(' Komentara', 'gabfire'); }
                          else{ $comments = __('1 komentar', 'gabfire'); }
                     }
                     echo '<span class="commentnr">' . $comments . '</span>';
                    ?>
                </p>

                <?php 
                if (($subtitle != '') && (($post_layout == 'bigpicture') or ($post_layout == 'fullwidth'))) { 
                    echo "<p class='subtitle postlead_subtitle'>$subtitle</p>"; }
                ?>
            </div>
        </div>
    </section>
    <?php 
    /* Call user defined post template */ 
    if ($post_layout == 'bigpicture') {
        get_template_part( 'single', 'bigpicture' );

    } elseif ($post_layout == 'fullwidth') {
        get_template_part( 'single', 'fullwidth' );

    } elseif ($post_layout == 'leftsidebar') {
        get_template_part( 'single', 'leftsidebar' );

    } else {
        get_template_part( 'single', 'default' );   
    }
    ?>

    <?php endwhile; else : endif; ?>

<?php get_footer(); ?>

I have red all the similiar questions and answers here but none seems to be helpful for me. Thanks!

1
Looks like the_content() is being called outside the while loop - might be worth looking into that - trysmudford

1 Answers

0
votes

the_content() should be inside the loop as this is actually content of your post.

<?php get_header(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post();

/* post template defined on custom fields? */
$post_layout = get_post_meta($post->ID, 'gabfire_post_template', true);

/* Any subtitle entered to post? */
$subtitle = get_post_meta($post->ID, 'subtitle', true);
?>

<?php /* Post lead */ ?>
<section class="row">
  <div class="col-md-12">
    <div class="post-lead">
      <p class="post-category"><?php the_category(' &middot; '); ?></p>
      <h1 class="post-title"><?php the_title(); ?></h1>
      <p class="post-datecomment">
        <?php
        $authorlink = '<a href="'.get_author_posts_url(get_the_author_meta( 'ID' )).'">'.  get_the_author() . '</a>';
        printf(esc_attr__('%2$s Autor: %1$s','gabfire'), $authorlink, get_the_date());
        ?>
        <?php
        /* get the number of comments */
        $num_comments = get_comments_number();
        if ( comments_open() ){
          if($num_comments == 0){  $comments = __('Nema komentara', 'gabfire');  }
          elseif($num_comments > 1){ $comments = $num_comments. __(' Komentara', 'gabfire'); }
          else{ $comments = __('1 komentar', 'gabfire'); }
        }
        echo '<span class="commentnr">' . $comments . '</span>';
        ?>
      </p>

      <?php
      if (($subtitle != '') && (($post_layout == 'bigpicture') or ($post_layout == 'fullwidth'))) {
        echo "<p class='subtitle postlead_subtitle'>$subtitle</p>"; }
        ?>
    </div>
  </div>
</section>
<div class="row">
  <div class="col-md-8">
    <?php the_content(); ?>
  </div>
  <?php get_sidebar(); ?>
</div>

<?php
/* Call user defined post template */
/*if ($post_layout == 'bigpicture') {
get_template_part( 'single', 'bigpicture' );

} elseif ($post_layout == 'fullwidth') {
get_template_part( 'single', 'fullwidth' );

} elseif ($post_layout == 'leftsidebar') {
get_template_part( 'single', 'leftsidebar' );

} else {
get_template_part( 'single', 'default' );
} */
?>

<?php endwhile; else : endif; ?>

  <?php get_footer(); ?>

the_template_part is loading single-default.php which is weird, because single-default.php contains another loop? This file structure is inappropriate, take a look on twentysixteen theme:

<?php
/**
 * The template for displaying all single posts and attachments
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */

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 single post content template.
            get_template_part( 'template-parts/content', 'single' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            if ( is_singular( 'attachment' ) ) {
                // Parent post navigation.
                the_post_navigation( array(
                    'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
                ) );
            } elseif ( is_singular( 'post' ) ) {
                // Previous/next post navigation.
                the_post_navigation( array(
                    'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
                        '<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
                        '<span class="post-title">%title</span>',
                    'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
                        '<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
                        '<span class="post-title">%title</span>',
                ) );
            }

            // End of the loop.
        endwhile;
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Look at get_template_part( 'template-parts/content', 'single' ); They cut off the content stuff to other file template-parts/content-single. It is better in many ways fe. managment, version control.