Wordpress comments not showing in single.php - php

comments not showing in single.php
this is my code in single.php (I have created comments.php and copied the code from default comments.php file theme):
<?php get_header(); ?>
<div class="content-post container">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> | <?php the_category(', '); ?> | <?php comments_number('No comment', '1 comment', '% comments'); ?></p>
<?php the_content(); ?>
<?php wp_list_comments(); ?>
<?php endwhile; else: ?>
<h2>Woops...</h2>
<p>Sorry, no posts we're found.</p>
<?php endif; ?>
<p align="center"><?php posts_nav_link(); ?></p>
</div>
<?php get_footer(); ?>
could this be due the css issue? I also installed Disqus plugin and its not displaying

This code looks good. Could be a couple things:
In the admin area, go to the post your viewing and find the "Comments Allowed" checkbox, if your theme allows it.
Try changing the code:
wp_list_comments();
to:
comments_template();
Change it back if that doesn't work.
Don't know what you mean by "css issue". If it's a CSS issue, make some comments, then view the page in a browser. View the page source, and if the comments are set to display:none, you'll still be able to see them in the page source, then you'll know if it's a CSS issue.

Related

Been running into a critical error with WordPress Theme

With one of my own WordPress Themes, I would click on any links under the recent posts category and I would receive the "gray screen of death" with the following error:
There has been a critical error on your website.
Learn more about debugging in WordPress.
I did the disable plugins deal but that didn't work. If you click on Archives and Categories, those work without no problems. Long story short, I walked away from studying WordPress and Web Development in early 2019 due to working mainly 55+ hours a week. Back in early 2019, those recent posts links worked, but now in Oct 2020, they don't.
Here's a link to the theme (yes, the footer is off, I'm looking to fix it next):
https://rthomas.xyz/TestAreaA/
Thanks for the help, hopefully I'm making sense here.
After further digging, there was something wrong with my single.php. I did the following to create a debug.log file in the wp-content folder, you can find it on the WordPress website:
Example debugging for wp-config
Next, the debug.log told me of an error on my single.php. It's the reason why the Archives and the Categories links worked but not the single posts.
My single.php had the following code:
<?php get_header(); ?>
<div class="container">
<div class="primary">
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<hr>
<h2><?php the_title(); ?></h2>
<p class="date-author">Posted: <?php the_date(); ?> by <?php the_author(); ?></p>
<p><?php the_content(); ?></p>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your critera.' ); ?></p>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>
<hr>
</div><!--/.primary-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It said that the error was on the last line. After some editing, I reduced it to this:
<?php get_header(); ?>
<div class="container">
<div class="primary">
<!-- Start the Loop. -->
<h2><?php the_title(); ?></h2>
<p class="date-author">Posted: <?php the_date(); ?> by <?php the_author(); ?></p>
<p><?php the_content(); ?></p>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>
<hr>
</div><!--/.primary-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Wordpress Custom Theme: Plugins Won't Load or Display Only Code

This is my first attempt at creating a theme purely from scratch. Before this I just used underscores_me and made most of my changes to style.css and left the majority of PHP alone, because I'm a novice with it.
My issue is that plugins are not working. None of the ones I have installed work. At this point I have been trying plugins that create an event calendar, but I'm assuming that any and all plugins will have issues. In the areas that are meant to display the calendar, there are two things I'm seeing. Plugin-generated pages show nothing at all (aside from the theme visuals) and plugins that are inserted into an admin-created page display plugin-generated code.
I am using WampServer. I have wp_footer(); and wp_head(); in the correct places. My functions.php file was created from the example found at https://scanwp.net/blog/create-a-wordpress-starter-theme-from-scratch/ and the only adjustment I have made to it so far is to remove the fontawesome line of code.
My index.php file looks like this:
<?php get_header(); ?>
<h1><?php echo "&#9755 "; ?><?php the_title(); ?></h1>
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Display post content
endwhile;
endif;
?>
<?php get_footer(); ?>
And my page.php file looks like this:
<?php get_header(); ?>
<h1><?php echo "&#9755 "; ?><?php the_title(); ?></h1>
<?= get_post_field('post_content', $post->ID) ?>
<?php get_footer(); ?>
First of all, you have to understand that in your displayed files, there are no functions that recall objects that will later show the page content.
Then, in your index.php file there is an error, besides what was said above, because you're calling the_title () (function) that extrapolates the title of a post or page via the post object, which in this case should be extracted within the while loop contained within the if condition.
Then try editing the files as follows.
index.php
<?php
get_header(); ?>
<?php if( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php if( is_singular() ) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else: ?>
<h1>No posts to display</h1>
<?php endif; ?>
<?php get_footer(); ?>
and page.php
<?php
get_header(); ?>
<?php while( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php get_footer(); ?>
However, within the wordpress codex you will find all the guides well written on any type of function, look no further.
source: https://codex.wordpress.org/

Loop within my single.php WordPress blog only return for one post

hi i has a wordpress blog i put this code below within single.php page in side bar
the code is the same code in the hompage side bar >
this code is correctly work in hompage sidebar and return to all posts
but in the single.php sidebar only return to one post.
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="new-posts-form">
<div class="new-posts-img"><?php the_post_thumbnail(array(100,80)); ?></div>
<div class="new-posts-title"><?php the_title(); ?></div>
<div class="new-post-description"><?php content('11'); ?></div>
<div class="new-post-add-date-time"><img src="<?php bloginfo('template_url'); ?>/images/tb_clock.png" /><?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> : <?php the_category(', ') ?></div>
<?php endwhile; ?>
<?php endif; ?>
I think on single.php page you should use this
for reference please check
http://codex.wordpress.org/Function_Reference/get_post
i am trying to solve your problem hope this help.
thanks
anand

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.

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

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.

Categories