Hello Community,
i want to share how i have got my custom include to work and what i have found on the way..
my initial thing you can read at
https://ww.wp.xz.cn/support/topic/enable-on-custom-included-posts/
i now have a setup that is working – a child theme with some customization:
– there is a custom short-code to include pages and posts into other sites..
– a modified comments.php (copied from twentytwentyone theme:
<?php
/**
* The template for displaying comments
*
* This is the template that displays the area of the page that contains both the current comments
* and the comment form.
*
* @link https://developer.ww.wp.xz.cn/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password,
* return early without loading the comments.
*/
if ( post_password_required() ) {
return;
}
$twenty_twenty_one_comment_count = get_comments_number();
?>
<div
id="post-comments-area-<?php echo get_the_ID(); ?>"
class="comments-area default-max-width <?php echo get_option( 'show_avatars' ) ? 'show-avatars' : ''; ?>"
>
<?php if ( '0' !== $twenty_twenty_one_comment_count ) : ?>
<h2 class="comments-title">
<?php if ( '1' === $twenty_twenty_one_comment_count ) : ?>
<?php esc_html_e( '1 comment', 'twentytwentyone' ); ?>
<?php else : ?>
<?php
printf(
/* translators: %s: Comment count number. */
esc_html( _nx( '%s comment', '%s comments', $twenty_twenty_one_comment_count, 'Comments title', 'twentytwentyone' ) ),
esc_html( number_format_i18n( $twenty_twenty_one_comment_count ) )
);
?>
<?php endif; ?>
</h2><!-- .comments-title -->
<ol class="comment-list">
<?php
// we need to manually receive this list..
$comments = get_comments( array(
'post_id' => get_the_ID(),
'orderby' => 'comment_date_gmt',
'status' => 'approve',
));
wp_list_comments(
array(
'avatar_size' => 60,
'style' => 'ol',
'short_ping' => true,
),
$comments
);
?>
</ol><!-- .comment-list -->
<?php
the_comments_pagination(
array(
'before_page_number' => esc_html__( 'Page', 'twentytwentyone' ) . ' ',
'mid_size' => 0,
'prev_text' => sprintf(
'%s <span class="nav-prev-text">%s</span>',
is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ),
esc_html__( 'Older comments', 'twentytwentyone' )
),
'next_text' => sprintf(
'<span class="nav-next-text">%s</span> %s',
esc_html__( 'Newer comments', 'twentytwentyone' ),
is_rtl() ? twenty_twenty_one_get_icon_svg( 'ui', 'arrow_left' ) : twenty_twenty_one_get_icon_svg( 'ui', 'arrow_right' )
),
)
);
?>
<?php if ( ! comments_open() ) : ?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'twentytwentyone' ); ?></p>
<?php endif; ?>
<?php else : ?>
<!-- no comments found. -->
<?php endif; ?>
<?php
comment_form(
array(
'logged_in_as' => null,
'title_reply' => esc_html__( 'Leave a comment', 'twentytwentyone' ),
'title_reply_before' => '<h2 class="comment-reply-title">',
'title_reply_after' => '</h2>',
// Change the ID of the comment form from #commentform
// to #commentform-1234, where 1234 is the ID of the post
// https://ww.wp.xz.cn/support/topic/multiple-comment-forms-reloading-page-on-comment-submit/#post-13554846
'id_form' => 'commentform-' . get_the_ID(),
)
);
?>
</div><!-- #comments -->
the main parts i changed:
i added a id="post-comments-area-<?php echo get_the_ID(); ?>"
so wrapper has a id.
and added the id to the comments form
the second seems to be needed as outlined in
https://ww.wp.xz.cn/support/topic/multiple-comment-forms-reloading-page-on-comment-submit/#post-13554846
the first does not hurt… – so it is easier to track what is happening..
in my main page the html structure looks like this:
<body class="home page page-id-5 page-parent singular has">
<div id="page" class="site">
<!-- ... -->
<div id="content" class="site-content">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<article id="post-5" class="post-5 page type-page status-publish hentry entry">
<div class="entry-content">
<!-- post count: 10 -->
<!-- post tittle: "Gästebuch" -->
<!-- post tittle: "Kontakt" -->
<!-- ... -->
<ul>
<li>
<section id="guestbook_section" class="overlay-box">
<div class="content">
<button class="close-button">X</button>
<div class="wp-block-latest-posts__post-full-content">
<article id="post-186" class="post-186">
<!-- ... -->
</article>
<!-- get_post_comments() -->
<div id="post-comments-area-186" class="comments-area default-max-width show-avatars">
<h2 class="comments-title">
2 comments
</h2><!-- .comments-title -->
<ol class="comment-list">
<li id="comment-7" class="comment even thread-even depth-1 parent">
<article id="div-comment-7" class="comment-body">
<div class="comment-content">
<!-- ... -->
</div>
</article>
</li>
<li id="comment-12" class="comment odd alt thread-odd thread-alt depth-1">
<article id="div-comment-12" class="comment-body">
<div class="comment-content">
<!-- ... -->
</div>
</article>
</li>
</ol><!-- .comment-list -->
<div id="respond-186" class="comment-respond">
<h2 class="comment-reply-title">
Leave a comment
</h2>
<form action="https://localhost/test.de/wp-comments-post.php" method="post" id="commentform-186" class="comment-form" novalidate="">
</form>
</div><!-- #respond -->
</div><!-- #comments -->
</div>
</div>
</section>
</li>
<li>
<section id="contact" class="overlay-box">
<div class="content">
<button class="close-button">X</button>
<div class="wp-block-latest-posts__post-full-content">
<article id="post-7" class="post-7">
</article>
<!-- get_post_comments() -->
<div id="post-comments-area-7" class="comments-area default-max-width show-avatars">
<!-- no comments found. -->
</div>
<!-- #comments -->
</div>
</div>
</section>
</li>
</ul>
<!-- ... -->
</div><!-- .entry-content -->
</article><!-- #post-5 -->
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- #content -->
<!-- ... -->
</div><!-- #page -->
</body>
with this i have the following setup in the wp-ajaxify-comments config:
– Post container selector article[id^='post-']
– Comment pages URL regex /.*/i
– Comment form selector ~.comments-area .comment-form
– Comments container selector ~.comments-area
– Comment paging links selector ~.comments-area *[class^='nav-'] a (not tested)
– Comment links selector ~.comments-area a[href*="/comment-page-"]
– Respond container selector ~.comments-area .comment-respond
one big help to find what selectors i had to use was reading the source code:
https://plugins.trac.ww.wp.xz.cn/browser/wp-ajaxify-comments/trunk/js/wp-ajaxify-comments.js#L506
that made it clear how the plugin is searching for things…
sunny greetings
stefan
-
This topic was modified 4 years, 9 months ago by
s-light. Reason: fixed formating
(@s-light)
4 years, 9 months ago
Hello Community,
i want to share how i have got my custom include to work and what i have found on the way..
my initial thing you can read at
https://ww.wp.xz.cn/support/topic/enable-on-custom-included-posts/
i now have a setup that is working – a child theme with some customization:
– there is a custom short-code to include pages and posts into other sites..
– a modified comments.php (copied from twentytwentyone theme:
the main parts i changed:
i added a
id="post-comments-area-<?php echo get_the_ID(); ?>"so wrapper has a id.
and added the id to the comments form
the second seems to be needed as outlined in
https://ww.wp.xz.cn/support/topic/multiple-comment-forms-reloading-page-on-comment-submit/#post-13554846
the first does not hurt… – so it is easier to track what is happening..
in my main page the html structure looks like this:
with this i have the following setup in the wp-ajaxify-comments config:
– Post container selector
article[id^='post-']– Comment pages URL regex
/.*/i– Comment form selector
~.comments-area .comment-form– Comments container selector
~.comments-area– Comment paging links selector
~.comments-area *[class^='nav-'] a(not tested)– Comment links selector
~.comments-area a[href*="/comment-page-"]– Respond container selector
~.comments-area .comment-respondone big help to find what selectors i had to use was reading the source code:
https://plugins.trac.ww.wp.xz.cn/browser/wp-ajaxify-comments/trunk/js/wp-ajaxify-comments.js#L506
that made it clear how the plugin is searching for things…
sunny greetings
stefan