只需构建一个包含一些查询参数的链接:
printf(
\'<a href="http://example.com/all-comments?pid=%s">All comments</a>\'
,get_the_ID()
);
然后添加一个永久链接为的页面
all-comments
, 所以你有目标。
在这里,您可以附加一个模板,如下所示(只是一个要处理的基础):
<?php
/**
* Template Name: All Comments
*/
// Abort if we got no `pid` query arg and redirect
if ( ! isset( get_query_arg( \'pid\' ) ) )
{
// We got no referer, so we don\'t know where to go: Send visitor to home
if (
! isset ( $_SERVER["HTTP_REFERER"] )
OR ! strstr( $_SERVER["HTTP_REFERER"], home_url( \'/\' ) )
)
exit( wp_redirect( home_url( \'/\' ) ) );
exit( wp_redirect( $_SERVER["HTTP_REFERER"] ) );
}
// Do something with our comments.
// So far we just throw some debug output to get insights and see if it\'s working:
echo \'<pre>\'.var_export( get_comments( array( \'post_id\' => get_query_arg( \'pid\' ) ) ), true ).\'</pre>\';