Wordpress: single.php doesn't display the_content() - php

I'm creating a custom Wordpress Theme and I can't seem to get the single.php template to work. Below is the code I have written. The title comes up but the content doesn't. Any Ideas why it isn't?
<?php
/**
* The Template for displaying all single posts.
*/
get_header(); ?>
<div id="content" role="main">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
</div><!-- #content -->
See here for a screenshot of the output:

the_content() is not displaying because it has to be inside the The Loop - take a look at the docs here »
You need to change your code to this:
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile;
else:
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
endif;
You can leave out the else if you are always sure you have content to display :) Or just take look at the original single.php where you can find The Loop always surrounds the_content()
edit:
Here is the whole single.php you might wanna use/start with:
<?php
/**
* The Template for displaying all single posts.
*/
get_header(); ?>
<div id="content" role="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endwhile; endif; ?>
</div><!-- #content -->

I just simply put the_post() above the_content() and it worked

I'm writing this because I had a similar problem. My content wasn't showing up. However my call to the_content was inside the The Loop. Furthermore, this was working on my development server but not on the production server.
I was able to solve this by removing all the plugins and then, one by one, add them back in.
Also, of course, if you have caching enabled, a good first step is to clear the cache.

Related

Twitter-bootstrap-3 and Wordpress post display

Scratching my head over this one but it is probably simple? I cannot seem to figure it out. So I am showing blog posts using a custom theme I have made with Twitter-Bootstrap-3 but having a problem showing my posts in a grid.
so i have a latest post at the top which is fine. but below I am aiming to show a grid of posts so when a new one is added it naturally goes to the top, I also have a side bar on the right. so the grid of posts should be 3 across and then create a new row and so on. My posts are just creating new rows now matter if i set them to be say col-md-3?
<?php endwhile; wp_reset_query(); ?>
<h2 class="blog-title">Past Posts</h2>
<div class = "col-md-3">
<?php while(have_posts()) : the_post(); ?>
<?php the_post_thumbnail( 'medium', $attr ); ?>
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<p class="text-muted">Posted by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?></p>
<p><?php comments_number( 'no responses', '1 response', '% responses' ); ?>.</p>
<hr>
<?php endwhile; wp_reset_query(); ?>
From researching I guessing there is a requirement for a loop of some sort? I am unsure form my code where to begin with that...
probably because you need to wrap each post is s col-md-3, not all of the in a single one?
So have a look at this...
<h2 class="blog-title">Past Posts</h2>
<?php while(have_posts()) : the_post(); ?>
<div class = "col-md-3">
<?php the_post_thumbnail( 'medium', $attr ); ?>
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<p class="text-muted">Posted by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?></p>
<p><?php comments_number( 'no responses', '1 response', '% responses' ); ?>.</p>
<hr>
</div>
<?php endwhile; wp_reset_query(); ?

PHP codes for wordpress

Hello guys so I am making a car review wordpress magazine and I am having issues with php codes as I am not a great programmer. Actually on this page Memes I would like the social plugins to be below each picture and not on the top furthermore I would like it to display the post date and the author of the post. Some formatting for the pictures size etc would be great too. Below is the code I am using
<?php /*
Template Name: ListPostsInCategoryThatHasSameNameAsPage
*/ ?>
<?php get_header(); ?>
<div id="content" class="archive <?php if(get_option('colabs_layout_settings')=='two-col-right'){echo 'right';}else{?>left<?php }?>">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post_<?php the_ID(); ?>">
<span id="map"><?php _e('Home','colabsthemes');?> » <?php the_title(); ?></span>
<h2 class="title"><?php the_title(); ?></h2>
<div class="entry" style="padding-top:15px;">
<?php the_content(__('<p>Read the rest of this page »</p>','colabsthemes')); ?>
<?php echo colabs_share();?>
<?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong>','colabsthemes'), 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
</div>
</div>
<div id="sidebar" class="<?php if(get_option('colabs_layout_settings')=='two-col-right'){echo 'left';}else{?>right<?php }?>">
<?php get_sidebar(); ?>
</div>
<div> <?php get_footer(); ?> </div>
Finally for the review part I would like to do something like Autotest/review but I don't know which code to use to show these kind of square articles. Please help me out.
For adding the author and date of the post, you can add:
<p>Written by:
<?php get_the_author(); ?></p>
get_the_author() will display the author's name as is set in their "Display name publicly as" field in their user profile (Administration > Users > Your Profile).
To also display the date:
<p>Written by:
<?php get_the_author(); ?> on
<?php get_the_date(); ?></p>
I don't see where you're using the social sharing links on the page you linked to - did you remove them?
For more information:
http://codex.wordpress.org/Function_Reference/get_the_author
http://codex.wordpress.org/Function_Reference/get_the_date

Wordpress post not showing up title when redirected from permalink

I've created my own theme. On my front page (index.php), I am showing a snippet of posts, with 'Read More' link in the end. So when I click read more, I get redirected to that post's page (localhost/wordpress/2014/post-title/), but there, I can't see the title of the post, but all the content.
Code for snippet in index.php
<div id="blog" class="container">
<?php query_posts('showposts=3'); ?>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="post col-md-4">
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_excerpt(__('(more…)')); ?>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
</div>
</div>
<?php endwhile; ?>
<div class="navigation">
<?php posts_nav_link(); ?>
</div>
<?php endif; ?>
</div>
So how do I get the post title there?
I think people can't help you to solve this with this code. If that post's page doesn't show the post title, then you need to check on single.php
Probably, you may have forgot to add the <?php the_title(); ?> part in that single.php file.

Wordpress Page Template Not Rendering

Our blog page is supposed to look something like this: http://livedemo00.template-help.com/wordpress_33821/?page_id=174
However it ends up looking like this - completely empty!
This is despite the fact that the page theme is set correctly and the template file contains the following code:
<?php
/**
* Template Name: Blog
*/
get_header(); ?>
<div class="box clearfix color2">
<div id="content" class="three_fourth">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=5'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<h2><?php the_title(); ?></h2>
<div class="post-meta">
<div class="fleft">Posted in: <?php the_category(', ') ?> | <time datetime="<?php the_time('Y-m-d\TH:i'); ?>"><?php the_time('F j, Y'); ?> at <?php the_time() ?></time> , by <?php the_author_posts_link() ?></div>
<div class="fright"><?php comments_popup_link('No comments', 'One comment', '% comments', 'comments-link', 'Comments are closed'); ?></div>
</div><!--.post-meta-->
</header>
<?php echo '<div class="featured-thumbnail">'; the_post_thumbnail(); echo '</div>'; ?>
<div class="post-content">
<div class="excerpt"><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,50);?>Read more</div>
</div>
</article>
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<nav class="oldernewer">
<div class="older">
<?php next_posts_link('« Older Entries') ?>
</div><!--.older-->
<div class="newer">
<?php previous_posts_link('Newer Entries »') ?>
</div><!--.newer-->
</nav><!--.oldernewer-->
<?php endif; ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div><!--#content-->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Unfortunately this theme doesn't have any documentation so I'm forced to find my own solution.
Actually I already faced this situation in WordPress.
Its not fault of your code. Might be WordPress Bug.
Try to change your page name once.
Like
<?php
/**
* Template Name: Blog_new
*/
?>
And login again and check if it is showing new custom page option or not.

Trying to Edit 'Blog' Template, to display full posts not excerpts

I'm working with a theme I paid for a long time ago, customized a bunch graphically and with the CSS and am pulling pieces of it into separate directory via iFrame Fancybox.
BUT, I'm trying to reformat the blog template - as currently it renders and populates when updated as:
Title
etc etc
A few lines of Content here/ then cuts of mid sentence.
Read More , etc // And these links just refresh the page?
So, I'm a bit novice with PHP & am wondering how I'd edit the below 'Blog Template' code to allow full posts text to display, not excerpts that are cut off in the middle:
<?php
/*
Template Name: Blog Template
*/
get_header();
?>
<div id="content">
<?php
//get exclusions for categories
$exclude = get_option($shortname.'_exclude_categories');
$exclude = str_replace(',,','|-',$exclude);
$exclude = str_replace(',','-',$exclude);
$exclude = substr($exclude, 0, -1);
$exclude = str_replace('|',',',$exclude);
query_posts('posts_per_page=&paged='.$paged.'&cat='.$exclude);
if(have_posts()) : while(have_posts()) : the_post();
?>
<div class="entry" id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p class="meta">Added by <?php the_author_posts_link() ?> on <?php the_time('F jS, Y') ?>, filed under <?php the_category(', ') ?></p>
<div class="entry-content">
<p><?php the_post_thumbnail('wide'); ?></p>
<?php the_excerpt('Read the rest of this entry »'); ?>
<p><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> ~ Add your thoughts | Continue Reading</p>
</div><!-- e: entry content -->
</div><!-- e: entry -->
<?php
endwhile;
//endif;
?>
<div class="paginate">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
</div><!-- e: content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Replace the_excerpt() with the_content(), that's it.

Categories