每列不能超过1个帖子

时间:2013-06-28 20:24:57

标签: php jquery css wordpress

您好我在wordpress中工作,到目前为止我能够为我的帖子循环显示不同的大小,但我在每列中只收到1个帖子。我已经尝试将多个post循环添加到我们的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个帖子

0 个答案:

没有答案