Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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_Wordpress Theming - Fatal编程技术网

Php 列出wordpress主题定制器中的帖子

Php 列出wordpress主题定制器中的帖子,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,你好。我正在创建一个Wordpress主题,想知道是否有人知道如何在主题定制器中列出我的一个自定义帖子类型。我有一个名为“幻灯片”的自定义帖子类型,它有自定义的元框等,专为幻灯片设计。我希望能够在customiser中的下拉列表中列出这些帖子。理想情况下,它们会像这样出现在阵列中。。。 'the_id'=>'幻灯片帖子标题' $wp_customize->add_setting( 'slideshow-homepage',

你好。我正在创建一个Wordpress主题,想知道是否有人知道如何在主题定制器中列出我的一个自定义帖子类型。我有一个名为“幻灯片”的自定义帖子类型,它有自定义的元框等,专为幻灯片设计。我希望能够在customiser中的下拉列表中列出这些帖子。理想情况下,它们会像这样出现在阵列中。。。 'the_id'=>'幻灯片帖子标题'

            $wp_customize->add_setting(
              'slideshow-homepage',
              array(
                'default' => 'none',
               )
              );

            $wp_customize->add_control(
              'slideshow-homepage',
              array(
                'type' => 'select',
                'priority' => 3,
                'label' => 'Slideshow',
                'description' => '',
                'section' => 'homepage',
                'choices' => array(

                'somehow' => 'somehow',
                'list' => 'list',
                'all' => 'all',
                'custom' => 'custom',
                'post' => 'post',
                'types' => 'types',
                'of' => 'of',
                'type' => 'type',
                'slideshow' => 'slideshow'

                ),
              )
            );
非常感谢各位。刘易斯使用

要同时添加空字段,请执行以下操作:

$posts = array_reduce( 
        get_posts( 'post_type=slideshow&posts_per_page=-1' ), 
        function( $result, $item ) { 
            $result[$item->ID] = $item->post_title;
            return $result;
        }
    );
    $none = array('' => 'None');
    $choices = $none + $posts;

    $wp_customize->add_control('slideshow_control', array(
        'label'      => __('Choose Slideshow', 'themename'),
        'section'    => 'slideshow_option',
        'settings'   => 'slideshow_settings',
        'type' => 'select',
        'choices' => $choices
    )); 

我不确定你的帖子类型叫什么。很高兴它成功了。非常好,谢谢你,你有没有可能知道如何在减少的数组中包含默认值?i、 e.“无”=>“无”…再次感谢你绝对的明星!我刚刚在php手册中查看了array_merge,但你让我明白了!我非常感谢像你这样知道你在说什么的人!很抱歉一直打扰你,我真的很抱歉,我非常感谢你的帮助。您可能知道一种获取帖子ID的方法,而不是让数组以递增方式列出数字作为ID。目前,我可以从下拉列表中选择并呈现ID,但当我添加“slideshow”类型的新帖子时,所选ID会发生变化。这有意义吗?哦,我明白了。我更新了我的答案。使用
+
运算符代替
数组\u merge
$posts = array_reduce( 
        get_posts( 'post_type=slideshow&posts_per_page=-1' ), 
        function( $result, $item ) { 
            $result[$item->ID] = $item->post_title;
            return $result;
        }
    );
    $none = array('' => 'None');
    $choices = $none + $posts;

    $wp_customize->add_control('slideshow_control', array(
        'label'      => __('Choose Slideshow', 'themename'),
        'section'    => 'slideshow_option',
        'settings'   => 'slideshow_settings',
        'type' => 'select',
        'choices' => $choices
    ));