我想在wordpress页面(page.php)上显示两篇文章,主文章和侧边栏中的次要文章。次要文章从具有帖子ID的自定义字段中检索。我使用此代码:显示带自定义字段的wordpress页面
<?php
$other_article = get_post_custom('secondaryarticle');
if ($other_article > 0) {
$show_article = get_post($other_article);
$article_content = $show_article->post_content;
echo $article_content;
}?>
每篇主要文章都有一个名为secondaryarticle的自定义字段,值是帖子ID(例如14)。代码运行时,php中没有错误消息,但没有显示文章内容。有小费吗?
你能告诉我什么是自定义字段secondaryarticle的价值?它是帖子ID还是帖子帖子? – Pranita
对不起,我迟到了,我想我会收到一封电子邮件,当我在这里收到答案时。次粒子字段将具有作为值的帖子ID,例如, 14. – Hansson