Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Comments template cleaned up and refactored #1296

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 10 additions & 90 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

if ( have_comments() ) :
if ( ( is_page() || is_single() ) && ( ! is_home() && ! is_front_page() ) ) :
?>
<section id="comments">
<?php
Copy link
Collaborator

@colin-marshall colin-marshall Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an <hr> here? I think it makes the the comments section easier to decipher from the post content with one.

EDIT: So it's clear, I'm talking right before the <section> element.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a good idea but also we still could add a line with CSS and border, which will avoid adding hr element...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already using an <hr> element between the comments and the leave a reply form.

Questions for everybody:

  1. Do we want a line in both places or just one of the places? (between post and comments, and between comments and comment reply form)
  2. Should we make this line with CSS or with <hr>?

Copy link
Contributor

@JPOak JPOak Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would either remove the <hr> in both places or just add the <hr> element. I lean towards being less opinionated when it comes to design.

Copy link
Collaborator Author

@derweili derweili Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the <hr> from the pull request

Expand All @@ -37,9 +36,11 @@
);

?>
<?php
foundationpress_the_comments_pagination();
?>
</section>
<?php
endif;
endif;
?>

Expand All @@ -65,96 +66,15 @@

<?php
if ( comments_open() ) :
if ( ( is_page() || is_single() ) && ( ! is_home() && ! is_front_page() ) ) :
?>
<section id="respond">
<h3>
<?php
comment_form_title(
__( 'Leave a Reply', 'foundationpress' ),
/* translators: %s: author of comment being replied to */
__( 'Leave a Reply to %s', 'foundationpress' )
);
?>
</h3>
<p class="cancel-comment-reply"><?php cancel_comment_reply_link(); ?></p>
<?php if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) : ?>
<p>
<?php
/* translators: %s: login url */
printf(
__( 'You must be <a href="%s">logged in</a> to post a comment.', 'foundationpress' ),
wp_login_url( get_permalink() )
);
?>
</p>
<?php else : ?>
<form action="<?php echo get_option( 'siteurl' ); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( is_user_logged_in() ) : ?>
<p>
<?php
/* translators: %1$s: site url, %2$s: user identity */
printf(
__( 'Logged in as <a href="%1$s/wp-admin/profile.php">%2$s</a>.', 'foundationpress' ),
get_option( 'siteurl' ),
$user_identity
);
?> <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php __( 'Log out of this account', 'foundationpress' ); ?>"><?php _e( 'Log out &raquo;', 'foundationpress' ); ?></a>
</p>
<?php else : ?>
<p>
<label for="author">
<?php
_e( 'Name', 'foundationpress' );
if ( $req ) {
_e( ' (required)', 'foundationpress' );
}
?>
</label>
<input type="text" class="five" name="author" id="author" value="<?php echo esc_attr( $comment_author ); ?>" size="22" tabindex="1" <?php if ( $req ) { echo "aria-required='true'"; } ?>>
</p>
<p>
<label for="email">
<?php
_e( 'Email (will not be published)', 'foundationpress' );
if ( $req ) {
_e( ' (required)', 'foundationpress' );
}
?>
</label>
<input type="text" class="five" name="email" id="email" value="<?php echo esc_attr( $comment_author_email ); ?>" size="22" tabindex="2" <?php if ( $req ) { echo "aria-required='true'"; } ?>>
</p>
<p>
<label for="url">
<?php
_e( 'Website', 'foundationpress' );
?>
</label>
<input type="text" class="five" name="url" id="url" value="<?php echo esc_attr( $comment_author_url ); ?>" size="22" tabindex="3">
</p>
<?php endif; ?>
<p>
<label for="comment">
<?php
_e( 'Comment', 'foundationpress' );
?>
</label>
<textarea name="comment" id="comment" tabindex="4"></textarea>
</p>
<p id="allowed_tags" class="small"><strong>XHTML:</strong>
<?php
_e( 'You can use these tags:', 'foundationpress' );
?>
<code>
<?php echo allowed_tags(); ?>
</code>
</p>
<p><input name="submit" class="button" type="submit" id="submit" tabindex="5" value="<?php esc_attr_e( 'Submit Comment', 'foundationpress' ); ?>"></p>
<?php comment_id_fields(); ?>
<?php do_action( 'comment_form', $post->ID ); ?>
</form>
<?php endif; // If registration required and not logged in. ?>
<?php
comment_form(
array(
'class_submit' => 'button'
)
);
?>
</section>
<?php
endif; // If you delete this the sky will fall on your head.
endif; // If you delete this the sky will fall on your head.
61 changes: 61 additions & 0 deletions library/foundation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,67 @@ function foundationpress_pagination() {
}
endif;

// Custom Comments Pagination.
if ( ! function_exists( 'foundationpress_get_the_comments_pagination' ) ) :
function foundationpress_get_the_comments_pagination( $args = array() ) {
$navigation = '';
$args = wp_parse_args( $args, array(
'prev_text' => __( '&laquo;', 'foundationpress' ),
'next_text' => __( '&raquo;', 'foundationpress' ),
'size' => 'default',
'show_disabled' => true,
) );
$args['type'] = 'array';
$args['echo'] = false;
$links = paginate_comments_links( $args );
if ( $links ) {
$link_count = count( $links );
$pagination_class = 'pagination';
if ( 'large' == $args['size'] ) {
$pagination_class .= ' pagination-lg';
} elseif ( 'small' == $args['size'] ) {
$pagination_class .= ' pagination-sm';
}
$current = get_query_var( 'cpage' ) ? intval( get_query_var( 'cpage' ) ) : 1;
$total = get_comment_pages_count();
$navigation .= '<ul class="' . $pagination_class . '">';
if ( $args['show_disabled'] && 1 === $current ) {
$navigation .= '<li class="page-item disabled">' . $args['prev_text'] . '</li>';
}
foreach ( $links as $index => $link ) {
if ( 0 == $index && 0 === strpos( $link, '<a class="prev' ) ) {
$navigation .= '<li class="page-item">' . str_replace( 'prev page-numbers', 'page-link', $link ) . '</li>';
} elseif ( $link_count - 1 == $index && 0 === strpos( $link, '<a class="next' ) ) {
$navigation .= '<li class="page-item">' . str_replace( 'next page-numbers', 'page-link', $link ) . '</li>';
} else {
$link = preg_replace( "/(class|href)='(.*)'/U", '$1="$2"', $link );
if ( 0 === strpos( $link, '<span class="page-numbers current' ) ) {
$navigation .= '<li class="page-item active">' . str_replace( array( '<span class="page-numbers current">', '</span>' ), array( '<a class="page-link" href="#">', '</a>' ), $link ) . '</li>';
} elseif ( 0 === strpos( $link, '<span class="page-numbers dots' ) ) {
$navigation .= '<li class="page-item disabled">' . str_replace( array( '<span class="page-numbers dots">', '</span>' ), array( '<a class="page-link" href="#">', '</a>' ), $link ) . '</li>';
} else {
$navigation .= '<li class="page-item">' . str_replace( 'class="page-numbers', 'class="page-link', $link ) . '</li>';
}
}
}
if ( $args['show_disabled'] && $current == $total ) {
$navigation .= '<li class="page-item disabled">' . $args['next_text'] . '</li>';
}
$navigation .= '</ul>';
$navigation = _navigation_markup( $navigation, 'comments-pagination' );
}
return $navigation;
}
endif;

// Custom Comments Pagination.
if ( ! function_exists( 'foundationpress_the_comments_pagination' ) ) :
function foundationpress_the_comments_pagination( $args = array() ) {
echo foundationpress_get_the_comments_pagination( $args );
}
endif;


/**
* A fallback when no navigation is selected by default.
*/
Expand Down