我知道如何创建超链接以及如何为未发布的帖子创建永久链接(如果我想通过电子邮件发送)。
我想做的是安排一系列帖子,并将列表或表格放在一个带有标题的帖子时间表的小部件中,并且一旦发布目标帖子,标题就可以用作超链接,并作为纯文本呈现为纯文本。您可以使用主题
functions.php
functions.php
文件:
function conditional_post_link($atts) {
$atts = shortcode_atts(array(
'id' => '',
'text' => 'Post Title'
), $atts, 'post_link');
$post = get_post($atts['id']);
if ($post && $post->post_status === 'publish') {
return '<a href="' . get_permalink($atts['id']) . '">' . esc_html($atts['text']) . '</a>';
} else {
return esc_html($atts['text']);
}
}
add_shortcode('post_link', 'conditional_post_link');
在您的帖子,小部件或页面编辑器中,使用这样的快捷代码:[POST_LINK ID =“ 123” text =“即将到来的帖子标题”]replace
123
带有帖子ID,并带有实际标题的“即将到来的帖子标题”。