你可能会逍遥法外shortcodes:
add_shortcode(\'title\', function ($atts, $content = null) {
$atts = shortcode_atts([
\'id\' => null,
], $atts);
$title = \'\';
if (!empty($atts[\'id\'])) {
$title = get_the_title($atts[\'id\']);
}
return $title;
});
add_shortcode(\'content\', function ($atts, $content = null) {
$atts = shortcode_atts([
\'id\' => null,
], $atts);
$content = \'\';
if (!empty($atts[\'id\'])) {
$post = get_post($atts[\'id\']);
// Full content, disregarding "read more" tags:
$content = str_replace(\'<!--more-->\', \'\', $post->post_content);
$content = apply_filters(\'the_content\', $content);
// Alternatively, simply use this which respects "read more" tags.
#$content = apply_filters(\'the_content\', $content);
}
return $content;
});
将其放入函数中。您正在使用的主题的php。
在您的页面中,您可以使用[title id="42"]
和[content id="42"]
, 哪里42
是要显示的帖子的ID。