Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops wordpress自定义帖子在一个div中显示一些帖子,在另一个div中显示其余帖子_Loops_Custom Post Type_Wordpress - Fatal编程技术网

Loops wordpress自定义帖子在一个div中显示一些帖子,在另一个div中显示其余帖子

Loops wordpress自定义帖子在一个div中显示一些帖子,在另一个div中显示其余帖子,loops,custom-post-type,wordpress,Loops,Custom Post Type,Wordpress,在wordpress中,我制作了一个自定义的帖子类型。因此,对于自定义帖子类型,我的代码如下所示 add_action( 'init', 'broker_post_type' ); function broker_post_type() { register_post_type( 'new_broker', array( 'labels' => array( 'name' => __( 'Brands' ), 'singular

在wordpress中,我制作了一个自定义的帖子类型。因此,对于自定义帖子类型,我的代码如下所示

add_action( 'init', 'broker_post_type' );
function broker_post_type() {
  register_post_type( 'new_broker',
    array(
      'labels' => array(
        'name' => __( 'Brands' ),
        'singular_name' => __( 'Brand' )
      ),
    'public' => true,
    'has_archive' => true,
    'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
    )
  );
}
function display_broker_posts() {
  $args = array(
    'post_type' => 'new_broker',
    'orderby' => 'title',
    'order' => 'ASC',
    'posts_per_page'=> -1,
  );

  $dee_bios = new WP_Query( $args );
  if( $dee_bios->have_posts() ):
    $dee_output = '<div id="brokers-wrap">';
    $dee_output .= '<div id="brokers-bg-wrap">';
    $dee_output .= '<div class="brokers-content">';
    $dee_output .= '<div class="brokers-left-content">';
    while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
      if( $dee_bios->current_post == 0 || ( $dee_bios->current_post % 2 ) == 0 ) {
        $dee_output .= '<a class="branding first" href=""><div class="one-half first">';
        }
      else {
        $dee_output .= '<a href="" class="branding"><div class="one-half">';
        }

      $dee_output .= get_the_post_thumbnail( $dee_bios->post->ID,'small', 'bios', array( 'class' => 'alignleft' ) );
      $dee_output .= '<span></span>';
    //  $dee_output .= '<p><strong>' . get_the_title() . ',</strong> ' . get_the_content() . '</p>';
      $dee_output .= '</div><!--end .one-half-->';
    endwhile;
    $dee_output .= '<div class="clear"></div><!--clear all floats-->';
    $dee_output .= '</div><!-- end #bios-->';
  endif;

  wp_reset_postdata();
  return $dee_output;
}
add_shortcode( 'display_brokers', 'display_broker_posts' );
为了通过快捷码显示自定义帖子的内容,我这样做了

add_action( 'init', 'broker_post_type' );
function broker_post_type() {
  register_post_type( 'new_broker',
    array(
      'labels' => array(
        'name' => __( 'Brands' ),
        'singular_name' => __( 'Brand' )
      ),
    'public' => true,
    'has_archive' => true,
    'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
    )
  );
}
function display_broker_posts() {
  $args = array(
    'post_type' => 'new_broker',
    'orderby' => 'title',
    'order' => 'ASC',
    'posts_per_page'=> -1,
  );

  $dee_bios = new WP_Query( $args );
  if( $dee_bios->have_posts() ):
    $dee_output = '<div id="brokers-wrap">';
    $dee_output .= '<div id="brokers-bg-wrap">';
    $dee_output .= '<div class="brokers-content">';
    $dee_output .= '<div class="brokers-left-content">';
    while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
      if( $dee_bios->current_post == 0 || ( $dee_bios->current_post % 2 ) == 0 ) {
        $dee_output .= '<a class="branding first" href=""><div class="one-half first">';
        }
      else {
        $dee_output .= '<a href="" class="branding"><div class="one-half">';
        }

      $dee_output .= get_the_post_thumbnail( $dee_bios->post->ID,'small', 'bios', array( 'class' => 'alignleft' ) );
      $dee_output .= '<span></span>';
    //  $dee_output .= '<p><strong>' . get_the_title() . ',</strong> ' . get_the_content() . '</p>';
      $dee_output .= '</div><!--end .one-half-->';
    endwhile;
    $dee_output .= '<div class="clear"></div><!--clear all floats-->';
    $dee_output .= '</div><!-- end #bios-->';
  endif;

  wp_reset_postdata();
  return $dee_output;
}
add_shortcode( 'display_brokers', 'display_broker_posts' );
function display\u broker\u posts(){
$args=数组(
“post_type”=>“new_broker”,
'orderby'=>'title',
“订单”=>“ASC”,
“每页帖子数”=>-1,
);
$dee_bios=新的WP_查询($args);
如果($dee\u bios->have\u posts()):
$dee_输出=“”;
$dee_输出='';
$dee_输出='';
$dee_输出='';
而($dee_bios->have_posts()):$dee_bios->the_post();
如果($dee_bios->current_post==0 | |($dee_bios->current_post%2)==0){
$dee_输出='';
}
否则{
$dee_输出='';
}
$dee_output.=获取_post_缩略图($dee_bios->post->ID,'small','bios',array('class'=>'alignleft');
$dee_输出='';
//$dee_output.=''。获取_title()。,'。获取_content()。

'; $dee_输出=''; 结束时; $dee_输出=''; $dee_输出=''; endif; wp_reset_postdata(); 返回$dee_输出; } 添加快捷码('display_brokers'、'display_brokers_posts');

这里工作很好。我可以使用快捷码在我的页面中看到特色图片。但是假设我有20篇自定义文章,我希望前6篇在另一个div中显示,另外14篇在另一个div中显示。有人能告诉我怎么做吗?任何帮助都是值得的。谢谢

像这样的东西怎么样:

$dee_bios = new WP_Query( $args );
$i = 0;
if( $dee_bios->have_posts() ):
  while ( $dee_bios->have_posts() ) : $dee_bios->the_post();
    if ($i ==0) {
       $dee_output .= '<div id="first_broker_div">';
    } elseif ($i == 6) {
       $dee_output .= '</div><div id="second_broker_div">';
    }
    $dee_output .= //Your post content
    $i++;
  endwhile;
  $dee_output .= '</div>';
endif;
$dee\u bios=新的WP\u查询($args);
$i=0;
如果($dee\u bios->have\u posts()):
而($dee_bios->have_posts()):$dee_bios->the_post();
如果($i==0){
$dee_输出='';
}elseif($i==6){
$dee_输出='';
}
$dee_输出。=//您的帖子内容
$i++;
结束时;
$dee_输出='';
endif;

感谢您的回复,但无论您的代码中显示的是什么情况,您能告诉我如何解决此问题吗?