I'm creating a simple theme using Twitter's Bootstrap. I am only using wordpress for the blog portion of my website (http://www.mattaltepeter.com/n3). In my single.php file i use to pull in the comments template. Ultimately I would like to use Jetpack comments, but just trying to use the default wordpress one currently. I have created a test post and added a couple comments to it, but the comments do not show up on the post. I switched my theme to twenty-eleven and they did, so it has to be something with my theme. I think the issue is with my comments.php. I'm not entirely sure what to put in there to make it work. I started working on this awhile ago and cannot remember where I got the code that currently resides in comments.php. I tried to copy and paste the code from the twenty-eleven comments.php, but that didn't work either. Do I need to write custom code for this or what?
Thanks for the help!
Matt
Try using this. This is what I use to call comments.
In functions.php:
function custom_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
$GLOBALS['comment_depth'] = $depth;
?>
<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
<div class="comment-author vcard"><?php commenter_link() ?></div>
<div class="comment-meta"><?php printf(__('Posted %1$s at %2$s <span class="meta-sep">|</span> Permalink', 'your-theme'),
get_comment_date(),
get_comment_time(),
'#comment-' . get_comment_ID() );
edit_comment_link(__('Edit', 'your-theme'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'your-theme') ?>
<div class="comment-content">
<?php comment_text() ?>
</div>
<?php // echo the comment reply link
if($args['type'] == 'all' || get_comment_type() == 'comment') :
comment_reply_link(array_merge($args, array(
'reply_text' => __('Reply','your-theme'),
'login_text' => __('Log in to reply.','your-theme'),
'depth' => $depth,
'before' => '<div class="comment-reply-link">',
'after' => '</div>'
)));
endif;
?>
<?php } // end custom_comments
In your post, within the loop:
<?php if ( ('open' == $post->comment_status) && ('open' == $post->ping_status) ) : // Comments and trackbacks open ?>
<?php printf( __( '<a class="comment-link" href="#respond" title="Post a comment">Post a comment</a> or leave a trackback: <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback URL</a>.', 'your-theme' ), get_trackback_url() ) ?>
<?php elseif ( !('open' == $post->comment_status) && ('open' == $post->ping_status) ) : // Only trackbacks open ?>
<?php printf( __( 'Comments are closed, but you can leave a trackback: <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback URL</a>.', 'your-theme' ), get_trackback_url() ) ?>
<?php elseif ( ('open' == $post->comment_status) && !('open' == $post->ping_status) ) : // Only comments open ?>
<?php _e( 'Trackbacks are closed, but you can <a class="comment-link" href="#respond" title="Post a comment">post a comment</a>.', 'your-theme' ) ?>
<?php elseif ( !('open' == $post->comment_status) && !('open' == $post->ping_status) ) : // Comments and trackbacks closed ?>
<?php _e( 'Both comments and trackbacks are currently closed.', 'your-theme' ) ?>
<?php comments_template('', true); ?>
Related
I have an index.php page where I have added the following code to display different content based on the page loaded:
if( is_page( 'my-account' ) ) {
get_template_part( 'template-parts/my-account', 'account' );
} else if( is_home() || is_front_page() ) {
get_template_part( 'template-parts/album-grid', 'index' );
} else if( is_page( 'create-album') ) {
get_template_part( 'template-parts/create-album', 'create-album' );
}
In album-grid.php I am using a WP_Query and a pagination. The pagination displays OK. When I click on Next link, it takes me to http://albumlocal.com/page/2 but does not does not show up anything. I am expecting to see the next set of records here.
Here is my code on album-grid.php file:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts = new WP_Query( array(
'taxonomy' => 'album-category',
'post_type' => array('albums'),
'posts_per_page' => 10,
'paged' => $paged,
)
);
if( $posts->have_posts() ) { ?>
<div class="grid-table" xmlns="http://www.w3.org/1999/html">
<?php
while ( $posts->have_posts() ) :$posts->the_post(); ?>
<a class="grid-anchor" href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<div class="grid-col">
<h3><?php the_title(); ?></h3>
<div class="grid-thumbnail">
<?php the_post_thumbnail('home_grid_thumbnail'); ?>
</div>
<div class="grid-action">
<i class="fa fa-camera"></i> Photos
</div>
</div>
</a>
<?php
endwhile;
wp_reset_query(); ?>
</div>
<?php } ?>
<div class="clear"></div>
<?php echo paginate_links( array(
'total' => $posts->max_num_pages,
'mid_size' => 2,
'format' => 'page/%#%'
)); ?>
I think when I am on second or any sub page (e.g. http://albumlocal.com/page/2) is_home() or is_front_page() is no longer been satisfied and hence it is not loading the required template part album-grid.php any more.
if( is_home() || is_front_page() ) {
get_template_part( 'template-parts/album-grid', 'index' );
}
I am not sure if this the case, but if so, I don't know how to make it to work.
Try to create in your theme folder :
home.php for the Grid
page template page.create-album.php with inside
<?php //Template Name: Create Album
//Here all the html and php
page template page.my-account.php with inside
<?php //Template Name: My Account
//Here all the html and php
Everything will me automatically done, and you will no longer need :
if( is_page( 'my-account' ) ) {
get_template_part( 'template-parts/my-account', 'account' );
} else if( is_home() || is_front_page() ) {
get_template_part( 'template-parts/album-grid', 'index' );
} else if( is_page( 'create-album') ) {
get_template_part( 'template-parts/create-album', 'create-album' );
}
I dont' know if it will fix the problem for you but, it will be cleaner i think, and i already have done pagination on the home.php this way without any problems.
Just try, and if it's not working we will find another way :)
I'm trying to learn to use wordpress.
I'm trying to change comments layout and I want to join comment date to comment author data. But I am not getting it. For example, I have what is in first image but I want what it is in second. Can you help please? Thanks so much!
I think your main problem is that you want to customize the way the date is placed using only css but that's extremely hard.
The best thing for you to do is have your own custom comment code.
Wordpress let's you have your own comments code.
For example when you call the comment template code instead of doing this:
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 42,
) );
You can do something like this:
<ol class="commentlist">
<?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?>
</ol>
And on the function.php file you can add the mytheme_comment function with the original comment code that wp has and reaarrange the classes and html code placement so you can have the date where you want.
function mytheme_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
?>
</div>
<?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
In the default code you can see that the code:
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() );
?>
is what gives you the date information.
Hope you understanded this.
Here's the original WP documentation about this:
wp list comments
I'm working on a wordpress theme. I can't figure out a (probably simple) issue! The code below does something with post-data. I want this code to work on 2 template files. It works on home.php, but i nee it to work on blog.php as well. I tried:
<?php if ( !is_page_template('templates/home.php') ) || ( !is_page_template('templates/blog.php') ) { ?>
But that didn't work. How do I fix this? Any thoughts? Thanks! :)
<ul class="post-meta clr">
<li class="meta-date">
<?php _e('Posted on','wpex'); ?>
<span class="meta-date-text"><?php echo get_the_date(); ?></span>
</li>
<?php if ( !is_page_template('templates/home.php') ) { ?>
<?php if(isset($fist_category)){ ?>
<li class="meta-category">
<span class="meta-seperator">/</span><?php _e('Under','wpex'); ?>
<?php echo $category_name; ?>
</li>
<?php } ?>
<?php if( comments_open( $post_id ) ) { ?>
<li class="meta-comments comment-scroll">
<span class="meta-seperator">/</span><?php _e('With','wpex'); ?>
<?php comments_popup_link( __( '0 Comments', 'wpex' ), __( '1 Comment', 'wpex' ), __( '% Comments', 'wpex' ), 'comments-link' ); ?>
</li>
<?php } ?>
<?php } ?>
</ul>
In the code you've tried your if statement will always be true.
The original version will execute the code if the user is not viewing a page that uses the templates/home.php page template.
In your modified version it will execute the code if the current page is not using templates/home.php or it's not using templates/blog.php. The only way that code won't fire is if the current page template is both home.php and blog.php which isn't possible.
Instead you need to use:
if ( ! ( is_page_template( 'templates/home.php' ) || is_page_template( 'templates/blog.php' ) ) ) {
// code here.
Or:
if ( ! is_page_template( 'templates/home.php' ) && ! is_page_template( 'templates/blog.php' ) ) {
// code here.
I am using custom code to print the comments but the problem is whatever i do, i cant print the comment reply link under any comment....
here is the code
<?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
}
/* This variable is for alternating comment background */
/*$oddcomment = 'class="alt" ';*/
$oddcomment = 'alt';
?>
<!-- You can start editing here. -->
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<!--<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">-->
<li class="<?php echo $oddcomment; ?> <?php if ($comment->comment_author_email == get_the_author_email()) { echo 'author_comment'; } ?>" id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?> <?php edit_comment_link('edit',' ',''); ?>
</small>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
?>
</div>
</li>
<?php
/* Changes every other comment to a different class */
/*$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';*/
$oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
But when i use wp_list_comments functions i can see the reply link appear automatically i am using wordpress 3.2.1
It can be helpful to read the source for comment_reply_link (http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061), as there are multiple conditions that can lead to the link not appearing. Work through each one at a time, and you'll likely find your answer.
The one that tripped me up, is that the link will not appear if comments are closed. So it can be helpful to review the comment settings on the blog to make sure that providing replies is actually allowed on this post.
Try this:
comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'])))
Thanks to the following codex-entry (http://codex.wordpress.org/Function_Reference/comment_reply_link), I managed to find the actual use of the comment_reply_link() on the following link: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061
This leaves me with the following question - did you try adding either the second or the third parameter for the function? I think there might be something fishy going on under the hood, making the comment-link not know where to actually link.
Try removing the following snippet
comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
and instead use the following one
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );
Let me know if it works out for you!
Enable nested comments in Admin > Settings > Discussion:
Enable threaded (nested) comments levels deep
I've searched this question a lot, but all I find is answers of how to show every category for a specific taxonomy.
I'm developing a theme, and I'm going to filter a list of posts (custom post type 'jobs') using jQuery, but I need to have a <div> with a class showing the categories of that specific post.
I'm going to filter these on the category page (jobs).
For this to work, I'm putting all my code in the loop.php.
<div class="post_entry">
<div class="post-thumb"><?php the_post_thumbnail('single-post-thumbnail'); ?></div>
<h4 class="post-title"><?php the_title(); ?></h4>
<?php
$location = get_post_meta($post->ID, 'location', TRUE);
$organization = get_post_meta($post->ID, 'organization', TRUE);
$url = get_post_meta($post->ID, 'url', TRUE);
?>
<div class="post-meta">
<?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
<?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
<?php if($url != ''){ ?><p class="post_meta_url">Website: Click Here</p><?php } ?>
</div>
<div class="hidden tags">
</div>
<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
<p class="post_excerpt"><?php the_excerpt(); ?></p>
<?php else : ?>
<div class="category_read_more"><?php the_content( __( 'Read More', 'twentyten' ) ); ?></div>
<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
<?php endif; ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
<?php comments_template( '', true ); ?>
</div>
I've been lucky to add meta-box information, but I want to show the posts custom categories (jobtype) in <div class="hidden tags"></div>
To take a look at the website, check out http://www.cirkut.net/wp/libertyguide/jobs
If anyone could help, that would be fantastic! If any more information is needed, let me know.
In the loop:
Category: <?php echo get_the_category_list(', '); ?>
Update:
Wordpress writes:
Listing the terms
If you want to have a custom list in your theme, then you can pass the
taxonomy name into the the_terms() function in the Loop, like so:
the_terms( $post->ID, 'people', 'People: ', ', ', ' ' );
This should address your problem.
http://codex.wordpress.org/Taxonomies#Listing_the_terms