2017-02-28 61 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()函数从前端获取所有数据。

相关问题