2012-07-02 26 views
0

大家好我是新來的wp插件開發。到目前爲止,除了這個表格選擇部分似乎在踢我的腦袋外,我的表現很好。我試圖在選擇字段中顯示最近發佈的帖子列表,供管理員選擇並執行一些操作,但標題不會顯示。我在單選按鈕甚至文本字段中試過這個,但沒有得到任何結果。請問,我在這個表格中錯過了什麼?如何使用get_posts()和表單select

<form method="post"><select name="Article"> 
$args = array('numberposts' => 10, 'order'=> 'ASC', 'orderby' => 'title'); 
$postslist = get_posts($args);  foreach ($postslist as $post) : setup_postdata($post); 

echo'<option value='".the_ID()."'>'".the_title()."'</option>'; 
endforeach; 
echo"</select></form>"; 

回答

0

我現在不能測試,但有幾種可能性。

首先,the_ID()將立即回顯該值 - 在連接過程中無法正常工作。您需要改爲get_the_ID()

其次,當您的echooption時,您報價的匹配看起來很奇怪。假設你所要的輸出是這樣的

<option value="1">Title</option> 

echo應該

echo '<option value="' . get_the_ID() . '">' . get_the_title() . '</option>'; 
0

它將無法正常工作,你會在一個串聯的中間喜歡。您需要改爲get_the_ID($post)

<?php 
     $args = array('numberposts=>-1&order=>ASC&orderby=>title'); 
     $postslist = get_posts($args);  foreach ($postslist as $post) : setup_postdata($post); 
     echo '<option value="'.get_the_id($post).'">'.get_the_title($post).'</option>'; 
     endforeach; 
?> 

echo應該

echo '<option value="' . get_the_ID($post) . '">' . get_the_title($post) . '</option>';