Skip to content

Commit

Permalink
Don't fetch the page contents twice
Browse files Browse the repository at this point in the history
Simplify comments' markup
Put the "Share this page" section after the comments
  • Loading branch information
bperel committed Feb 14, 2019
1 parent 3e41492 commit d03d20f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 100 deletions.
70 changes: 33 additions & 37 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,44 @@ function format_comment($comment, $args, $depth) {
if ( post_password_required() ) {
return;
} ?>
<article>
<div class="entry-content">
<div id="comments" class="comments-area">
<div id="comments" class="comments-area">

<?php
// You can start editing here -- including this comment!
if ( have_comments() ) :
?>
<h2 class="comments-title">
<?=__('Share your thoughts')?>
</h2>
<?php
// You can start editing here -- including this comment!
if ( have_comments() ) :
?>
<h2 class="comments-title">
<?=__('Share your thoughts')?>
</h2>

<?php the_comments_navigation(); ?>
<?php the_comments_navigation(); ?>

<ol class="comment-list">
<?php
wp_list_comments( array(
'callback' => 'format_comment',
'style' => 'ol',
'short_ping' => true,
) );
?>
</ol><!-- .comment-list -->
<ol class="comment-list">
<?php
wp_list_comments( array(
'callback' => 'format_comment',
'style' => 'ol',
'short_ping' => true,
) );
?>
</ol><!-- .comment-list -->

<?php
the_comments_navigation();
<?php
the_comments_navigation();

if ( ! comments_open() ) :
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'klarity' ); ?></p>
<?php
endif;
if ( ! comments_open() ) :
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'klarity' ); ?></p>
<?php
endif;

endif; // Check for have_comments().
endif; // Check for have_comments().

comment_form([
'label_submit' => __('Comment'),
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="btn %3$s" value="%4$s" />',
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x('Comment', 'noun') . ' *</label> <textarea id="comment" class="materialize-textarea" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>'
]);
?>
comment_form([
'label_submit' => __('Comment'),
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="btn %3$s" value="%4$s" />',
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x('Comment', 'noun') . ' *</label> <textarea id="comment" class="materialize-textarea" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>'
]);
?>

</div><!-- #comments -->
</div>
</article>
</div><!-- #comments -->
7 changes: 7 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ function add_theme_scripts() {
wp_enqueue_style('klarity-style', get_template_directory_uri() . '/editor.css', [], time());
}
add_action('enqueue_block_editor_assets', 'add_theme_scripts');

// Remove AddToAny this we add it ourselves later
function addtoany_remove() {
remove_filter( 'the_content', 'A2A_SHARE_SAVE_add_to_content', 98 );
}
add_action( 'pre_get_posts', 'addtoany_remove');

/**
* Implement the Custom Header feature.
*/
Expand Down
7 changes: 0 additions & 7 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@
<?php
while ( have_posts() ) :
the_post();

get_template_part( 'template-parts/content', 'page' );

// 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;

endwhile; // End of the loop.
?>

Expand Down
104 changes: 48 additions & 56 deletions template-parts/content-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,61 @@
*
* @package klarity
*/

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if (has_post_thumbnail() ) {
?>
if (has_post_thumbnail()) { ?>
<div id="index-banner" class="parallax-container">
<div class="section no-pad-bot valign-wrapper">
<div class="entry-content">
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
endif;

if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php
klarity_posted_on();
klarity_posted_by();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
</header><!-- .entry-header -->
</div>
<div class="section no-pad-bot valign-wrapper">
<div class="entry-content">
<header class="entry-header"><?php
if (is_singular()) :
the_title('<h1 class="entry-title">', '</h1>');
else :
the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
endif;
if ('post' === get_post_type()) :?>
<div class="entry-meta"><?php
klarity_posted_on();
klarity_posted_by(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>
</header><!-- .entry-header -->
</div>
<div class="parallax">
<?php
the_post_thumbnail( 'post-thumbnail', array(
'alt' => the_title_attribute(array('echo' => false)))
);
?></div>
</div>
<?php
}
?>

<div class="entry-content">
<?php
$post_content = get_the_content( get_the_ID() ); // Get the post_content

the_content(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'klarity' ),
array(
'span' => array('class' => array()),
)
),
get_the_title()
)
);

wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'klarity' ),
'after' => '</div>',
) );
?>
<div class="parallax"><?php
the_post_thumbnail('post-thumbnail', [
'alt' => the_title_attribute(['echo' => false])]
); ?>
</div>
</div><?php
} ?>
<div class="entry-content"><?php
$post_content = get_the_content(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__('Continue reading<span class="screen-reader-text"> "%s"</span>', 'klarity'),
['span' => ['class' => []]]
),
get_the_title()
)
);
wp_link_pages([
'before' => '<div class="page-links">' . esc_html__('Pages:', 'klarity'),
'after' => '</div>',
]);
// If comments are open or we have at least one comment, load up the comment template.
if (comments_open() || get_comments_number()) :
ob_start();
comments_template();
$post_content .= ob_get_clean();
endif;
if (function_exists('A2A_SHARE_SAVE_add_to_content')) {
$post_content = A2A_SHARE_SAVE_add_to_content($post_content);
}
echo $post_content; ?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php klarity_entry_footer(); ?>
Expand Down

0 comments on commit d03d20f

Please sign in to comment.