I am trying to use wordpress's commenting system. Their documentation is very confusing and it is kind of a pain to work with. I am trying to use the same commenting system they have on the default twentytwelve theme. It seems to be the way I want it. But even when using the same code they have I do not get a list of previous comment.
This is my comments.php
if ( post_password_required() )
return;
?>
<div id="comments" class="comments-area">
<?php // You can start editing here -- including this comment! ?>
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'dogcompany' ),
number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
?>
</h2>
<ol class="commentlist">
<?php wp_list_comments( array( 'callback' => 'dogcompany_comment', 'style' => 'ol' ) ); ?>
</ol><!-- .commentlist -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
<div id="comment-nav-below" class="navigation" role="navigation">
<h1 class="assistive-text section-heading"><?php _e( 'Comment navigation', 'dogcompany' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'dogcompany' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'dogcompany' ) ); ?></div>
</div>
<?php endif; // check for comment navigation ?>
<?php
/* If there are no comments and comments are closed, let's leave a note.
* But we only want the note on posts and pages that had comments in the first place.
*/
if ( ! comments_open() && get_comments_number() ) : ?>
<p class="nocomments"><?php _e( 'Comments are closed.' , 'dogcompany' ); ?></p>
<?php endif; ?>
<?php endif; // have_comments() ?>
<?php comment_form(); ?>
</div><!-- #comments .comments-area -->
This is function.php
<?php
function dogcompany_setup(){
// Adds RSS feed links to <head> for posts and comments.
add_theme_support( 'automatic-feed-links' );
}
add_action( 'after_setup_theme', 'dogcompany_setup' );
function dogcompany_scripts_styles() {
global $wp_styles;
/*
* Adds JavaScript to pages with the comment form to support
* sites with threaded comments (when in use).
*/
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
$protocol = is_ssl() ? 'https' : 'http';
}
add_action( 'wp_enqueue_scripts', 'dogcompany_scripts_styles' );
/*remove admin bar */
show_admin_bar(false);
if ( ! function_exists( 'dogcompany_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own dogcompany_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* #since Twenty Twelve 1.0
*/
function dogcompany_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
// Display trackbacks differently than normal comments.
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<p><?php _e( 'Pingback:', 'dogcompany' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'dogcompany' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
// Proceed with normal comments.
global $post;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<header class="comment-meta comment-author vcard">
<?php
echo get_avatar( $comment, 44 );
printf( '<cite class="fn">%1$s %2$s</cite>',
get_comment_author_link(),
// If current post author is also comment author, make it known visually.
( $comment->user_id === $post->post_author ) ? '<span> ' . __( 'Post author', 'dogcompany' ) . '</span>' : ''
);
printf( '<time datetime="%2$s">%3$s</time>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s at %2$s', 'dogcompany' ), get_comment_date(), get_comment_time() )
);
?>
</header><!-- .comment-meta -->
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'dogcompany' ); ?></p>
<?php endif; ?>
<section class="comment-content comment">
<?php comment_text(); ?>
<?php edit_comment_link( __( 'Edit', 'dogcompany' ), '<p class="edit-link">', '</p>' ); ?>
</section><!-- .comment-content -->
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'dogcompany' ), 'after' => ' <span>↓</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</article><!-- #comment-## -->
<?php
break;
endswitch; // end comment_type check
}
endif;
if ( ! function_exists( 'dogcompany_entry_meta' ) ) :
/**
* Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
*
* Create your own dogcompany_entry_meta() to override in a child theme.
*
* #since Twenty Twelve 1.0
*/
function dogcompany_entry_meta() {
// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( ', ', 'dogcompany' ) );
// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( '', __( ', ', 'dogcompany' ) );
$date = sprintf( '<time class="entry-date" datetime="%3$s">%4$s</time>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'dogcompany' ), get_the_author() ) ),
get_the_author()
);
// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
if ( $tag_list ) {
$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'dogcompany' );
} elseif ( $categories_list ) {
$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'dogcompany' );
} else {
$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'dogcompany' );
}
printf(
$utility_text,
$categories_list,
$tag_list,
$date,
$author
);
}
endif;
Thank you,
I don't know exactly where you are mistaken. Use new wordpress pack comments.php and functions.php codes. I think it will be solve your problem.
Related
I have a comments section which I am looking to have inline validation. It appears to work when no details are entered in the form fields. But if I enter an email that is not in the correct format (eg. notavalidemail.com) I am redirected to /wp-comments-post.php
How do I prevent this default action and include inline validation. Is this something that can only be done with JS/jQuery and is not a native action?
My comments file includes -
// comments.php
if ( post_password_required() ) {
return;
}
$boilerplate_comment_count = get_comments_number();
?>
<div id="comments" class="comments <?php echo get_option( 'show_avatars' ) ? 'comments__avatars--show' : ''; ?>">
<?php
if ( have_comments() ) :
?>
<h2 class="comments__title">
<?php if ( '1' === $boilerplate_comment_count ) : ?>
<?php esc_html_e( '1 comment', THEME_NAME ); ?>
<?php else : ?>
<?php
printf(
/* translators: %s: Comment count number. */
esc_html( _nx( '%s comment', '%s comments', $boilerplate_comment_count, 'Comments title', THEME_NAME ) ),
esc_html( number_format_i18n( $boilerplate_comment_count ) )
);
?>
<?php endif; ?>
</h2>
<ol class="comments__list">
<?php
$args = array(
'type' => 'comment',
'callback' => 'boilerplate_format_comment'
);
wp_list_comments( $args );
?>
</ol>
<?php
the_comments_pagination(
array(
'before_page_number' => esc_html__( 'Page', THEME_NAME ) . ' ',
'mid_size' => 0,
'prev_text' => sprintf(
'<span class="nav-prev-text">%s</span>',
esc_html__( 'Older comments', THEME_NAME )
),
'next_text' => sprintf(
'<span class="nav-next-text">%s</span>',
esc_html__( 'Newer comments', THEME_NAME ),
),
)
);
?>
<?php if ( ! comments_open() ) : ?>
<p class="comments__none"><?php esc_html_e( 'Comments are closed.', THEME_NAME ); ?></p>
<?php endif; ?>
<?php endif; ?>
<?php
comment_form(
array(
'logged_in_as' => null,
'title_reply' => esc_html__( 'Leave a comment', 'twentytwentyone' ),
'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</h2>',
)
);
?>
</div>
The comments are being formatted by:
function boilerplate_format_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li id="li-comment-<?php comment_ID() ?>" <?php comment_class(); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comments__item">
<div class="comments__item--media">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, '160' ); ?>
</div>
<div class="comments__item--content">
<div class="comments__item--title">
<?php
/* translators: %s: comment author link */
printf( __('<h3>%s</h3>'), get_comment_author_link( $comment ) );
?>
<div class="comments__item--date">
<time datetime="<?php comment_time( 'c' ) ?>">
<?php
/* translators: 1: comment time, 2: comment date */
printf( __( 'Posted at %1$s, %2$s' ), get_comment_time(), get_comment_date( 'd F', $comment ) );
?>
</time>
</div>
</div>
<div class="comments__item--comment">
<?php comment_text(); ?>
</div>
<?php if ( '0' == $comment->comment_approved ) : ?>
<div class="comments__moderation--await">
<p><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
</div>
<?php endif; ?>
<div class="comments__item--conversation">
<?php
if (get_comment_type() == 'comment') {
comment_reply_link( array_merge( $args, array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '<div class="comments__item--reply">',
'after' => '</div>'
) ) );
}
?>
<?php edit_comment_link( __( 'Edit' ), '<div class="comments__item--edit">', '</div>' ); ?>
</div>
</div>
</article>
<?php }
Is there something that I am missing out that is native to WP or can this type of action only be perform by JS? I see that comment_form() has the action argument that defaults to /wp-comments-post.php. DO I need to make changes here?
I am green in wordpress.
I have create a widget call woocommerce-dropdown-cart.php and placed in the same folder with the theme I am using. But why I cant find this widget in my Appereance-->widget?
On the other hands, my menu bar have not any widget, how can I add this widget into or just before the menu bar?
Many thanks!
Here is my php code:
<?php class Woocommerce_Dropdown_Cart extends WP_Widget {
public function __construct() {
parent::__construct(
'woocommerce-dropdown-cart', // Base ID
'Woocommerce Dropdown Cart', // Name
array( 'description' => __( 'Woocommerce Dropdown Cart', 'jeffho' ), ) // Args
);
}
public function widget( $args, $instance ) {
global $post;
extract( $args );
echo $before_widget;
global $woocommerce;
global $qode_options_proya;
$cart_holder_class = 'header_cart';
if (isset($qode_options_proya['woo_cart_type'])){
$cart_type = $qode_options_proya['woo_cart_type'];
switch ($cart_type) {
case 'font-elegant':
$cart_holder_class = "header_cart cart_icon";
break;
default:
$cart_holder_class = "header_cart";
break;
}
}
?>
<div class="shopping_cart_outer">
<div class="shopping_cart_inner">
<div class="shopping_cart_header">
<a class="<?php echo esc_attr($cart_holder_class);?>" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"><span class="header_cart_span"><?php echo $woocommerce->cart->cart_contents_count; ?></span></a>
<div class="shopping_cart_dropdown">
<div class="shopping_cart_dropdown_inner">
<?php
$cart_is_empty = sizeof( $woocommerce->cart->get_cart() ) <= 0;
$list_class = array( 'cart_list', 'product_list_widget' );
?>
<ul class="<?php echo implode(' ', $list_class); ?>">
<?php if ( !$cart_is_empty ) : ?>
<?php foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) :
$_product = $cart_item['data'];
// Only display if allowed
if ( ! $_product->exists() || $cart_item['quantity'] == 0 ) {
continue;
}
// Get price
$product_price = get_option( 'woocommerce_tax_display_cart' ) == 'excl' ? $_product->get_price_excluding_tax() : $_product->get_price_including_tax();
$product_price = apply_filters( 'woocommerce_cart_item_price_html', woocommerce_price( $product_price ), $cart_item, $cart_item_key );
?>
<li>
<a itemprop="url" href="<?php echo get_permalink( $cart_item['product_id'] ); ?>">
<?php echo $_product->get_image(); ?>
<?php echo apply_filters('woocommerce_widget_cart_product_title', $_product->get_title(), $_product ); ?>
</a>
<?php echo $woocommerce->cart->get_item_data( $cart_item ); ?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
</li>
<?php endforeach; ?>
<?php else : ?>
<li><?php _e( 'No products in the cart.', 'woocommerce' ); ?></li>
<?php endif; ?>
</ul>
</div>
<?php if ( sizeof( $woocommerce->cart->get_cart() ) <= 0 ) : ?>
<?php endif; ?>
<a itemprop="url" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" class="qbutton white view-cart"><?php _e( 'Cart', 'woocommerce' ); ?> <i class="fa fa-shopping-cart"></i></a>
<span class="total"><?php _e( 'Total', 'woocommerce' ); ?>:<span><?php echo $woocommerce->cart->get_cart_subtotal(); ?></span></span>
<?php if ( sizeof( $woocommerce->cart->get_cart() ) <= 0 ) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
echo $after_widget;
}
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
}
add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Dropdown_Cart" );' ) );
?>
<?php
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<span class="header_cart_span"><?php echo $woocommerce->cart->cart_contents_count; ?></span>
<?php
$fragments['span.header_cart_span'] = ob_get_clean();
return $fragments;
}
?>
I am using theme called "Creativo 5.0" and I have added:
register_sidebar( array(
'name' => __( 'Header Sidebar', 'Creativo' ),
'id' => 'header-sidebar',
'before_widget' => '<div class="header _widget_content">',
'after_widget' => '</div>',
'before_title' => '<h2 class="header-widget-title">',
'after_title' => '</h2>',
) );
into function creativo_widgets_init()
what I want is to add the php widget into the menu bar.
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 want to only display comments on one of the categories on my wordpress site. So for example my pear category with posts on it will have a comment function available but on my orange page the comment section will be disabled.
Any suggestions?
In the content.php file change:
<?php if ( comments_open() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open() ?>
to
<?php
$postid = get_the_ID();
$category = get_the_category( $postid );
$category = $category[0]->cat_name;
if ($category == "Pear")
{
if ( comments_open() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open()
}
?>
and in the comments.php file change:
<?php if ( have_comments() ) : ?>
to
<?php
$postid = get_the_ID();
$category = get_the_category( $postid );
$category = $category[0]->cat_name;
if ($category == "Pear")
{
if ( have_comments() ) :
?>
AND change:
<?php endif; // have_comments() ?>
<?php comment_form(); ?>
to
<?php endif; // have_comments() ?>
<?php comment_form();
}
?>
The above should only display comments in posts that are in the Pear category.
I want to pull the 5 most recent podcasts from an iTunes feed and post them along with their audio to a WP page.
The code I have is below
its pulling the feed and displaying the name, details, etc fine but its using the same podcast audio for each item.
<div class="podcastfeed">
<h4>Recent Podcasts</h4>
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
$feed = fetch_feed( $hpFeed );
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item)
{
if ($enclosure = $item->get_enclosure())
{
$enclosure->get_link();
}
}
if ( ! is_wp_error( $feed ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $feed->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$feed_items = $feed->get_items( 0, $maxitems );
endif;
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<ol>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $feed_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span><?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?></span>
</p>
</a>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>
I got it working in the end though it took some fiddling with
The page is now displaying each of the podcasts as audio.
<div class="podcastfeed">
<?php // Get $feed Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$hpFeed=get_post_meta($post->ID, "cmb_hp_feed", true);
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( $hpFeed );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<?php if ( $maxitems == 0 ) : ?>
<ol style="display:none;"><?php _e( 'No items', 'my-text-domain' ); ?></ol>
<?php else : ?>
<h4>Recent Podcasts</h4>
<ol>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>">
<p>
<span>
<?php echo esc_html( $item->get_title() ); ?>
</span>
<span>
<?php printf( __( '%s', 'my-text-domain' ), $item->get_date('F j, Y') ); ?>
</span>
</p>
</a>
<?php
if ($enclosure = $item->get_enclosure()){
$enclosure->get_link();
}
?>
<?php
$attr = array(
'src' => $enclosure->get_link(),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
?>
<?php echo wp_audio_shortcode( $attr );?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ol>
</div>