{"id":3808,"date":"2017-07-15T18:37:47","date_gmt":"2017-07-15T16:37:47","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=3808"},"modified":"2020-02-09T10:59:48","modified_gmt":"2020-02-09T09:59:48","slug":"separate-comments-pings-in-wordpress-theme","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/separate-comments-pings-in-wordpress-theme-3808\/","title":{"rendered":"Separate comments and pings in a WordPress theme"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Instead of listing all post reactions \u2013 comments, trackbacks, and pingbacks \u2013 in one list, I like to separate comments and pings (pingbacks and trackbacks) for the sake of clarity. That is not too difficult, but there are a few things to consider.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">The problem (with my old solution)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The way that might be most obvious (and the way I used until recently) is to call the comments template in this way:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">comments_template( <span class=\"hljs-string\">''<\/span>, <span class=\"hljs-literal\">true<\/span> );<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Setting the second param to true gives you the reactions separated by type via the <code class=\"lang-php\">$comments_by_type<\/code> variable in the <code class=\"lang-php\">comments.php<\/code> \u2013 to get the number of comments, I used to do a <code class=\"lang-php\">count( $comments_by_type['comment'] )<\/code>. That works without problems if the reactions are not broken into multiple pages. If that is the case, the above function call would only return the number of currently displayed comments, not the total comment number for the post.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The solution<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To fix that, we need to fetch the reactions on our own in the <code class=\"lang-php\">comments.php<\/code> and do not use the second param from <code class=\"lang-php\">comments_template()<\/code>. To show you how that can be done, I will go through the <code class=\"lang-php\">comments.php<\/code> of my new theme.<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n<span class=\"hljs-comment\">\/**\n * Comments template.\n *\n * <span class=\"hljs-doctag\">@version<\/span> 1.0.0\n *\n * <span class=\"hljs-doctag\">@package<\/span> Photographus\n *\/<\/span>\n\n<span class=\"hljs-keyword\">if<\/span> ( post_password_required() ) {\n\t<span class=\"hljs-keyword\">return<\/span>;\n} <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">aside<\/span> <span class=\"hljs-attr\">aria-labelledby<\/span>=<span class=\"hljs-string\">\"aside\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"comments-area\"<\/span>&gt;<\/span>\n\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> <span class=\"hljs-keyword\">if<\/span> ( have_comments() ) {\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * We cannot use the second parameter from comments_template()\n\t\t * to separate the reactions because if they are\n\t\t * broken on multiple pages, the count() would only return\n\t\t * the number of comments and pings which are displayed\n\t\t * on the current page, not the total.\n\t\t *\n\t\t * Because of that, we use our own function to get the comments by type.\n\t\t *\/<\/span>\n\t\t$comments_by_type = photographus_get_comments_by_type();<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">After using <code class=\"lang-php\">post_password_required()<\/code> to check if the post is password protected and we do not have the correct password, we check for reactions with <code class=\"lang-php\">have_comments()<\/code>. Next, we get the reactions \u2013 already separated \u2013 via a custom function. This function lives in the <code class=\"lang-php\">functions.php<\/code> (or in my case the <code class=\"lang-php\">template-tags.php<\/code>) and looks like that:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/**\n * Returns the post reactions separated by type.\n *\n * <span class=\"hljs-doctag\">@return<\/span> array Post reactions separated by type.\n *\/<\/span>\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">photographus_get_comments_by_type<\/span><span class=\"hljs-params\">()<\/span> <\/span>{\n\t$comment_args     = &#91;\n\t\t<span class=\"hljs-string\">'order'<\/span>   =&gt; <span class=\"hljs-string\">'ASC'<\/span>,\n\t\t<span class=\"hljs-string\">'orderby'<\/span> =&gt; <span class=\"hljs-string\">'comment_date_gmt'<\/span>,\n\t\t<span class=\"hljs-string\">'status'<\/span>  =&gt; <span class=\"hljs-string\">'approve'<\/span>,\n\t\t<span class=\"hljs-string\">'post_id'<\/span> =&gt; get_the_ID(),\n\t];\n\t$comments         = get_comments( $comment_args );\n\t$comments_by_type = separate_comments( $comments );\n\n\t<span class=\"hljs-keyword\">return<\/span> $comments_by_type;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">At first, we create an args array to get the approved reactions for that post, ordered by date in ascending order. Afterwards, we get the reactions via a <code class=\"lang-php\">get_comments()<\/code> call, separate the result with <code class=\"lang-php\">separate_comments()<\/code>, and return it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We continue in the <code class=\"lang-php\">comments.php<\/code> with the part of displaying comment count and the list of comments:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> ( ! empty( $comments_by_type&#91;<span class=\"hljs-string\">'comment'<\/span>] ) ) {\n\t<span class=\"hljs-comment\">\/**\n\t * Save the comment count.\n\t *\/<\/span>\n\t$comment_number = count( $comments_by_type&#91;<span class=\"hljs-string\">'comment'<\/span>] ); ?&gt;\n\t<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"comments-title\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"comments-title\"<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> printf( <span class=\"hljs-comment\">\/* translators: Title for comment list. 1=comment number, 2=post title *\/<\/span>\n\t\t\t_n(\n\t\t\t\t<span class=\"hljs-string\">'%1$s Comment on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t<span class=\"hljs-string\">'%1$s Comments on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t$comment_number,\n\t\t\t\t<span class=\"hljs-string\">'photographus'<\/span>\n\t\t\t),\n\t\t\tnumber_format_i18n( $comment_number ),\n\t\t\tget_the_title() ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span><\/span>\n\n\t<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">ul<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"commentlist\"<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * We need to specify the per_page key because otherwise\n\t\t * the separated reactions would not be broken correctly into\n\t\t * multiple pages.\n\t\t *\/<\/span>\n\t\twp_list_comments( &#91;\n\t\t\t<span class=\"hljs-string\">'callback'<\/span> =&gt; <span class=\"hljs-string\">'photographus_comments'<\/span>,\n\t\t\t<span class=\"hljs-string\">'style'<\/span>    =&gt; <span class=\"hljs-string\">'ul'<\/span>,\n\t\t\t<span class=\"hljs-string\">'type'<\/span>     =&gt; <span class=\"hljs-string\">'comment'<\/span>,\n\t\t\t<span class=\"hljs-string\">'per_page'<\/span> =&gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>],\n\t\t] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">ul<\/span>&gt;<\/span><\/span>\n&lt;?php }<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">At first, we check for comments and save their number. We echo it inside an <code class=\"lang-php\">h2<\/code> headline using the <code class=\"lang-php\">_n()<\/code> function, which gets the following parameters:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The singular form of the string.<\/li><li>The plural form.<\/li><li>A number which is used to display either the singular or plural form.<\/li><li>Text domain.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">We display the comments as an unordered list and hand over an array with the following arguments to <code class=\"lang-php\">wp_list_comments()<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code class=\"lang-php\">photographus_comments<\/code> as the <code class=\"lang-php\">callback<\/code> function to display comments. Because using a custom callback is optional, I will not go into that function \u2013 you can take a look at it <a href=\"https:\/\/florianbrinkmann.com\/en\/wordpress-themes\/photographus\/reference\/functions\/photographus_comments\/\">in the code reference<\/a>.<\/li><li><code class=\"lang-php\">ul<\/code> as the list <code class=\"lang-php\">style<\/code>.<\/li><li><code class=\"lang-php\">comment<\/code> as <code class=\"lang-php\">type<\/code>, to only get the comments.<\/li><li><code class=\"lang-php\">$comment_args['number']<\/code> as the value for <code class=\"lang-php\">per_page<\/code>, to display the correct number of comments if the reactions should be split into multiple pages. Without that, we would, for example, get five comments and five pings on one page instead of ten comments and pings, if the setting for comment number per page is ten.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Counting and displaying the pings looks similar:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> ( ! empty( $comments_by_type&#91;<span class=\"hljs-string\">'pings'<\/span>] ) ) {\n\t<span class=\"hljs-comment\">\/**\n\t * Save the count of trackbacks and pingbacks.\n\t *\/<\/span>\n\t$trackback_number = count( $comments_by_type&#91;<span class=\"hljs-string\">'pings'<\/span>] ); ?&gt;\n\t<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"trackbacks-title\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"trackbacks-title\"<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> printf( <span class=\"hljs-comment\">\/* translators: Title for trackback list. 1=trackback number, 2=post title *\/<\/span>\n\t\t\t_n(\n\t\t\t\t<span class=\"hljs-string\">'%1$s Trackback on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t<span class=\"hljs-string\">'%1$s Trackbacks on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t$trackback_number,\n\t\t\t\t<span class=\"hljs-string\">'photographus'<\/span>\n\t\t\t),\n\t\t\tnumber_format_i18n( $trackback_number ),\n\t\t\tget_the_title() ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span><\/span>\n\n\t<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">ul<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"commentlist\"<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * Display the pings in short version.\n\t\t *\/<\/span>\n\t\twp_list_comments( &#91;\n\t\t\t<span class=\"hljs-string\">'type'<\/span>       =&gt; <span class=\"hljs-string\">'pings'<\/span>,\n\t\t\t<span class=\"hljs-string\">'short_ping'<\/span> =&gt; <span class=\"hljs-keyword\">true<\/span>,\n\t\t\t<span class=\"hljs-string\">'per_page'<\/span>   =&gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>],\n\t\t] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">ul<\/span>&gt;<\/span><\/span>\n&lt;?php }<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">If we would want, we could go further and also separate pingbacks and trackbacks, using <code class=\"lang-php\">$comments_by_type['pingback']<\/code> and <code class=\"lang-php\">$comments_by_type['trackback']<\/code> instead of <code class=\"lang-php\">$comments_by_type['pings']<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now the last part:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">\t\t<span class=\"hljs-comment\">\/**\n\t\t * Only show the comments navigation if one of the reaction counts\n\t\t * is larger than the set number of comments per page. Necessary because\n\t\t * of our separation. Otherwise, the navigation would also be displayed if\n\t\t * we should display 4 comments per page and have 3 comments and 2 trackbacks.\n\t\t *\/<\/span>\n\t\t<span class=\"hljs-keyword\">if<\/span> ( ( isset( $trackback_number ) &amp;&amp; $trackback_number &gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>] ) || ( isset( $comment_number ) &amp;&amp; $comment_number &gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>] ) ) {\n\t\t\tthe_comments_navigation();\n\t\t}\n\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * Display comments closed hint if comments are closed but we already have comments.\n\t\t *\/<\/span>\n\t\t<span class=\"hljs-keyword\">if<\/span> ( ! comments_open() &amp;&amp; get_comments_number() ) { ?&gt;\n\t\t\t<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"nocomments\"<\/span>&gt;<\/span><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> _e( <span class=\"hljs-string\">'Comments are closed.'<\/span>, <span class=\"hljs-string\">'photographus'<\/span> ); <span class=\"hljs-meta\">?&gt;<\/span><\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span><\/span>\n\t\t&lt;?php }\n\t} <span class=\"hljs-comment\">\/\/ End if().<\/span>\n\n\t<span class=\"hljs-comment\">\/**\n\t * Display comment form with modified submit label.\n\t *\/<\/span>\n\tcomment_form( &#91;\n\t\t<span class=\"hljs-string\">'label_submit'<\/span> =&gt; __( <span class=\"hljs-string\">'Submit Comment'<\/span>, <span class=\"hljs-string\">'photographus'<\/span> ),\n\t] ); ?&gt;\n&lt;<span class=\"hljs-regexp\">\/aside&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">We check if the comment or ping count is higher than the number from the backend setting, and display the navigation in that case. After that, we conditionally display the comments closed hint and the comment form.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, the complete <code class=\"lang-php\">comments.php<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n<span class=\"hljs-comment\">\/**\n * Comments template.\n *\n * <span class=\"hljs-doctag\">@version<\/span> 1.0.0\n *\n * <span class=\"hljs-doctag\">@package<\/span> Photographus\n *\/<\/span>\n\n<span class=\"hljs-keyword\">if<\/span> ( post_password_required() ) {\n\t<span class=\"hljs-keyword\">return<\/span>;\n} <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">aside<\/span> <span class=\"hljs-attr\">aria-labelledby<\/span>=<span class=\"hljs-string\">\"aside\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"comments-area\"<\/span>&gt;<\/span>\n\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> <span class=\"hljs-keyword\">if<\/span> ( have_comments() ) {\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * We cannot use the second parameter from comments_template()\n\t\t * to separate the reactions because if they are\n\t\t * broken on multiple pages, the count() would only return\n\t\t * the number of comments and pings which are displayed\n\t\t * on the current page, not the total.\n\t\t *\n\t\t * Because of that, we use our own function to get the comments by type.\n\t\t *\/<\/span>\n\t\t$comments_by_type = photographus_get_comments_by_type();\n\t\t<span class=\"hljs-keyword\">if<\/span> ( ! <span class=\"hljs-keyword\">empty<\/span>( $comments_by_type&#91;<span class=\"hljs-string\">'comment'<\/span>] ) ) {\n\t\t\t<span class=\"hljs-comment\">\/**\n\t\t\t * Save the comment count.\n\t\t\t *\/<\/span>\n\t\t\t$comment_number = count( $comments_by_type&#91;<span class=\"hljs-string\">'comment'<\/span>] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"comments-title\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"comments-title\"<\/span>&gt;<\/span>\n\t\t\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> printf( <span class=\"hljs-comment\">\/* translators: Title for comment list. 1=comment number, 2=post title *\/<\/span>\n\t\t\t\t\t_n(\n\t\t\t\t\t\t<span class=\"hljs-string\">'%1$s Comment on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t\t\t<span class=\"hljs-string\">'%1$s Comments on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t\t\t$comment_number,\n\t\t\t\t\t\t<span class=\"hljs-string\">'photographus'<\/span>\n\t\t\t\t\t),\n\t\t\t\t\tnumber_format_i18n( $comment_number ),\n\t\t\t\t\tget_the_title() ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span>\n\n\t\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">ul<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"commentlist\"<\/span>&gt;<\/span>\n\t\t\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\t\t\t\t<span class=\"hljs-comment\">\/**\n\t\t\t\t * We need to specify the per_page key because otherwise\n\t\t\t\t * the separated reactions would not be broken correctly into\n\t\t\t\t * multiple pages.\n\t\t\t\t *\/<\/span>\n\t\t\t\twp_list_comments( &#91;\n\t\t\t\t\t<span class=\"hljs-string\">'callback'<\/span> =&gt; <span class=\"hljs-string\">'photographus_comments'<\/span>,\n\t\t\t\t\t<span class=\"hljs-string\">'style'<\/span>    =&gt; <span class=\"hljs-string\">'ul'<\/span>,\n\t\t\t\t\t<span class=\"hljs-string\">'type'<\/span>     =&gt; <span class=\"hljs-string\">'comment'<\/span>,\n\t\t\t\t\t<span class=\"hljs-string\">'per_page'<\/span> =&gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>],\n\t\t\t\t] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">ul<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> }\n\t\t<span class=\"hljs-keyword\">if<\/span> ( ! <span class=\"hljs-keyword\">empty<\/span>( $comments_by_type&#91;<span class=\"hljs-string\">'pings'<\/span>] ) ) {\n\t\t\t<span class=\"hljs-comment\">\/**\n\t\t\t * Save the count of trackbacks and pingbacks.\n\t\t\t *\/<\/span>\n\t\t\t$trackback_number = count( $comments_by_type&#91;<span class=\"hljs-string\">'pings'<\/span>] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"trackbacks-title\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"trackbacks-title\"<\/span>&gt;<\/span>\n\t\t\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> printf( <span class=\"hljs-comment\">\/* translators: Title for trackback list. 1=trackback number, 2=post title *\/<\/span>\n\t\t\t\t\t_n(\n\t\t\t\t\t\t<span class=\"hljs-string\">'%1$s Trackback on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t\t\t<span class=\"hljs-string\">'%1$s Trackbacks on \u201c%2$s\u201d'<\/span>,\n\t\t\t\t\t\t$trackback_number,\n\t\t\t\t\t\t<span class=\"hljs-string\">'photographus'<\/span>\n\t\t\t\t\t),\n\t\t\t\t\tnumber_format_i18n( $trackback_number ),\n\t\t\t\t\tget_the_title() ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span>\n\n\t\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">ul<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"commentlist\"<\/span>&gt;<\/span>\n\t\t\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\t\t\t\t<span class=\"hljs-comment\">\/**\n\t\t\t\t * Display the pings in short version.\n\t\t\t\t *\/<\/span>\n\t\t\t\twp_list_comments( &#91;\n\t\t\t\t\t<span class=\"hljs-string\">'type'<\/span>       =&gt; <span class=\"hljs-string\">'pings'<\/span>,\n\t\t\t\t\t<span class=\"hljs-string\">'short_ping'<\/span> =&gt; <span class=\"hljs-keyword\">true<\/span>,\n\t\t\t\t\t<span class=\"hljs-string\">'per_page'<\/span>   =&gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>],\n\t\t\t\t] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">ul<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> }\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * Only show the comments navigation if one of the reaction counts\n\t\t * is larger than the set number of comments per page. Necessary because\n\t\t * of our separation. Otherwise, the navigation would also be displayed if\n\t\t * we should display 4 comments per page and have 3 comments and 2 trackbacks.\n\t\t *\/<\/span>\n\t\t<span class=\"hljs-keyword\">if<\/span> ( ( <span class=\"hljs-keyword\">isset<\/span>( $trackback_number ) &amp;&amp; $trackback_number &gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>] ) || ( <span class=\"hljs-keyword\">isset<\/span>( $comment_number ) &amp;&amp; $comment_number &gt; $comment_args&#91;<span class=\"hljs-string\">'number'<\/span>] ) ) {\n\t\t\tthe_comments_navigation();\n\t\t}\n\n\t\t<span class=\"hljs-comment\">\/**\n\t\t * Display comments closed hint if comments are closed but we already have comments.\n\t\t *\/<\/span>\n\t\t<span class=\"hljs-keyword\">if<\/span> ( ! comments_open() &amp;&amp; get_comments_number() ) { <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"nocomments\"<\/span>&gt;<\/span><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> _e( <span class=\"hljs-string\">'Comments are closed.'<\/span>, <span class=\"hljs-string\">'photographus'<\/span> ); <span class=\"hljs-meta\">?&gt;<\/span><\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> }\n\t} <span class=\"hljs-comment\">\/\/ End if().<\/span>\n\n\t<span class=\"hljs-comment\">\/**\n\t * Display comment form with modified submit label.\n\t *\/<\/span>\n\tcomment_form( &#91;\n\t\t<span class=\"hljs-string\">'label_submit'<\/span> =&gt; __( <span class=\"hljs-string\">'Submit Comment'<\/span>, <span class=\"hljs-string\">'photographus'<\/span> ),\n\t] ); <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">aside<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>Instead of listing all post reactions \u2013 comments, trackbacks, and pingbacks \u2013 in one list, I like to separate comments and pings (pingbacks and trackbacks) for the sake of clarity. That is not too difficult, but there are a few things to consider.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[115],"tags":[],"class_list":["post-3808","post","type-post","status-publish","format-standard","hentry","category-wordpress-snippets"],"wp-worthy-pixel":{"ignored":false,"public":"fb14d88ac30d4266a0eb7a4f529d4e85","server":"vg07.met.vgwort.de","url":"https:\/\/vg07.met.vgwort.de\/na\/fb14d88ac30d4266a0eb7a4f529d4e85"},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=3808"}],"version-history":[{"count":3,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3808\/revisions"}],"predecessor-version":[{"id":5871,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3808\/revisions\/5871"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=3808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=3808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=3808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}