您所需要做的就是编写一个快捷代码,并在其周围添加一个函数:
function get_post_details($atts) {
// Get the shortcode\'s attributes
$atts = shortcode_atts( array(
\'post\' => 0,
), $atts, \'get-post-details\' );
// Fetch the ID from $atts array
$id = $atts[\'post\'];
// Stop the shortcode if no ID is set
if ($id == \'0\') return \'Please provide a post ID.\';
// Get the title for this post
$data = get_the_title($id);
// Get the permalink for this post
$data .= get_the_permalink($id);
// Get the thumbnail for this post
$data .= get_the_post_thumbnail_url($id, \'thumbnail\');
// Return the data
return $data;
}
add_shortcode( \'get-post-details\', \'get_post_details\' );
现在,您可以使用
[get-post-details post="123"]
. 如果未设置ID,则将显示循环中当前帖子的详细信息。