How to include comments under posts in a clean build template? - php

I am new to wordpress theme development and currently building building my first one from scratch, I have hit an issue with adding comments with blog posts.
I have the loop the that returns each post:
<div class="eachPost">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>"><?php
the_title();?></a></h2>
<p class="entry-meta">by <?php the_author_meta('first_name'); ?>
<?php the_author_meta('last_name'); ?> in <?php the_category(", ")
?></p>
<p class='right'><a class='comments-count' href='<?php the_permalink() ?>'><?php comments_number('0', '1', '%')
?></a></p>
<?php comments_template(); ?>
</article>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<p><?php the_content(__('(more...)')); ?></p>
<hr> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
</div>
I believe that I need to call the function:
<?php comments_template(); ?>
but adding this to the code has no effect.
I have comments.php and comment-template.php in the same folder as the file and believe that I need to include these in the page as follows
<?php get_template_part('comments.php'); ?>
<?php get_template_part('comments_template.php'); ?>
Using in config
<?php define('WP_DEBUG', true);?>
<?php define('WP_DEBUG_LOG', true);?>
<?php define('WP_DEBUG_DISPLAY', true);?>
Create no error in logs or info.
In a clean build template how do you include comments under posts?

The comments.php needs to be inside the Template root folder, please take a look at the Wordpress Codex http://codex.wordpress.org/Function_Reference/comments_template
If you want to have it somewhere else, here's the Wordpress recommendation:
The path to the file used for an alternative comments template should
be relative to the current theme root directory, and include any
subfolders. So if the custom comments template is in a folder inside
the theme, it may look like this when called:
<?php comments_template( '/custom-templates/alternative-comments.php' ); ?>
You see no errors because there's no mistake there. The system is calling a function that should load a file that if it doesn't exist, no error is thrown.

Related

Wordpress comments not showing in single.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.

Switching between posts in wordpress

I have created a sidebar.php-file with the code;
<section class="sidomeny"><p class="Senastenytt2"><?php get_search_form();?></p></section><!--Slut på sidomeny-->
<div id="nyhet3">
<?php
query_posts('category = all');
if (have_posts()) :
while (have_posts()) : ?>
<?php the_post(); ?>
<p class="datum2"><?php the_time('Y-m-d'); ?></p>
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
<?php the_excerpt(); ?>
<p class="textnyhet2"></p>
<?php
endwhile;
endif;
?>
</div><!--Slut på Nyhet3-->
And now I would like to add the function that if you press the sidebar news section, the "textnyhet2" section will get updated with the news you clicked on. That is how it's working now.
But the problem is that the sidebar vanished whenever you click on one of those "latest news" links. So what I need help with is to edit the sidebar.php-file so the "latest news" function with links is still there so you don't have to go back one page whenever you would like to read about another post.
Im not sure how to do this. If it's php involved or if you can do it by simple visiting the posts/pages section in wordpress.
Would be grateful if anyone could help me. If I have forgotten any necassary information please tell me and I will the post.
Thanks!
<?php
get_header();
?>
<section class="textinnehall">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;?>
</section>
<section class="sidomeny">
<?php
get_sidebar(); ?>
</section>
<?php
get_footer();
?>
This is my page.php file. Don't know if it will be to any help. But the sidebar is already active.
May be the sidebar is not called in your single page.
you need to have the same design in your themes single.php page(As per twenty ten theme standard).
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
The href <?php the_permalink() ?> takes the post to single page for full view
Just call the sidebar in your theme's single page.

How Can i Remove all sidebars from specific wordpress pages?

hi everyone im trying to remove all of the sidebars from a specific video page im creating on a wordpress site ive found tutorials on google on how to do this if the sidebars are called to the page using the
<?php get_sidebar(); ?>
method however my theme uses following method to call sidebars to a page
<?php include(TEMPLATEPATH."/sidebar.php");?>
i cant find any good methods for removing the sidebars that calls them to a page the same way as my theme does. here is the code to my page.php file on my website any help understanding how to remove them would be greatly appreciated =)
<?php get_header(); ?>
<div id="breadcrumb"><?php breadcrumbs(); ?></div>
<?php include(TEMPLATEPATH."/sidebar.php");?>
<div id="kontenutama">
<div class="postingan">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark">
<?php the_title(); ?></a></h2><?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<br style="clear:both;">
</div>
</div>
<?php include(TEMPLATEPATH."/r_sidebar.php");?>
<br style="clear:both"><div style="clear:both">
</div>
<?php get_footer()?>
Why not create a new WordPress page template and remove the sidebar include on that page?
The theme is pretty dodgy, it shouldn't ever include files like that in template pages.

How to strip embedded video from content on category pages in WordPress?

I have a couple of posts that have YouTube videos embedded in them. I only want the videos to show up on the full version of the post. On the category page that lists the posts, I don't want the video to appear.
Here is the site: http://tsa-watch.com/
and the full version of the post:
http://tsa-watch.com/2013/03/25/tsa-makes-double-amputee-marine-remove-prosthetic-legs-during-screening/
Here is a bit of code I use in functions.php to remove the first image from a post ONLY if it is listed on a category page:
function remove_first_image ($content) {
if (is_category()) {
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
$content = preg_replace("/<object[^>]+>/i", "", $content, 1);
} return $content;
}
add_filter('the_content', 'remove_first_image');
Also, here is the loop that I am using on my index.php and category.php files:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="votes" style="min-width:60px"><strong>VOTES:</strong><?php wdpv_vote(false); ?></div>
<div class="alignleft" style="max-width:590px">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<div class="byline"><?php the_time('F jS, Y') ?> by <?php the_author() ?> in <?php the_category(', ') ?> <strong>:</strong> <?php comments_number( 'No Comments', '1 Comment', '% Comments' ); ?></div>
<div class="excerpt">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(array(115,115));
}
?>
<?php the_content('Read more »'); ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<h1>Not Found</h1>
<p><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
Any help would be appreciated...
This is a WordPress site I believe?
If so you need to look at editing the theme template file that is responsible for showing the preview of your post on the category pages and remove the section where it is showing images/videos from the post.
Unfortunately not knowing what theme it is you are using or what the file names are called it's hard to tell but look for a page template which has the word home or categories in it or open up the category.php from within your activated theme folder if you have them to see if you can find something related to this and comment it out to see if it fixes it.
Also try adding the following inside your custom function:
$content = preg_replace("/<embed[^>]+>/i", "", $content, 1);

Showing Wordpress posts on two pages

I have three pages on my site. Let's call them home, page2, and page3.
My 'home' page is set as a static front page. My 'page2' is set up as the blog page.
What I want is the following:
I want page2 to display blog posts with a certain category (of which ID is known).
AND
I want page3 to display blog posts with a certain category (of which ID is known).
The PHP code to only show posts with a certain category (or actually in my case, show posts excluding two categories) is the following:
<?php query_posts($query_string . '&cat=-3,-8'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h3>
<?php the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
Now, in my page.php, I have the following code to display posts with one category:
<?php
// BEGIN IF PAGE is newspaper articles page
if ( is_page('newspaper') ) {
//BEGIN POST REGION
query_posts($query_string . '&cat=8'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><?php the_title(); ?></h3>
<?php the_content('Read more »'); ?>
</div><!-- /.post-->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php
} //end if is_page
?>
But it doesn't show the proper posts on the newspaper page (or page3 in this question). It does, however, work for the articles page (main index.php blog page).
EDIT: I've also tried the following (but it doesn't work). I put this in the index.php file:
<?php
if ( is_page('newspaper') || is_home() ) { // START if is home
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to
<?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h3>
<!--<p><?php the_time('F jS, Y') ?> <?php //the_author() ?></p>-->
<?php the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php
} //end if is_home() or is_page()
?>
Again, this shows the posts on the main blog page, but doesn't show any posts on the newspaper page...
The question is therefore simple (I think). How do I show posts on another page OTHER than the main blog page?
Thanks!
Amit
Rather than exclude categories and exclude pages and change the standard Wordpress loop, use a new query, like this:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a></h3>
<?php the_excerpt('Read the rest of this entry »'); ?>
<?php endwhile; ?>
This can be used inside the standard WP loop and be used mutiple times in a page/post or page template without conflicting. (Enable php execution to use it in the page/post editor). Function Reference/WP Query « WordPress Codex
This also works well to use page templates to create different pages with blog posts: Page Templates « WordPress Codex, but don't forget that WP also uses category pages, too, depending on your theme: Category Templates « WordPress Codex.
I think you have to make different templates for different page. Check this link http://codex.wordpress.org/Pages
I think this thread answers the question and does what you want.
http://wordpress.org/support/topic/show-only-x-category-posts-on-page?replies=9#post-1053767
Using the string 'newspaper' in is_page('newspaper') is a potential source of the problem. It might be misspelled easily.
Have you ever tried using the page id? Something like
is_page('999')

Categories