2017-02-28 66 views
0

您好,我有一項任務是將一個FAQ模塊添加到一個worpress項目中。我是wordpress新手。 我的客戶說明如下:「從正確的地方獲取不使用簡碼的常見問題。」 。這條指令是什麼意思,我該怎麼做?如何在沒有簡碼的情況下在wordpress中實現FAQ

我試着把FAQ模塊,但它根據此代碼生成短代碼。我如何把它無需使用簡碼..我的代碼是

<?php 
    add_action('init', function() { 

     $labels = array(
      'name' => _x('FAQ', 'post type general name'), 
      'singular_name' => _x('Question', 'post type singular name'), 
      'add_new' => _x('Add New Question', 'Question'), 
      'add_new_item' => __('Add New Question'), 
      'edit_item' => __('Edit Question'), 
      'new_item' => __('New Question'), 
      'all_items' => __('All FAQ Questions'), 
      'view_item' => __('View Question'), 
      'search_items' => __('Search FAQ'), 
      'not_found' => __('No FAQ found'), 
      'not_found_in_trash' => __('No FAQ found in Trash'), 
      'parent_item_colon' => '', 
      'menu_name' => 'FAQ' 
     ); 

     $args = array(
      'labels' => $labels, 
      'public' => true, 
      'publicly_queryable' => true, 
      'show_ui' => true, 
      'show_in_menu' => true, 
      'query_var' => true, 
      'rewrite' => true, 
      'capability_type' => 'post', 
      'has_archive' => true, 
      'hierarchical' => false, 
      'menu_position' => null, 
      'supports' => array('title', 'editor', 'page-attributes') 
     ); 
     register_post_type('FAQ', $args); 
    }); 

    add_action('wp_enqueue_scripts', 'wptuts_enqueue'); 

    function wptuts_enqueue() { 
     wp_register_style('wptuts-jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/south-street/jquery-ui.css'); 
     wp_enqueue_style('wptuts-jquery-ui-style'); 

     wp_register_script('wptuts-custom-js', get_template_directory_uri() . '/faq/faq.js', array('jquery','jquery-ui-accordion'), '', true); 
     wp_enqueue_script('wptuts-custom-js'); 
    } 




    add_shortcode('faq', function() { 

     $posts = get_posts(array( //Get the FAQ Custom Post Type 
      'numberposts' => 10, 
      'orderby' => 'menu_order', 
      'order' => 'ASC', 
      'post_type' => 'faq', 
     )); 

     $faq = '<style type="text/css"> 
     .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default{ 
      border-bottom : 1px solid #327e04; 
      background: #F7F7F7; 
      font-weight: bold; 
      color: #ffffff; 
      border-bottom: 4px solid red; 
     } 

     .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { 
      -moz-border-radius-bottomright: 0px; 
      -webkit-border-bottom-right-radius: 0px; 
      -khtml-border-bottom-right-radius: 0px; 
      border-bottom-right-radius: 0px; 
      border-radius: 0px; 
      border-bottom: 4px solid red; 
     } 

     address, blockquote, dl, fieldset, figure, h1, h2, h3, h4, h5, h6, hgroup, hr, ol, p, pre, table, ul{ 
      margin-bottom: 0rem; 
      /*border-bottom: 4px solid red;*/ 
     } 

     .ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-tr { 
      -moz-border-radius-topright: 0px; 
      -webkit-border-top-right-radius: 0px; 
      -khtml-border-top-right-radius: 0px; 
      border-top-right-radius: 0px; 
      /*border-bottom: 4px solid #F7F7F7;*/ 
     } 

     .ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl { 
      -moz-border-radius-topleft: 0px; 
      -webkit-border-top-left-radius: 0px; 
      -khtml-border-top-left-radius: 0px; 
      border-top-left-radius: 0px; 
     } 

     .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { 
      border: 0px solid #327e04; 
      border-top: 2px solid #C0C0C0; 
      border-bottom: 2px solid #C0C0C0; 
     } 

     .ui-widget-content { 
      border: 0px solid #F7F7F7; 
      background: #F7F7F7; 
      color: #312e25; 
      border-bottom: 2px solid #C0C0C0; 
     } 

     .ui-accordion .ui-accordion-header { 
      cursor: pointer; 
      position: relative; 
      margin-top: -2px; 
      zoom: 1; 
     } 

     .ui-accordion .ui-accordion-content { 
      padding: 1em 2.2em; 
      border-top: 0; 
      margin-top: -3px; 
      position: relative; 
      top: 1px; 
      margin-bottom: -3px; 
     } 

     .ui-accordion .ui-accordion-header .ui-icon { 
      position: absolute; 
      left: initial; 
      top: 50%; 
      margin-top: -8px; 
      width: 56px; 
      height: 56px; 
     } 

     .ui-accordion .ui-accordion-header .ui-icon { 
      position: absolute; 
      right: .5em !important; 
     } 

     .ui-state-default .ui-icon { 
      background-image: url(http://freevector.co/wp-content/uploads/2014/08/54785-down-arrow.png); 
      right: .5em !important; 
      background-position: 0px -20px; 
      background-size: 100% 100%; 
     } 

     .ui-state-active .ui-icon { 
      background-image: url(http://www.seeicons.com/images/iconstore/512/seeicons__57808be438471.png); 
      right: .5em !important; 
      background-position: 0px 0px; 
      background-size: 100% 100%; 
     } 

     .ui-icon-triangle-1-e { 
      background-position: 0px -20px; 
     } 

     .ui-icon-triangle-1-s { 
      background-position: -0px -20px; 
     } 


    </style> <div id="wptuts-accordion" >'; //Open the container 
     foreach ($posts as $post) { // Generate the markup for each Question 
      $faq .= sprintf(('<h3><a href="">%1$s</a></h3><div>%2$s</div>'), 
       $post->post_title, 
       wpautop($post->post_content) 
      ); 
     } 
     $faq .= '</div>'; //Close the container 



     return $faq; //Return the markup. 
    }); 

    ?> 
+0

這不是一個短碼這是自定義後類型顯示在管理方面 –

+0

這個代碼,我做了一個名爲「常見問題解答」我插入 – henrybbosa

+0

WordPress的頁面上的內容區域,但是這就是我的客戶希望不是簡碼.. – henrybbosa

回答

-1

你可以把這個代碼只對你的主題的function.php

add_action('init', function() { 

    $labels = array(
     'name' => _x('FAQ', 'post type general name'), 
     'singular_name' => _x('Question', 'post type singular name'), 
     'add_new' => _x('Add New Question', 'Question'), 
     'add_new_item' => __('Add New Question'), 
     'edit_item' => __('Edit Question'), 
     'new_item' => __('New Question'), 
     'all_items' => __('All FAQ Questions'), 
     'view_item' => __('View Question'), 
     'search_items' => __('Search FAQ'), 
     'not_found' => __('No FAQ found'), 
     'not_found_in_trash' => __('No FAQ found in Trash'), 
     'parent_item_colon' => '', 
     'menu_name' => 'FAQ' 
    ); 

    $args = array(
     'labels' => $labels, 
     'public' => true, 
     'publicly_queryable' => true, 
     'show_ui' => true, 
     'show_in_menu' => true, 
     'query_var' => true, 
     'rewrite' => true, 
     'capability_type' => 'post', 
     'has_archive' => true, 
     'hierarchical' => false, 
     'menu_position' => null, 
     'supports' => array('title', 'editor', 'page-attributes') 
    ); 
    register_post_type('faq', $args); 
}); 

它爲您創建自定義後類型,那麼你可以在這裏添加你的常見問題與帖子相同,並使用WP_Query()函數從前端獲取所有數據。

相關問題