选项页面字段的简短路径 - Unyson框架

时间:2016-04-15 17:49:14

标签: php arrays wordpress frameworks

我使用框架设置页面创建了以下内容。

$options = array(
'page' => array(
    'title'   => __( 'Page settings', 'unyson' ),
    'type'    => 'box',
    'options' => array(
        'general-box' => array(
            'title'   => __( 'Title tab', 'unyson' ),
            'type'    => 'group',
            'options' => array(
                'header_select' => array(
                    'type'         => 'multi-picker',
                    'label'        => false,
                    'desc'         => false,
                    'picker'       => array(
                        'selected' => array(
                            'label'   => __( 'Select header', 'unyson' ),
                            'type'    => 'radio',
                            'choices' => array(
                                'text_header'  => __( 'Only page name', 'unyson' ),
                                'photo_header'  => __( 'Single photo', 'unyson' ),
                                'photo_slider_header' => __( 'Slider photo', 'unyson' ),
                                'youtube_background_header'  => __( 'YouTube background', 'unyson' ),
                                'video_local_background_header'  => __( 'Video file background', 'unyson' ),
                            ),
                        )
                    ),
                    'choices' => array(
                        'text_header'  => array(
                            'disable_transparent_header' => array(
                                'type'              => 'switch',
                                'label'             => __( 'Disable transparent header', 'unyson' ),
                            ),
                            'enabl_breadcrumbs' => array(
                                'type'              => 'switch',
                                'label'             => __( 'Disable breadcrumbs', 'unyson' ),
                            )
                        ),
                        'photo_header' => array(
                            'disable_transparent_header' => array(
                                'type'              => 'switch',
                                'label'             => __( 'Disable transparent header', 'unyson' ),
                            ),
                            'file_single_photo' => array(
                                'label'       => __( 'Photo Upload', 'unyson' ),
                                'type'        => 'upload',
                                'images_only' => true,
                            ),
                            'parallax_size_slider' => array(
                                'label'             => __( 'Parallax size', 'unyson' ),
                                'type'              => 'short-text',
                                'value'             => 11,
                            ),
                        ),
                        'photo_slider_header' => array(
                            'disable_transparent_header' => array(
                                'type'              => 'switch',
                                'label'             => __( 'Disable transparent header', 'unyson' ),
                            ),
                            'webcam'                => array(
                                'type'              => 'switch',
                                'label'             => __( 'Webcam', 'unyson' ),
                            )
                        ),
                        'youtube_background_header' => array(
                            'disable_transparent_header' => array(
                                'type'              => 'switch',
                                'label'             => __( 'Disable transparent header', 'unyson' ),
                            ),
                            'youtube_header_link'=> array(
                                'label'             => __( 'Youtube video link', 'unyson' ),
                                'type'              => 'text'
                            ),
                        ),
                        'video_local_background_header' => array(
                            'disable_transparent_header' => array(
                                'type'              => 'switch',
                                'label'             => __( 'Disable transparent header', 'unyson' ),
                            ),
                            'file_mp4' => array(
                                'label'       => __( 'MP4 Upload', 'unyson' ),
                                'type'        => 'upload',
                                'files_ext' => array( 'mp4' ),
                                'images_only' => false,
                            ),
                            'ogg_upload' => array(
                                'label'       => __( 'OGG Upload', 'unyson' ),
                                'type'        => 'upload',
                                'files_ext' => array( 'ogg' ),
                                'images_only' => false,
                            ),
                            'webm_upload' => array(
                                'label'       => __( 'WEBM Upload', 'unyson' ),
                                'type'        => 'upload',
                                'files_ext' => array( 'webm' ),
                                'images_only' => false,
                            )
                        ),
                    ),
                    'show_borders' => false,
                ),
            )
        ),
    )
)

page.php文件如下所示:

<?php get_header(); ?>
        <?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php
                    global $post;

                    $options = fw_get_db_post_option('header_select');
                    $options = fw_get_db_post_option($post->ID );

                    if (array_key_exists('header_select', $options) && array_key_exists('selected', $options['header_select'])) {
                        switch ($options['header_select']['selected']) {

                            case 'photo_header':
                                    get_template_part( 'partials/content', 'header-photo' );
                                    break;

                            case 'photo_slider_header':
                                    get_template_part( 'partials/content', 'header-photoslider' );
                                    break;

                            case 'youtube_background_header':
                                    get_template_part( 'partials/content', 'header-videoyoutube' );
                                    break;

                            case 'video_local_background_header':
                                    get_template_part( 'partials/content', 'header-videolocal' );
                                    break;

                            default:
                                get_template_part( 'partials/content', 'header-text' );
                                break;
                        }
                    } else {

                    }
                ?>
                <?php the_content();?>
            <?php endwhile;?>
        <?php else : ?>

        <?php endif; ?>

如何获取php文件中最短路径的值(例如:content-header-text.php,content-header-photo.php)?

我的表:

array
(
    [selected] => 'photo_header'
    [text_header] => array
    (
        [disable_transparent_header] => false
        [enabl_breadcrumbs] => false
    )
    [photo_header] => array
    (
        [disable_transparent_header] => false
        [file_single_photo] => array
        (
            [attachment_id] => '61'
            [url] => '[my_website_link]/wp-content/uploads/2016/04/hero.jpg'
        )
        [parallax_size_slider] => '11'
    )
    [photo_slider_header] => array
    (
        [disable_transparent_header] => false
        [webcam] => false
    )
    [youtube_background_header] => array
    (
        [disable_transparent_header] => false
        [youtube_header_link] => ''
    )
    [video_local_background_header] => array
    (
        [disable_transparent_header] => false
        [file_mp4] => ''
        [ogg_upload] => ''
        [webm_upload] => ''
    )
)

如何获取变量值,例如。 [url]来自数组&#39; file_single_photo&#39;?

以下代码返回null:

$image_header_url = fw_get_db_post_option(get_the_ID(), 'photo_header');

0 个答案:

没有答案