Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress作为函数获取帖子_Php_Wordpress - Fatal编程技术网

Php 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();

嗨,我正试图创建一个函数来显示wordpress管理菜单中的帖子列表,但因为我在同一页面上调用了该函数几次,所以我需要添加一些额外的语句,但它破坏了输出,我不知道为什么

以下是我当前输出基本信息的代码:

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"; ?>