2016-04-28 84 views
1

我不知道在哪裏張貼此疑問,更新佈局..使用WordPress的主題定製選擇頁面模板預覽

我最近發現WordPress的‘主題定製’和我用它來使更容易爲客戶更新頁面。而不是標準的方式來編輯每個單獨的頁面,單擊更新,然後訪問該頁面以查看更改,我喜歡Theme Customizer如何自動預覽右側的更改。

我試圖讓我能在多大程度上與主題定製去我全力以赴在這之前的理解...

我創建了一個「主頁」設置/節/合照控制在這裏:

enter image description here

這裏是該代碼:

function prowordpress_customize_register($wp_customize) { 

    // Settings, Sections, and Controls are defined here 

    // HOME PAGE 

    $wp_customize->add_setting('home_page_text' , array(
     'default'   => 'This is the home page text', 
     'type'    => 'option', 
     'transport'   => 'refresh', 
    )); 
    $wp_customize->add_section('prowordpress_content_customizations' , array(
     'title'  => __('Home Page', 'prowordpress'), 
     'description' => __('Modify the Home Page', 'prowordpress'), 
     'priority' => 30, 
    )); 
    $wp_customize->add_control('home_page_text_control', array(
     'label'  => __('Home Page Text', 'prowordpress'), 
     'section' => 'prowordpress_content_customizations', 
     'settings' => 'home_page_text', 
     'type'  => 'textarea', 
    )); 


    $wp_customize->add_setting('home_page_template_select' , array(
     'default'   => 'test', 
     'type'    => 'option', 
     'transport'   => 'refresh', 
    )); 
    $wp_customize->add_control(
     new WP_Customize_Control(
      $wp_customize, 
      'home_page_template_select', 
      array(
       'label'   => __('Home page template:', 'blankwptheme'), 
       'section'  => 'prowordpress_content_customizations', 
       'settings'  => 'home_page_template_select', 
       'type'   => 'select', 
       'choices'  => array(
        'template_one' => __('Template Layout 1'), 
        'template_two' => __('Template Layout 2') 
       ) 
      ) 
     ) 
    ); 

} 

add_action('customize_register', 'prowordpress_customize_register'); 

你可以在截圖中看到我添加了一個選擇菜單「主頁模板「...

是否有可能我可以設置它,客戶端可以從這個選擇菜單中選擇現有的」頁面模板「,然後讓頁面預覽/佈局在右側自動繼承頁面模板設置並實時調整佈局?

同樣,我只是試圖瞭解這是否可行,以及是否有人嘗試過類似的東西。我意識到這可能需要一些AJAX或沿着這些線。

感謝您的幫助!

回答

0

是的,你可以。我在自己的主題中完成了這種佈局選擇。

在你的PHP文件,你需要做這樣的事情 -

<?php if (get_option('home_page_template_select') === 'template_one') { 

get_template_part('layouts/template-one'); ?> 

我希望幫助。