wordpress comment form styling - wordpress

I have integrated a HTML Template into Wordpress theme. In, menu area there is a menu called Blog. On click of that menu I want to show all the posts. On clicking some particular posts title one should go to the single post`s page. On that page there should be comments shown which are being posted earlier by some one as well as the comment form through which one can comment on that post.
Below is my blog.php code
<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<div id="inner_contant">
<div id="all_post">
<?php
$myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<h2><?php the_title(); ?></h2>
<div class="author">Posted by <?php the_author(); ?></div>
<div class="post_excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my single.php code
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my comments.php code
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
) ?>
<?php comment_form($comment_args); ?>
I want to add some styling to that comment form. I have tried every thing but not worked for me. Thanks in advance for those who will help me.

WordPress' comment_form function prints a form with id 'commentform'. So you can use CSS to style this form.
form#commentform {
// your styles.
}
form#commentform input {
// your styles for inputs
}
/* default class of submit button is 'submit'. For changing it: add a
* key=>value to comment_form args like
* 'class_submit' => 'your_submit_class'
*/
form#commentform .submit {
// your submit button styles.
}
Also, you can change ID of comment form like this:
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?',
'id_form' => 'myAwesomeCommentForm'
) ?>
<?php comment_form($comment_args); ?>

Related

Single post template not working in WordPress

page-webinars.php:
<?php
/*
Template Name: Webinars
*/
?>
<?php
$loop = new WP_Query(array('post_type' => array('webinars')));
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post();
?>
<?php get_template_part('loop-webinars'); ?>
<?php endwhile; ?>
<?php endif;
wp_reset_postdata(); ?>
loop-webinars.php:
<?php the_title(); ?>
single-webinars.php:
<h1><?php the_title(); ?></h1>
<div>
<?php
the_post();
the_content();
?>
</div>
Looks like everything's correct. Page displays necessary template, but single not working.
You forget to use WordPress loop.
Try with this code in your single-webinars.php file.
<?php
// Start the loop.
while ( have_posts() ) : the_post();
?>
<?php the_title('<h1>', '</h1>'); ?>
<div>
<?php the_content(); ?>
</div>
<?php // End of the loop.
endwhile;
?>
It had just to "reactivate" theme...

show comments of a post below the post in single.php wordpress

I have single.php file and Im showing single post in it. I want to show comments on related to this post under this post. But the problem is Im getting comments all of comments below any post.
Below is my single.php code
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my comments.php code
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
) ?>
Thanks in advance.
use is_single() to check the post :
<?php if( is_single() ) : ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
<?php endif; // close to check single.php ?>
Remove the foreach from single.php:
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php comments_template(); ?>
<?php endwhile; endif; ?>
</div>
</div>
<?php get_footer(); ?>
Then, add it to your comments.php and pass $comment_args in get_comments() like so:
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
)
?>
<?php foreach (get_comments($comment_args) as $comment): ?>
<div>
<?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".
</div>
<?php endforeach; ?>
have a look the the function reference for get_comments to see the list of arguments you can pass into get_comments
Single.php code. Remove get_comments()
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach ($comments as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
You need to get_the_ID() per single page comment, then add the comment query.
$id - get_the_ID();
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?',
'post__in' => $id, //Retrieves comments for an array of posts
'post_id' => $post_ID // Post's ID you can make sure only comments related to that post appear.
)
?>
// The comment query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );

Wordpress blog isn't showing posts. Does adding a custom portfolio post field effect this?

Now I've done this a couple other times with no problem, I have a main page using home.php and the blog as another page using "blog-home.php" blog template with all the right code to grab the posts but it's not displaying. The only difference is I've added a custom portfolio post field to the functions, would this be effecting it or could it be something else? I can access a post from the home page under latest post putting the code below but that's it.
<?php query_posts("post_per_page=1"); the_post(); ?>
<p><?php the_excerpt(); ?></p>
<?php wp_reset_query(); ?></div>
*UPDATE: I've tried another code but now it is only displaying the blog page as a post. *
<?php
/*
Template Name: Blog Home
*/
?>
<?php get_header(); ?>
<div id="contentwrapper">
<?php query_posts( array ( 'category_name' => 'Blog', 'posts_per_page' => 5 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="blogentry">
<h4><?php the_title(); ?> </h4>
<?php the_content(); ?>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
</div>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Maybe if you use
$posts = get_posts(array('numberposts' => 1));
global $post;
$post = $posts[0];
the_excerpt();
instead
query_posts();
is never a good idea change the global query if get_posts dosn't work for you try with WP_Query()

Getting Post Author in Wordpress

I'm building a Wordpress template from an HTML page.
I currently have
<?php $queried_post = get_post( $_GET['id'], $output ); ?>
Then I use ...
<?php echo $queried_post->post_title; ?>
Which works fine for echoing the post title.
Then I try to echo the author with...
<?php echo $queried_post->post_author; ?>
I get back '1' which is not the author name. How is this done correctly?
Try this code:
<?php the_author($_GET['id']); ?>
Codex entry: http://codex.wordpress.org/Function_Reference/the_author
My single.php file:
<?php get_header(); ?>
<?php if (have_posts()): ?>
<?php while (have_posts()): the_post(); ?>
<div class="post post-single">
<h1 class="post-title">
<?php the_title(); ?>
<?php edit_post_link('Edit', '', ''); ?>
</h1>
<div class="content"><?php the_content(); ?></div>
</div>
<?php endwhile; else: ?>
There are no posts to display.
<?php endif; ?>
<?php get_footer(); ?>

Wordpress: category page not for post's

Please at first let me explain my question. I use wordpress to create web sites for flash games, so I don't have certain page for post's. I add each game by
<code>
post-new.php?post_type=game
</code>
and u can see it's not the regular post for wordpress.
I try to use this code from codex:
<code>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$i = 0;
$loop = new WP_Query(array('post_type' => 'game', 'post_per_page' => 5 ));
while ($loop->post_type()) : $loop->game();
?>
</code>
<code>
<?php if ( in_category('') ) { ?>
<div class="post-cat-three">
<?php } else { ?>
<div class="post">
<?php } ?>
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<p>Category: <?php single_cat_title(); ?></p>
</div>
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</code>
I think it really have to works for posts, but in such case I try to change post for games, try many ways, but don't sucseed yet.
Could anyone tell me what I have change in this code?
i think that promblem in the begining with 'have post' and 'the loop'.
Thanks.
I hope this will help. This is from my WordPress custom post type (loop):
<?php query_posts('post_type=clients&showposts=1000');
if (have_posts()) : while (have_posts()) : the_post();
$nameofclient = get_post_meta($post->ID,'name_of_client',true);
$clientcompany = get_post_meta($post->ID,'company_of_client',true);?>
<div <?php post_class();?> id="ka-<?php the_ID(); ?>">
<h2 class="categorytitle"><?php the_title(); ?></h2>
<?php the_content(); ?><p class="ats_autors">/ <?php if($nameofclient): echo '<span class="client">'.$nameofclient.'</span>'; endif; if($clientcompany): if($nameofclient){echo ', ';} echo '<span class="client-company">'.$clientcompany.'</span>'; endif; ?></p></div><?php endwhile; endif;wp_reset_query();?>
Just found one mistake: in_category('') MUST be filled with category ID in slug. http://codex.wordpress.org/Function_Reference/in_category#Parameters
Correct would be in_category('some-game-cat-slug')
plus worth to read http://new2wp.com/noob/query_posts-wp_query-differences/

Resources