I want to add my printerfriendly button to all of my posts under my header. this is the HTML of the button:
<script>var pfHeaderImgUrl = '';var pfHeaderTagline = '';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = 'right';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = '';var pfBtVersion='1';(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/>
</a>
As for now, the example I placed in the HTML printerfriendly code that was generated in my side bar that you can see here :
http://iamdentistry.com/archive/dentistry/about-dental-night-guards/
I do not know how to move this button to where I want. I want to place it in the same line as the Leave A Response button under the posts header to the far right.
I asked the author of the theme and all they told me was that I need to add the code to the content.php file of my theme which is this :
<article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
<?php if ( is_singular( get_post_type() ) ) : ?>
<?php
$format = get_post_format();
get_template_part( 'post-header', $format );
?>
<header class="entry-header">
<?php if (
fearless_get_option( 'singular_featured_image_enabled' )
&& 'audio' != $format
&& 'gallery' != $format
&& 'video' != $format
) {
fearless_post_thumbnail();
}
?>
<h1 class="entry-title"><?php single_post_title(); ?></h1>
<?php
printf(
apply_atomic_shortcode(
'entry_byline',
'<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . '</div>'
),
sprintf(
_n(
'1 View',
'%1$s Views',
get_post_meta( get_the_ID(), 'Views', true ),
'fearless'
),
get_post_meta( get_the_ID(), 'Views', true )
)
);
?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php if ( is_singular( 'post' ) ) get_template_part( 'review-box' ); ?>
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms before="Posted in " taxonomy="category"] [entry-terms before="| Tagged "]', 'fearless' ) . '</div>' ); ?>
</footer><!-- .entry-footer -->
<?php else : ?>
<?php global $fearless_blogroll_layout; ?>
<?php fearless_post_thumbnail( $fearless_blogroll_layout['thumbnail_size'] ); ?>
<header class="entry-header">
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
<?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '</div>' ); ?>
</header><!-- .entry-header -->
<?php if ( $fearless_blogroll_layout['excerpt_length'] ) : ?>
<div class="entry-summary">
<?php echo fearless_get_the_excerpt( $fearless_blogroll_layout['excerpt_length'] ); ?>
<?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
</div><!-- .entry-summary -->
<?php endif; ?>
<?php if ( '1col-thumb' != $fearless_blogroll_layout['style'] ) : ?>
<p class="more-link-wrapper"><?php _e( 'Read More »', 'fearless' ); ?></p>
<?php endif; ?>
<?php endif; ?>
</article><!-- .hentry -->
----- Dave this is how I attempted what you asked :
<?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '<script>var pfHeaderImgUrl = '';var pfHeaderTagline = '';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = 'right';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = '';var pfBtVersion='1';(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/></div>' );
?>
---------------Christopher Pecoraro , this was my attempt:
<article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
<?php if ( is_singular( get_post_type() ) ) : ?>
<?php
$format = get_post_format();
get_template_part( 'post-header', $format );
?>
<header class="entry-header">
<?php if (
fearless_get_option( 'singular_featured_image_enabled' )
&& 'audio' != $format
&& 'gallery' != $format
&& 'video' != $format
) {
fearless_post_thumbnail();
}
?>
<h1 class="entry-title"><?php single_post_title(); ?></h1>
$link_text = '<script>var pfHeaderImgUrl = \'\';var pfHeaderTagline = \'\';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = \'right\';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = \'\';var pfBtVersion=\'1\';(function(){var js, pf;pf = document.createElement(\'script\');pf.type = \'text/javascript\';if(\'https:\' == document.location.protocol){js=\'https://pf-cdn.printfriendly.com/ssl/main.js\'}else{js=\'http://cdn.printfriendly.com/printfriendly.js\'}pf.src=js;document.getElementsByTagName(\'head\')[0].appendChild(pf)})();</script><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/>';
printf(
apply_atomic_shortcode(
'entry_byline',
'<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . $link_text . '</div>'
),
sprintf(
_n(
'1 View',
'%1$s Views',
get_post_meta( get_the_ID(), 'Views', true ),
'fearless'
),
get_post_meta( get_the_ID(), 'Views', true )
)
);
?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php if ( is_singular( 'post' ) ) get_template_part( 'review-box' ); ?>
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms before="Posted in " taxonomy="category"] [entry-terms before="| Tagged "]', 'fearless' ) . '</div>' ); ?>
</footer><!-- .entry-footer -->
<?php else : ?>
<?php global $fearless_blogroll_layout; ?>
<?php fearless_post_thumbnail( $fearless_blogroll_layout['thumbnail_size'] ); ?>
<header class="entry-header">
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
<?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '</div>' ); ?>
</header><!-- .entry-header -->
<?php if ( $fearless_blogroll_layout['excerpt_length'] ) : ?>
<div class="entry-summary">
<?php echo fearless_get_the_excerpt( $fearless_blogroll_layout['excerpt_length'] ); ?>
<?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
</div><!-- .entry-summary -->
<?php endif; ?>
<?php if ( '1col-thumb' != $fearless_blogroll_layout['style'] ) : ?>
<p class="more-link-wrapper"><?php _e( 'Read More »', 'fearless' ); ?></p>
<?php endif; ?>
<?php endif; ?>
</article><!-- .hentry -->
Place your code where it says [YOUR CODE HERE]. If you want to be lazy, just put it right in there. Note that it is VERY IMPORTANT that you escape the single quotes in the code by putting a \ in front of them
<?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '[YOUR CODE HERE]</div>' ); ?>
You might want to do escape the single quotes this way:
$str = [YOUR CODE];
string addslashes ( string $str );
Then place $str in the code like ...'fearless' ) . $str . '</div>'
You could also just replace all the single quotes with double quotes.
Could you try something like this (not elegant at all)?
replace:
<?php
printf(
apply_atomic_shortcode(
'entry_byline',
'<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . '</div>'
),
with:
$link_text = '<script>var pfHeaderImgUrl = \'\';var pfHeaderTagline = \'\';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = \'right\';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = \'\';var pfBtVersion=\'1\';(function(){var js, pf;pf = document.createElement(\'script\');pf.type = \'text/javascript\';if(\'https:\' == document.location.protocol){js=\'https://pf-cdn.printfriendly.com/ssl/main.js\'}else{js=\'http://cdn.printfriendly.com/printfriendly.js\'}pf.src=js;document.getElementsByTagName(\'head\')[0].appendChild(pf)})();</script><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/>';
printf(
apply_atomic_shortcode(
'entry_byline',
'<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . $link_text . '</div>'
),
Related
I actually struggling with problem on this URL: Problematic URL
The problem can be described like this:
Page on that URL was set as main blog page in WordPress settings, but the page does not output list of posts, it just only outputs name of page "Herní články" and button read more (číst více) links to this page.. article id="post - id" showing classes "page type-page" and I really don't know how to resolve this problem..
The archive.php code is here:
<?php get_header(); ?>
<?php
$title_style = 'margin-bottom: 50px;';
$blog_content_style = 'margin-bottom: 30px;';
?>
<div id="primary" class="blog-content-area archive" style="<?php echo esc_attr($blog_content_style); ?>">
<?php
$title_color = (!empty($tdl_options['tdl_blog_title_color_scheme'])) ? $tdl_options['tdl_blog_title_color_scheme'] : 'mta-light';
$default_image_header = "";
if ( (isset($tdl_options['tdl_blog_default_header_bg']['url'])) && (trim($tdl_options['tdl_blog_default_header_bg']['url']) != "" ) ) {
$default_image_header = $tdl_options['tdl_blog_default_header_bg']['url'];
}
if ($default_image_header) {
$header_content_type = 'image';
$image_header = $default_image_header;
} else {
$header_content_type = '';
}
$title_align = $tdl_options['tdl_blog_title_align'];
?>
<?php
if ($header_content_type == 'image')
echo '<div class="site_header with_featured_img' . $no_parallax . '" style="' . $title_style . 'background-image:url(' . $image_header . ')">';
else
echo '<div class="site_header without_featured_img ' . $title_color . '" style="' . $title_style . '">';
?>
<div class="site_header_overlay"></div>
<div class="row">
<div class="large-12 <?php echo esc_attr( $title_align );?> large-centered columns">
<?php
if ((isset($tdl_options['tdl_shop_breadcrumb'])) && ($tdl_options['tdl_shop_breadcrumb'] == "1"))
{
// BREADCRUMBS
echo woodstock_breadcrumbs();
}
?>
<h1 class="page-title on-shop">
<?php
if ( is_category() ) :
single_cat_title();
elseif ( is_tag() ) :
single_tag_title();
elseif ( is_author() ) :
/* Queue the first post, that way we know
* what author we're dealing with (if that is the case).
*/
the_post();
printf( esc_html__( 'Author: %s', 'woodstock' ), '<span class="vcard">' . get_the_author() . '</span>' );
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
elseif ( is_day() ) :
printf( esc_html__( 'Day: %s', 'woodstock' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
printf( esc_html__( 'Month: %s', 'woodstock' ), '<span>' . get_the_date( 'F Y' ) . '</span>' );
elseif ( is_year() ) :
printf( esc_html__( 'Year: %s', 'woodstock' ), '<span>' . get_the_date( 'Y' ) . '</span>' );
elseif ( is_tax( 'post_format', 'post-format-aside' ) ) :
esc_html_e( 'Asides', 'woodstock' );
elseif ( is_tax( 'post_format', 'post-format-image' ) ) :
esc_html_e( 'Images', 'woodstock');
elseif ( is_tax( 'post_format', 'post-format-video' ) ) :
esc_html_e( 'Videos', 'woodstock' );
elseif ( is_tax( 'post_format', 'post-format-quote' ) ) :
esc_html_e( 'Quotes', 'woodstock' );
elseif ( is_tax( 'post_format', 'post-format-link' ) ) :
esc_html_e( 'Links', 'woodstock' );
else :
esc_html_e( 'Archives', 'woodstock' );
endif;
?>
</h1>
<?php
// Show an optional term description.
$term_description = term_description();
if ( ! empty( $term_description ) ) :
printf( '<div class="term-description"><p>%s</p></div>', $term_description );
endif;
?>
</div><!-- .large-12 -->
</div><!-- .row -->
</div><!-- .site_header -->
<?php if ( $blog_with_sidebar == "yes" ) : ?>
<div class="row"><div class="large-8 columns with-sidebar">
<?php endif; ?>
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<!--masonry style-->
<?php if ( $blog_with_sidebar == "blog-masonry" ) : ?>
<div class="blog-isotop-master-wrapper">
<div class="row">
<div class="large-12 columns">
<div class="blog-isotop-container">
<div id="filters" class="button-group">
<button class="filter-item is-checked" data-filter="*">show all</button>
</div>
<div class="blog-isotope">
<div class="grid-sizer"></div>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="blog-post hidden <?php echo get_post_format(); ?>">
<div class="blog-post-inner">
<?php get_template_part( 'includes/content', get_post_format() ); ?>
<hr class="content_hr" />
</div><!--blog-post-inner-->
</div><!-- .blog-post-->
<?php endwhile; ?>
</div><!-- .blog-isotope -->
</div><!-- .blog-isotop-container-->
</div><!--.large-12-->
</div><!--.row-->
<?php woodstock_content_nav( 'nav-below' ); ?>
</div><!--blog-isotop-master-wrapper-->
<!--default style-->
<?php else : ?>
<?php if(is_author()) {
echo '<h1 class="author-name">Články od autora: '.get_the_author_meta('display_name', $author_id).'</h1>';
echo '<div class="author-description">'.get_the_author_meta('description', $author_id).'</div>';
} ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'includes/content', get_post_format() ); ?>
<hr class="content_hr" />
<?php endwhile; ?>
<?php woodstock_content_nav( 'nav-below' ); ?>
<?php endif; ?>
<!--no posts found-->
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
<?php if ( $blog_with_sidebar == "yes" ) : ?>
</div><!-- .columns -->
<?php endif; ?>
<?php if ( $blog_with_sidebar == "yes" ) : ?>
<div class="large-4 columns">
<div class="row">
<div class="large-10 large-push-2 columns">
<?php get_sidebar(); ?>
</div>
</div>
</div><!-- .columns -->
<?php endif; ?>
<?php if ( $blog_with_sidebar == "yes" ) : ?>
</div><!-- .row -->
<?php endif; ?>
<?php if ( $blog_with_sidebar == "yes" ) : ?>
<?php if (is_active_sidebar( 'sidebar')) : ?>
<div id="button_offcanvas_sidebar_left"><i class="sidebar-icon"></i></div>
<?php endif; ?>
<?php endif; ?>
</div><!-- #primary -->
<?php get_footer(); ?>
Same code works well on this URL
I've already tried update WordPress but it still doesn't work, so I'm helpless..
Problem was resolved by switching theme, so, it was maybe some bug in WP.
Google Webmaster Tools reports a bunch of structured data error: Missing: author, Missing: entry-title and Missing: updated for all my pages. For my posts thoug, it's only Missing: updated.
I'm using WordPres CM with a custom theme based on the Twenty Thirteen theme. Pretty much every thread I've enountered on this issue tells me to edit my single.php file and add the entry-title class to the h1 tag containing the_title. However, my single.php file looks like this:
<?php
/**
* The template for displaying all single posts
*
* #package WordPress
* #subpackage Twenty_Thirteen
* #since Twenty Thirteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php twentythirteen_post_nav(); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I don't know PHP very well, but I guess that the following line
<?php get_template_part( 'content', get_post_format() ); ?>
means that it's loading the file content.php, which looks like this:
<?php
/**
* The default template for displaying content
*
* Used for both single and index/archive/search.
*
* #package WordPress
* #subpackage Twenty_Thirteen
* #since Twenty Thirteen 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( has_post_thumbnail() && ! post_password_required() && ! is_attachment() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<?php if ( is_single() ) : ?>
<h1 class="entry-title post-title"><?php the_title(); ?></h1>
<?php else : ?>
<h1 class="entry-title post-title">
<?php the_title(); ?>
</h1>
<?php endif; // is_single() ?>
<div class="entry-meta">
<?php twentythirteen_entry_meta(); ?>
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php
/* translators: %s: Name of current post */
the_content( sprintf(
__( 'Continue reading %s <span class="meta-nav">→</span>', 'twentythirteen' ),
the_title( '<span class="screen-reader-text">', '</span>', false )
) );
wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
<footer class="entry-meta">
<?php if ( comments_open() && ! is_single() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a comment', 'twentythirteen' ) . '</span>', __( 'One comment so far', 'twentythirteen' ), __( 'View all % comments', 'twentythirteen' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open() ?>
<?php if ( is_single() && get_the_author_meta( 'description' ) && is_multi_author() ) : ?>
<?php get_template_part( 'author-bio' ); ?>
<?php endif; ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
I assume this is the key part:
<div class="entry-meta">
<?php twentythirteen_entry_meta(); ?>
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-meta -->
where
<?php twentythirteen_entry_meta(); ?>
is calling a function from the functions.php file:
if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
/**
* Print HTML with meta information for current post: categories, tags, permalink, author, and date.
*
* Create your own twentythirteen_entry_meta() to override in a child theme.
*
* #since Twenty Thirteen 1.0
*/
function twentythirteen_entry_meta() {
if ( is_sticky() && is_home() && ! is_paged() )
echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>';
if ( ! has_post_format( 'link' ) && 'post' == get_post_type() )
twentythirteen_entry_date();
// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
if ( $categories_list ) {
echo '<span class="categories-links">' . $categories_list . '</span>';
}
// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
if ( $tag_list ) {
echo '<span class="tags-links">' . $tag_list . '</span>';
}
// Post author
if ( 'post' == get_post_type() ) {
printf( '<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', 'twentythirteen' ), get_the_author() ) ),
get_the_author()
);
}
}
endif;
SO, here's the big question:
What do I need to change to fix those structured data errors?
Any help is very much appreciated.
I have an issue I cannot solve. On my single.php page I included the comment form:
<?php comments_template('/partials/comments.php'); ?>
In my partials folder I made a comments.php (from the theme where this is working fine):
<?php
/**
* The template for displaying Comments.
*
* The area of the page that contains both current comments
* and the comment form. The actual display of comments is
* handled by a callback to MYtheme_comment().
*
*/
function MYtheme_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php esc_html_e( 'Pingback:', 'my_theme' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( esc_html__( 'Edit', 'my_theme' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class('clearfix'); ?> id="comment-<?php comment_ID(); ?>">
<span class="comment_avatar">
<?php
$avatar_size = 100;
if ( '0' != $comment->comment_parent ){
$avatar_size = 100;
}
echo get_avatar( $comment, $avatar_size );
echo '</span><span class="comment_content">';
?>
<div class="comment-text">
<?php
/* translators: 1: comment author, 2: date and time */
printf( esc_html__( '%1$s %2$s', 'my_theme' ),
sprintf( '<span class="comment-author">%s</span>', get_comment_author_link() ),
sprintf( '<time pubdate datetime="%2$s">%3$s</time>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( esc_html__( '%1$s at %2$s', 'my_theme' ), get_comment_date(), get_comment_time() )
)
);
?>
<?php edit_comment_link( esc_html__( 'Edit', 'my_theme' ), '<span class="edit-link">', '</span>' ); ?>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'my_theme' ); ?></em>
<br />
<?php else: ?>
<?php comment_text(); ?>
<?php endif; ?>
<p class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => esc_html__( 'Reply ', 'my_theme' ).'<i class="ci_icon-chevronright-thin"></i>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</p><!-- .reply -->
</span>
</div>
<?php
break;
endswitch;
}
?>
<div id="comments">
<?php if ( post_password_required() ) : ?>
<p class="nopassword"><?php esc_html_e( 'This post is password protected. Enter the password to view any comments.', 'my_theme' ); ?></p>
</div><!-- #comments -->
<?php
/* Stop the rest of comments.php from being processed,
* but don't kill the script entirely -- we still have
* to fully load the template.
*/
return;
endif;
?>
<?php // You can start editing here -- including this comment! ?>
<?php if ( have_comments() ) : ?>
<h3 id="comments-title"><?php printf( _n( 'One comment', '%1$s comments', get_comments_number(), 'my_theme' ), number_format_i18n( get_comments_number() ) );?></h3>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
<nav id="comment-nav-above">
<h1 class="assistive-text"><?php esc_html_e( 'Comment navigation', 'my_theme' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( esc_html__( '← Older Comments', 'my_theme' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments →', 'my_theme' ) ); ?></div>
</nav>
<?php endif; // check for comment navigation ?>
<ol class="commentlist">
<?php
/* Loop through and list the comments. Tell wp_list_comments()
* to use MYtheme_comment() to format the comments.
* If you want to overload this in a child theme then you can
* define MYtheme_comment() and that will be used instead.
* See MYtheme_comment() in twentyeleven/functions.php for more.
*/
wp_list_comments( array( 'callback' => 'MYtheme_comment' ) );
?>
</ol>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
<nav id="comment-nav-below">
<h1 class="assistive-text"><?php esc_html_e( 'Comment navigation', 'my_theme' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( esc_html__( '← Older Comments', 'my_theme' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments →', 'my_theme' ) ); ?></div>
</nav>
<?php endif; // check for comment navigation ?>
<?php
/* If there are no comments and comments are closed, let's leave a little note, shall we?
* But we don't want the note on pages or post types that do not support comments.
*/
elseif ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="nocomments"><?php esc_html_e( 'Comments are closed.', 'my_theme' ); ?></p>
<?php endif; ?>
<?php
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields = array(
'author' =>
'<div class="comment_fields"><p class="comment-form-author"><input id="author" name="author" type="text" placeholder="' . esc_html__( 'Name*', 'my_theme' ) . '" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' /></p>',
'email' =>
'<p class="comment-form-email"><input id="email" name="email" type="text" placeholder="' . esc_html__( 'E-mail*', 'my_theme' ) . '" value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' /></p>',
'url' =>
'<p class="comment-form-url"><input id="url" name="url" type="text" placeholder="' . esc_html__( 'Website*', 'my_theme' ) . '" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30"' . $aria_req . ' /></p></div>',
);
$comment_field = '<p class="comment-form-comment"><textarea id="comment" name="comment" placeholder="' . esc_html__( 'Message*', 'my_theme' ) . '" cols="45" rows="8" aria-required="true"></textarea></p>';
comment_form(array(
'fields' => $fields,
'comment_field' => $comment_field,
'comment_notes_after' => '',
'id_submit' => 'comment-submit',
'title_reply' => esc_html__( 'Leave a reply', 'my_theme' ),
'label_submit' => esc_html__( 'Leave a comment', 'my_theme' ),
)); ?>
<div class="clear"></div>
</div><!-- #comments -->
The form appears, my comments are enabled in the wordpress. I fill the form and click on the submit button, and nothing happens!
So I tried to ajaxify it by adding the code from here
<script type="text/javascript">
jQuery('document').ready(function($){
// Get the comment form
var commentform = $('#commentform');
// Add a Comment Status message
commentform.prepend('<div id="comment-status" ></div>');
// Defining the Status message element
var statusdiv = $('#comment-status');
commentform.submit(function(){
// Serialize and store form data
var formdata = commentform.serialize();
//Add a status message
statusdiv.html('<p class="ajax-placeholder">Processing...</p>');
//Extract action URL from commentform
var formurl = commentform.attr('action');
//Post Form with data
$.ajax({
type: 'post',
url: formurl,
data: formdata,
error: function(XMLHttpRequest, textStatus, errorThrown){
statusdiv.html('<p class="ajax-error" >You might have left one of the fields blank, or be posting too quickly</p>');
},
success: function(data, textStatus){
if(data == "success")
statusdiv.html('<p class="ajax-success" >Thanks for your comment. We appreciate your response.</p>');
else
statusdiv.html('<p class="ajax-error" >Please wait a while before posting your next comment</p>');
commentform.find('textarea[name=comment]').val('');
}
});
return false;
});
});
</script>
Now when I comment, I get first the first error about leaving one of the fields blank, and then after that immediately I get the second error about posting a comment too quickly. I also noticed a 409 (Conflict) error in the console in Chrome that comes from mythemefolder/wp-comments-post.php which is a default from action link that comes from wordpress.
The strange thing is that once I refresh my page, I can see the post that I've added with ajax post. If I remove ajax and try to post a comment, and then refresh, nothing happens.
So what can be the issue? Why is there nothing being posted when I have no AJAX, and why are comments appearing when I have AJAX but only on page refresh?
EDIT
In Firebug when I inspect and send the form, I get:
POST mythemefolder/wp-comments-post.php 302 Moved Temporarily 2,51s
POST mythemefolder/wp-comments-post.php 409 Conflict 1,37s
GET mythemefolder/postname/#comment-11 200 OK 2,64s
So something happens. When I open the conflict one I find
<p>Duplicate comment detected; it looks as though you’ve already said that!</p></body>
Any clues?
Found the answer, the fault was my theme. It had a preventDefault() on a .submit button when clicked. The comment form works when I remove that part.
I have a single.php file where I want to show author name and the date which it is posted on outside the loop, the date outputs fine but the author of the post doesn't appear. I have tried everything like making the author name global etc.
I have three files single.php, content-single.php and a file with the function.
single.php code
get_header(); ?>
<div class="bread-crumb">
<?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
</div>
<div class="title-main">
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<div class="entry-meta">
<?php motion_posted_on(); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
</div>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'single' ); ?>
<?php the_post_navigation(); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
content-single.php code
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'motion' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php motion_entry_footer(); ?>
</footer><!-- .entry-footer -->
and another file with the related function of motion_posted_on();
function motion_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'motion' ),
'' . $time_string . ''
);
$byline = sprintf(
esc_html_x( 'by %s', 'post author', 'motion' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';}
Try this:
function motion_posted_on() {
global $post;
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'motion' ),
'' . $time_string . ''
);
$byline = ''. get_the_author_meta( 'display_name',$post->post_author).'';
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';}
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/