我正在使用高級自定義字段(ACF)來允許用戶從頁面列表中進行選擇,然後將顯示相應頁面的標題,摘錄和鏈接。ACF和帖子對象ID未能顯示正確的內容
由於某些原因,這是拉取當前帖子的摘錄而不是相關的帖子ID。根據需要標題和固定字詞。我想要一些幫助。
感謝, 傑弗裏
<?php
/*
// Adding our custom content output
/*
* Loop through post objects (assuming this is a multi-select field) (don't setup postdata)
* Using this method, the $post object is never changed so all functions need a second parameter of the post ID in question.
*/
add_action('genesis_entry_content', 'genesis_project_list', 10, 2);
add_action('genesis_post_content', 'genesis_project_list', 10, 2);
// The Custom Content output function
function genesis_project_list() {
$post_objects = get_field('acf_selected_projects');
if($post_objects): ?>
<ul style="list-style:none;">
<?php foreach($post_objects as $post_object): ?>
<li style="list-style:none;">
<h3><a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a></h3>
<span><?php echo get_the_excerpt($post_object->ID); ?></span>
<a href="<?php echo get_permalink($post_object->ID); ?>">Read more...</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif;
}
genesis();
請張貼'get_the_excerpt()'函數的代碼,因爲它可能是出現問題的地方,上面的代碼似乎看起來不錯。 –
剛發現'get_the_excerpt()'是一個內置的Wordpress函數,我錯誤地認爲它是你網站的一部分)) –
@ mik-t是的,它是核心功能。我仍然不明白爲什麼我的原始代碼不起作用。令人高興的是,賈裏德有另一種解決方案。 – jeffreyd00