0

嗨,我在 wordpress 中工作,到目前为止,我能够为我的帖子循环显示不同的大小,但我在每列中一直只有 1 个帖子。我已经尝试将多个帖子循环添加到我们的 php 中,并且还设置了 css 的大小,但每列仍然只有 1 个帖子。

    /* returns carousel html and js embed code */
function get_carousel($id, $get_first_post) 
{

    $id = intval($id);
    if ($id <= 0)
        die ('tc-oops7');   

    global $wpdb;       
    $carousels_table = $wpdb->prefix . 'touchcarousels';
    $slider_row = $wpdb->get_row("SELECT * FROM $carousels_table WHERE id = $id", ARRAY_A);     

    if(!$slider_row) {
        return "<p>Oops, TouchCarousel with ID $id not found.</p>";
    }

    $carousel_html = '';
    $skin_name = $slider_row['skin'];
    $css_classes = $slider_row['css_classes'];
    $carousel_html .= "<div id=\"touchcarousel-$id\" class=\"touchcarousel $skin_name $css_classes\" style=\"width:{$slider_row['width']};  height:{$slider_row['height']}; \">\n";
    $carousel_html .= "\t<ul class=\"touchcarousel-container\">\n";

    global $post;
    $args = array(
        'numberposts'     => intval($slider_row['max_posts']),
        'posts_per_page'  => intval($slider_row['max_posts']),
        'offset'          => 0,
        'cat'             => $slider_row['post_categories'],
        'orderby'         => $slider_row['post_orderby'],
        'order'           => 'DESC',
        'include'         => '',
        'exclude'         => '',
        'meta_key'        => '',
        'meta_value'      => '',
        'post_type'       => $slider_row['post_type'],
        'post_mime_type'  => '',
        'post_parent'     => '',
        'post_status'     => 'publish' );


    $post_taxonomies_arr = (array)json_decode (stripslashes($slider_row['post_categories']));
    $taxonomies_query_arr = array();

    $taxonomies_query_arr['relation'] = $slider_row['post_relation'];

    $count = 0;
    foreach ($post_taxonomies_arr as  $key => $taxonomy ) {
        $taxonomies_query_arr[$count]['taxonomy'] = $key;
        $taxonomies_query_arr[$count]['terms'] = $taxonomy;
        $taxonomies_query_arr[$count]['field'] = 'slug';
        $count++;
    }

    $args['tax_query'] = $taxonomies_query_arr;

    $the_query = new WP_Query( $args );

    if($get_first_post) {
        $the_query->have_posts();
        $the_query->the_post();
        $this->current_loop_post = $post;
        return $post;
    }


    if($the_query->have_posts()) {
        $layout_code = stripslashes($slider_row['layout_code']);
        while ($the_query->have_posts()) : $the_query->the_post();$this->current_loop_post = $post; 
        $do_not_duplicate[] = $post->ID;
            $carousel_html .= "\t\t<li class=\"touchcarousel-item\">\n";
            $carousel_html .= preg_replace_callback ("/\[tco.*?\](.*?)\[\/tco\]/", array($this, 'format_variables'), $layout_code);
            $carousel_html .= "\t\t</li>\n";
        endwhile;

        $carousel_html .= "\t</ul>\n";
        $carousel_html .= "</div>";

        $slider_settings =  stripslashes($slider_row['js_settings']);

        $carousel_js = "";
        $carousel_js .= "<script type=\"text/javascript\">\n";
        $carousel_js .= "jQuery(document).ready(function($) {";
        $carousel_js .= "$(\"#touchcarousel-$id\").touchCarousel(";         
        $carousel_js .= $slider_settings;       
        $carousel_js .= ");";
        $carousel_js .= "});\n";
        $carousel_js .= "</script>";

        $carousel_html .= $carousel_js;


    } else {
        $carousel_html = "<p class=\"tc-posts-not-found\">". __('TouchCarousel Warning: No posts found with selected settings.', 'touchcarousel') ."</p>";
    }




    wp_reset_postdata();
    wp_reset_query();


    return stripslashes($carousel_html);
}

示例位置可以在http://demo.campaignready.com查看

到目前为止,我已经尝试通过它们的 id 和类调用帖子和 div,但在运行“the_query”后,每列仍然只显示 1 个帖子

4

0 回答 0