2017-07-12 30 views
0

我想学习如何建立一个动态的自定义文章类型WordPress插件,我米用这个老指南:动态自定义后类型WordPress的

https://code.tutsplus.com/tutorials/building-a-dynamic-custom-post-type-plugin--wp-26322

,但我不能让它正常工作,我能够创建动态自定义帖子类型,但是每次我注册一个新的自定义帖子类型时,支持部分的'标题','编辑','作者'等都会在之前创建的自定义帖子类型中更改。

(我发现这个插件,使用相同的指导创建,但是它具有相同的反常行为

这是插件:https://wordpress.org/plugins/dynamic-custom-post-type/

要充分说明我得到了现场编辑,作者等,或每次添加或编辑另一个自定义帖子类型时的其他字段,即使数据库说对于该自定义帖子类型它应该关闭。

任何帮助,将不胜感激。

回答

0

自定义后类型只创建复制下面的代码粘贴&在你的主题function.php文件:

add_action('init', 'wfd_team'); 

function wfd_team() { 
    $labels = array(
     'name' => 'Member', 
     'singular_name' => 'Member', 
     'menu_name' => 'Teams', 
     'name_admin_bar' => 'Team', 
     'add_new' => 'Add New', 
     'add_new_item' => 'Add New Member', 
     'new_item' => 'New Member', 
     'edit_item' => 'Edit Member', 
     'view_item' => 'View Member', 
     'all_items' => 'All Members', 
     'search_items' => 'Search Members', 
     'parent_item_colon' => 'Parent Members:', 
     'not_found' => 'No Member found.', 
     'not_found_in_trash' => 'No Member found in Trash.' 
    ); 

    $args = array(
     'labels' => $labels, 
     'public' => true, 
     'rewrite' => array('slug' => 'wfd-team'), 
     'has_archive' => true, 
     'menu_position' => 20, 
     'menu_icon' => 'dashicons-groups', 
     'supports' => array('title', 'editor', 'author', 'thumbnail') 
    ); 
    register_post_type('wfd_team', $args); 
} 

显示自定义后输入你的文章或网页通过短代码,下面添加主题验证码function.php &简码[wfd_team_short]粘贴您的文章或页面。

function wfd_team_fun() { 
    $query = new WP_Query(
      array('post_type' => 'wfd_team', 
     'posts_per_page' => 3, 'post_status' => 'publish', 
     'paged' => $paged, 'order' => 'DESC' 
    )); 

    if ($query->have_posts()) : 
     ?> 
     <?php while ($query->have_posts()) : $query->the_post(); ?> 
      <div class="col-sm-4"> 
       <div style="text-align: center;"> 
        <?php 
        if (has_post_thumbnail()) { 
         the_post_thumbnail('medium_large'); 
        } 
        ?> 
       </div> 
       <h2 style="text-align: center; font-weight: 700!important;"><?php the_title(); ?></h2> 
       <p style="text-align: justify;"> 
        <?php 
        echo wp_trim_words(get_the_content(),30); 
        ?> 
<a href="<?php the_permalink(); ?>">Read More</a> 
       </p> 
      </div> 
      <?php 
     endwhile; 
     wp_reset_postdata(); 
     ?> 
     <!-- show pagination here --> 
    <?php else : ?> 
     <!-- show 404 error here --> 
    <?php endif; ?> 


    <?php 
} 

add_shortcode('wfd_team_short', 'wfd_team_fun'); 
+0

[仅有代码的答案通常会被忽视。](https://meta.stackexchange.com/questions/148272) – Litty