Php Wordpress作为函数获取帖子
嗨,我正试图创建一个函数来显示wordpress管理菜单中的帖子列表,但因为我在同一页面上调用了该函数几次,所以我需要添加一些额外的语句,但它破坏了输出,我不知道为什么 以下是我当前输出基本信息的代码:Php Wordpress作为函数获取帖子,php,wordpress,Php,Wordpress,嗨,我正试图创建一个函数来显示wordpress管理菜单中的帖子列表,但因为我在同一页面上调用了该函数几次,所以我需要添加一些额外的语句,但它破坏了输出,我不知道为什么 以下是我当前输出基本信息的代码: function test() { // The Query query_posts( array ('posts_per_page' => -1 ) ); // The Loop while ( have_posts() ) : the_post();
function test() {
// The Query
query_posts( array ('posts_per_page' => -1 ) );
// The Loop
while ( have_posts() ) : the_post();
?>
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option>
<?php endwhile;
// Reset Query
wp_reset_query();
}
功能测试(){
//询问
查询帖子(数组('posts\u per\u page'=>-1));
//环路
while(have_posts()):the_post();
?>
\u permalink()打印值,get\u permalink()返回值
试试这个
更改以下行
if($select == the_permalink()) { $selected = " selected"; }
到
这条线到
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option><?php echo "\n"; ?>
function test($select) {
// The Query
query_posts( array ('posts_per_page' => -1 ) );
// The Loop
while ( have_posts() ) : the_post();
if ($select == the_permalink()) { $selected = " selected"; }
?>
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option><?php echo "\n"; ?>
<?php endwhile;
// Reset Query
wp_reset_query();
}
<select>
<?php test("..GET Permalink from Database.."); ?>
</select>
<select>
http://website/posttitle1<option value="http://website/posttitle1">POST TITLE 1</option>
http://website/posttitle2<option value="http://website/posttitle2">POST TITLE 2</option>
http://website/posttitle3<option value="http://website/posttitle2">POST TITLE 3</option>
</select>
if($select == the_permalink()) { $selected = " selected"; }
if ($select == get_permalink()) { $selected = " selected"; }
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option><?php echo "\n"; ?>
<option value="<?php echo get_permalink() ?>"><?php echo get_the_title(); ?></option><?php echo "\n"; ?>