【发布时间】:2015-05-24 10:07:13
【问题描述】:
我正在使用 ACF 构建一个网站,我有两种不同类别的页面:文章和故事。
我想构建我的页面,使其成为故事中交替文章的列表,但目前我首先获取所有文章,然后是所有故事,而不是交错排列。
您可以在这里查看网站http://www.ndstudio.no/wp-mindthegap/
我希望循环是这样的:
POST 1 (ARTICLE)
POST 2 (STORY)
POST 3 (ARTICLE)
POST 4 (STORY)
但现在是这样的:
POST 1 (ARTICLE)
POST 2 (ARTICLE)
POST 3 (STORY)
POST 4 (STORY)
这是我的代码
<?php
$args = array(
'cat' => 5,
'post_type' => array( 'page' ),
'order' => 'ASC'
);
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
?>
<?php $colour = get_field('colour'); ?>
<div class="<?php print $colour; ?>-wrap">
<div class="first-text-content">
<h1 class="title-page"><?php the_title(); ?></h1>
<?php
// check if the repeater field has rows of data
if( have_rows('block') ):
// loop through the rows of data
while ( have_rows('block') ) : the_row();
?>
<!-- <p><?php the_sub_field('type'); ?><p> -->
<?php
$type = get_sub_field('type');
$quote = get_sub_field('quote');
$text = get_sub_field('text');
if ($type == "text") {
?>
<?php the_sub_field('text'); ?>
<?php
} else if ($type == "quote") {
?>
<div class="quote"><?php the_sub_field('quote'); ?></div>
<?php
}
?>
<?php
endwhile;
else :
// no rows found
endif;
?>
</div>
</div>
<?php
endwhile;
// Reset Query
wp_reset_query();
?>
<!-- STORIES categories -->
<?php
$args = array(
'cat' => 4,
'post_type' => array( 'page' ),
'order' => 'ASC'
);
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
?>
<div class="stories">
<div class="stories-length">
<div class="scroll-right"><img src="http://www.ndstudio.no/wp-mindthegap/wp-content/uploads/2015/05/scroll-right.png" /></div>
<img class="intro-image" src="<?php the_field('intro-image'); ?>" alt="" />
<div class="intro-column">
<h1 class="title-page"><?php the_title(); ?></h1>
<?php the_field('intro-text'); ?>
</div>
<?php
// check if the repeater field has rows of data
if( have_rows('content_block') ):
//consoleLog(get_field('block'));
// loop through the rows of data
while ( have_rows('content_block') ) : the_row();
?>
<!-- <p><?php the_sub_field('type'); ?><p> -->
<?php
// the_sub_field is printing the value, which is output into HTML
// get_sub_field is returning the value, which you'll store in a variable
$select = get_sub_field('select');
$textfield = get_sub_field('textfield');
$video = get_sub_field('video');
$quote = get_sub_field('quote');
$bgcolor = get_sub_field('bgcolor');
$image1 = get_sub_field('image1');
$image2 = get_sub_field('image2');
if ($select == "textfield") {
?>
<div class="text-column"><?php the_sub_field('textfield'); ?></div>
<?php
} else if ($select == "video") {
?>
<div class="video-row-2"><div class="article-video-2"><?php the_sub_field('video'); ?></div></div>
<?php
} else if ($select == "quote") {
?>
<div class="nautral-row"><div class="quotes"><?php the_sub_field('quote'); ?></div></div>
<?php
} else if ($select == "image1") {
?>
<div class="<?php print $bgcolor; ?>-row">
<img class="article-image" src="<?php the_sub_field('image1'); ?>" alt="" />
<?php
} else if ($select == "image2") {
?>
<img class="article-image" src="<?php the_sub_field('image2'); ?>" alt="" /></div>
<?php
}
?>
<?php
endwhile;
else :
// no rows found
endif;
?>
</div>
</div>
<?php
endwhile;
// Reset Query
wp_reset_query();
?>
非常感谢您观看。
【问题讨论】:
标签: php wordpress advanced-custom-fields