This is my first foray into customizing the WP comment form, and it's giving me a bit of trouble.
Ideally, I'd like to have a comment form with 3 fields: Name, Location, and Comment.
To facilitate that, I'm using arrays:
<?php comment_form(array(
'title_reply'=> 'Please feel free to share your home owning hopes and dreams.',
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'label_submit' => 'Share',
));
?>
In the comment list, I want the comment to display and just below that have "Name | Location"
<div class="comment-content"><?php comment_text(); ?><?php comment_author(); ?> | <?php echo $comment_author_url ?> </div>
As you can see on the live site, it isn't quite coming out that way. Any ideas why that may be? Tips and insight are appreciated.
functions.php
<?php
if ( ! function_exists( 'twentyeleven_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own twentyeleven_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* #since Twenty Eleven 1.0
*/
function twentyeleven_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<div class="comment-content"><?php comment_text(); ?><?php comment_author(); ?> | <?php echo $comment_author_url ?> </div>
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // ends check for twentyeleven_comment()
// Custom callback to list comments in the your-theme style
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
// Custom callback to list pings
function custom_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
<div class="comment-author"><?php printf(__('By %1$s on %2$s at %3$s', 'your-theme'),
get_comment_author_link(),
get_comment_date(),
get_comment_time() );
?></div>
<?php if ($comment->comment_approved == '0') _e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'your-theme') ?>
<div class="comment-content">
<?php comment_text() ?>
</div>
<?php } // end custom_pings
// Produces an avatar image with the hCard-compliant photo class
function commenter_link() {
$commenter = get_comment_author_link();
if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
$commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
} else {
$commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
}
$avatar_email = get_comment_author_email();
$avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, 80 ) );
echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
} // end commenter_link
if (!function_exists('iweb_reverse_comments')) {
function iweb_reverse_comments($comments) {
return array_reverse($comments);
}
}
add_filter ('comments_array', 'iweb_reverse_comments');
// custom comment field
function my_fields($fields) {
$fields['Location'] = '';
return $fields;
}
add_filter('comment_form_default_fields','my_fields');
?>
share.php
<?php
/*
Template Name: Share
*/
?>
<?php get_header(); ?>
<div class="content-left">
<?php comments_template(); ?>
</div><!-- end content-left -->
<div class="content-right">
<?php wp_list_comments( array( 'callback' => 'twentyeleven_comment' )); ?></ul>
</div><!-- end content-right -->
<?php get_footer(); ?>
i don't think it's twentyeleven_comment that you have to edit.
try an echo in the twentyeleven_comment to see if it's the right function.
echo "twentyeleven_comment ";
exit;
i think twentyeleven_comment show all comments of a post in the post view not the post list.
Related
I've been trying to split posts for a long time. I tried a variety of variations, but every time I post a single post or copy me all double.
I mean multiple posts.
If anyone has an idea how to fix it I will be very grateful to him.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'esteem_before_post_content' ); ?>
<?php
if( has_post_thumbnail() ) {
$image = '';
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'blog-large');
$title_attribute = the_title_attribute( 'echo=0' );
$image .= '<figure class="post-featured-image">';
$image .= '<a href="' . get_permalink() . '" title="'.the_title_attribute( 'echo=0' ).'">';
$image .= get_the_post_thumbnail( $post->ID, 'blog-large', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ) ) ).'</a>';
$image .= '<div class="mask">
<div class="image-icon-wrap">
<i class="icon-search"></i>
<i class="icon-link"></i>
</div>
</div>';
$image .= '</figure>';
echo $image;
}
?>
<div class="blog-content">
<header class="entry-header">
<h2 class="entry-title">
<?php the_title(); ?>
</h2><!-- .entry-title -->
</header>
<?php esteem_entry_meta(); ?>
<div class="entry-content clearfix">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</div>
<?php do_action( 'esteem_after_post_content' ); ?>
</article>
Post loop
<div id="primary">
<div id="content" class="clearfix">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php get_template_part( 'navigation', 'none' ); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
If anyone has an idea how to fix it I will be very grateful to him.
Since you are already calling post_class() function, you need to pass alternate class to that function itself and make sure to do this only on your custom page or selected blog page. The code will essentially be something like:
global $current_class;
$current_class = 'odd';
function alternating_post_class ( $classes ) {
global $current_class;
if( is_page(<PAGE_ID_HERE>) || is_home() ):
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
endif;
return $classes;
}
add_filter ('post_class', 'alternating_post_class');
This should resolve the problem by giving you odd/even class which you can use to style your two columns.
Cheers Mate!!!
I have http://spainthephilippines.com/ where I use Rift Theme. Im having problem with showing the sidebar on single post page. On my index page the sidebar is showing, on the 404 page the sidebar is showing. It is working anywhere I use it just not in signle post page. I was looking 2 hours for answer but I cant find it. The theme is on version 1.0, so is it possible that to be the problem? Then why the sidebar shows on most pages? Anyone can help? Tell me if you need any code.
<?php global $theme; get_header(); ?>
<div id="main">
<?php $theme->hook('main_before'); ?>
<div id="content">
<?php $theme->hook('content_before'); ?>
<?php
if (have_posts()) : while (have_posts()) : the_post();
/**
* Find the post formatting for the single post (full post view) in the post-single.php file
*/
get_template_part('post', 'single');
endwhile;
else :
get_template_part('post', 'noresults');
endif;
?>
<?php $theme->hook('content_after'); ?>
</div><!-- #content -->
<?php get_sidebars(); ?>
<?php $theme->hook('main_after'); ?>
</div><!-- #main -->
EDIT
Here is the sidebar:
<?php global $theme; ?>
<div id="sidebar-primary">
<?php
if(!dynamic_sidebar('sidebar_primary')) {
/**
* The primary sidebar widget area. Manage the widgets from: wp-admin -> Appearance -> Widgets
*/
$theme->hook('sidebar_primary');
}
$theme->hook("sidebar_primary_after");
?>
And also the post-single.php:
<?php global $theme; ?>
<div <?php post_class('post post-single clearfix'); ?> id="post-<?php the_ID(); ?>">
<h2 class="title"><?php the_title(); ?></h2>
<div class="postmeta-primary">
<span class="meta_date"><?php echo get_the_date(); ?></span>
<span class="meta_categories"><?php the_category(', '); ?></span>
<?php if(comments_open( get_the_ID() )) {
?> <span class="meta_comments"><?php comments_popup_link( __( 'No comments', 'themater' ), __( '1 Comment', 'themater' ), __( '% Comments', 'themater' ) ); ?></span><?php
}
if(is_user_logged_in()) {
?> <span class="meta_edit"><?php edit_post_link(); ?></span><?php
} ?>
</div>
<div class="entry clearfix">
<?php
if(has_post_thumbnail()) {
the_post_thumbnail(
array($theme->get_option('featured_image_width_single'), $theme->get_option('featured_image_height_single')),
array("class" => $theme->get_option('featured_image_position_single') . " featured_image")
);
}
?>
<?php
the_content('');
wp_link_pages( array( 'before' => '<p><strong>' . __( 'Pages:', 'themater' ) . '</strong>', 'after' => '</p>' ) );
?>
<?php if(get_the_tags()) {
?><div class="postmeta-secondary"><span class="meta_tags"><?php the_tags('', ', ', ''); ?></span></div><?php
}
?>
<!-- Post ID <?php the_ID(); ?> wtf-->
<?php
if(comments_open( get_the_ID() )) {
comments_template('', true);
}
?>
I've seen various sites using the built in wordpress comment system with a custom callback (to generate their own html different than that if the built in comments in wordpress) adding numbers to comments on their site.
Ala - http://mobile.smashingmagazine.com/2013/08/12/creating-high-performance-mobile-websites/
Each comment has a number beside it.
After doing a whole lot of searching I can't find any built in function of wordpress that does this.
I'm using a custom calllback for my comments.
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
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">
<div class="rounded">
<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
</div> <!-- end div rounded -->
</div> <!-- end div vcard -->
<div class="comment-meta commentmetadata">
<?php printf(__('<cite class="fn">%s</cite> <span class="says"></span>'), get_comment_author_link()) ?>
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
<?php
printf( __('%1$s at %2$s'), comment_time('F j, Y g:i a')) ?></a><?php edit_comment_link(__('(Edit)'),' ','' );
?>
</a>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation">
<?php _e('Your comment is awaiting moderation.') ?>
</em>
<br />
<?php endif; ?>
</div> <!-- end div commentmetadata -->
<div class="commentsholder">
<?php comment_text() ?>
</div> <!-- end div commentsholder -->
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div> <!-- end div reply -->
<?php echo '<div style="clear:both"></div>' ?>
<?php if ( 'div' != $args['style'] ) : ?>
</div> <!-- end div commentid -->
<?php endif; ?>
<?php
}
Can anyone give me any idea how to number each comment?
Look at the twentytwelve theme. It uses an ordered list.
<ol class="commentlist">
<?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>
</ol><!-- .commentlist -->
In the functions.php twentytwelve_comment function the comments are wrapped in a <li></li>.
If your comments are on multiple pages or you want to style the numbers you could use a plugin like http://wordpress.org/plugins/gregs-threaded-comment-numbering/. Read here how to use it.
I was exploring Alexander Kuzmin idea and I think that's how Smashing Magazine is numbering their comments.
It's done in a linear fashion without caring if the comment is threaded or not.
I tested in TwentyEleven, and manipulated the callback for wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) );.
In functions.php:
$countcomm = 1;
function twentyeleven_comment( $comment, $args, $depth )
{
global $countcomm;
// PRINT THE COMMENTS AND USE $countcomm TO ECHO THE NEW "COMMENT ID"
// TAKING CARE OF THE COMMENT PERMALINK:
// CHANGE ALL INSTANCES OF comment_ID() AND $comment->comment_ID
// TO $countcomm
$countcomm++;
}
is there a way to just search
pages
Custom Types
Posts
I am currently modifying the twenty eleven theme.
here is the Code for search.php:
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for "%s"', 'twentyeleven' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
<div class="SearchCount"><?php /* Search Count */
$allsearch = &new WP_Query("s=$s&showposts=-1");
//$key = wp_specialchars($s, 1);
$count = $allsearch->post_count; _e(''); _e();
echo $key; _e(); _e();
echo $count . ' '; _e('');
wp_reset_query(); ?> Saved Results </div>
<div id="topPagination"><?php twentyeleven_child_content_nav( 'nav-above' ); ?></div>
</header>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', 'search' );
?>
<?php endwhile; ?>
<?php twentyeleven_child_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
And here is the content-search.php
<h2><a href="<?php the_permalink();?>">
<?php $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $title); ?>
<?php echo $title; ?>
</a><br />
<span class="categoryClass"><?php the_category(','); ?></span></h2>
<?php the_excerpt(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
Thank you
The way I see it you have two options. One is to modify wp_query to only return the type that you want. The second is search on everything, but filter the results afterwards.
This is how I believe you would modify wp_query by using Type Parameters
$allsearch = &new WP_Query("s=$s&showposts=-1"); //what you currently have
$customsearch = &new WP_Query("post_type=page&posts_per_page =5");
This is how I believe you would filter post search
if ( have_posts() ) : while ( have_posts() ) : the_post();
if (is_page()) {} //do something if page
endwhile;
http://codex.wordpress.org/Creating_a_Search_Page
How to separate comments and pingbacks to the Twenty Ten theme? (default wordpress theme)
According to the functions.php
function twentyten_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar( $comment, 40 ); ?>
<?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
?>
</div><!-- .comment-meta .commentmetadata -->
<div class="comment-body"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</div><!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif;
I was google and have tons results, but all in old version. Let me know if can be done.
It depends on the version of wordpress you are using, not on the theme.
Maybe this is helpful: http://themocracy.com/2010/02/separate-pingbacks-user-comments/