wordpress中的动态mixitup插件

时间:2016-08-16 05:16:18

标签: php jquery wordpress mixitup

我正在尝试在WordPress中创建自己的主题。我将PSD文件转换为HTML,现在我想用WordPress使其动态化,我使用了混合插件,因为你知道它不是一个WordPress插件所以我试着让它自己动态,我用{{ 3}}教程,提供此问题的代码和视频。 正如你在图片中看到的那样,它必须显示我的类别,但显示' array'我找不到原因?

this

这是我的代码 首先,我使用名为books_category

的分类法创建名为book的帖子类型
function p2p2_register_book(){
    $labels = array(
        'name'               => _x( 'کتابخانه', 'books'),
        'singular_name'      => _x( 'کتاب', 'book' ),
        'add_new'            => _x( 'افزودن کتاب', '' ),
        'add_new_item'       => __( 'افزودن کتاب جدید' ),
        'edit_item'          => __( 'ویرایش کتاب' ),
        'new_item'           => __( 'کتاب جدید' ),
        'all_items'          => __( 'همه کتاب ها' ),
        'search_items'       => __( 'جست و جو کتاب' ),
        'not_found'          => _( 'کتاب یافت نشد' ),
        'not_found_in_trash' => __( 'کتاب در زباله دان یافت نشد' ),
        'parent_item_colon'  => '',
        'menu_name'          => 'کتابخانه'
    );
    $args=array(
            'labels'             => $labels,
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'query_var'          => true,
            'menu_position'      => 2,
            'rewrite'            => array( 'slug' => 'book' ),
            'capability_type'    => 'page',
            'has_archive'        => true,
            // 'hierarchical'       => false,
            'supports'           => array( 'title', 'editor', 'thumbnail', 'comments' ,'custom-fields'),
            // 'taxonomies'  => array( 'Books_category' ),

        );
    register_post_type('Book',$args);

}

    add_action('init', 'p2p2_register_book');

// ============================== Adding post toxonomy to library post ================
    function wp_library_post_taxonomy() {
    register_taxonomy(
        'books_category',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
        'book',                  //post type name
        array(
            'hierarchical'          => true,
            'label'                         => 'book Category',  //Display name
            'query_var'             => true,
            'show_admin_column'             => true,
            'rewrite'                       => array(
                'slug'                  => 'books_category', // This controls the base slug that will display before each term
                'with_front'    => true // Don't display the category base before
                )
            )
    );
}
    add_action( 'init', 'wp_library_post_taxonomy');
    include_once( 'mixitup-plug.php' );
    add_theme_support('post_thumbnails');
    add_image_size('Books_small_image',150,200,true); 

然后在教程中说我添加了这段代码以使其成为动态

<?php 
    function books_shortcode($atts){
         extract( shortcode_atts( array(
            'category' => ''
              ), $atts, '' ));


         $q= new WP_Query(
            array('posts_per_page'=> 30, 'post_type' => 'Book')
            );

         //library taxonomy query

         global $paged;
         global $post;
         $args = array(    
         'post_type' => 'Book',
         'paged' => $paged,
        ' posts_per_page' => -1,
        );

         $Books = new WP_Query($args);
         if(is_array($Books->posts) && !empty($Books->posts)) {

            foreach($Books->posts as $Books_post) {

                 $Books_taxs = wp_get_post_terms($Books_post->ID, 'Books_category', array("fields" => "all"));
                                  if(is_array($Books_taxs) && !empty($Books_taxs)) {
                    foreach($Books_taxs as $Books_tax) {
                        $Books_taxs[$Books_tax->slug] = $Books_tax->name;

                     }

             }
         }          
        }
        ?>

        <!--Category Filter-->

       <div class="filter-book">  
        <ul>
            <li class="filter active" data-filter="all">همه</li>
            <?php foreach($Books_taxs as $Books_tax_slug => $Books_tax_name): ?>


            <li class="filter" data-filter=".<?php echo $Books_tax_slug; ?>"><?php echo $Books_tax_name; ?></li>

            <?php endforeach; ?>
        </ul></div> 





        <!--End-->

<?php

    $list = '<div class="library-item">';
    while($q->have_posts()) : $q->the_post();
        $idd = get_the_ID();
        $small_image_url=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'Books_small_image');
        //Get Texanmy class        
        $item_classes = '';
        $item_cats = get_the_terms($post->ID, 'Books_category');
        if($item_cats):
        foreach($item_cats as $item_cat) {
            $item_classes .= $item_cat->slug . ' ';
        }
        endif;

        $single_link = 
        $list .= '    

                <div class="mix single-library cycology '.$item_classes.'">
                            <div>
                                <img src="'.$small_image_url[0].'">
                                <p class="text-center">کتاب جیبی موفقیت یک</p>
                            </div>

                </div>


                <div class="mix '.$item_classes.'" >'.get_the_content().'</div>        
        ';        
    endwhile;
    $list.= '</div>';
    wp_reset_query();
    return $list;
}
add_shortcode('Books', 'Books_shortcode');  
?>

这部分代码必定存在问题,因为此部分显示了类别

<div class="filter-book">  
        <ul>
            <li class="filter active" data-filter="all">همه</li>
            <?php foreach($Books_taxs as $Books_tax_slug => $Books_tax_name): ?>


            <li class="filter" data-filter=".<?php echo $Books_tax_slug; ?>"><?php echo $Books_tax_name; ?></li>

            <?php endforeach; ?>
        </ul></div> 

1 个答案:

答案 0 :(得分:0)

我找到答案就是单词问题。我使用Book而不是电话簿,所以它不起作用。