1 回答

TA貢獻1785條經驗 獲得超4個贊
問題是因為您在循環中間覆蓋了循環數據,這會破壞循環。
你需要改變兩件事 -
您正在
$post_id
使用作者頁面的帖子 ID 覆蓋該值。只需使用另一個變量,這樣您的主帖子 ID 就不會受到影響。刪除循環內的倍數
wp_reset_postdata
(我不確定這意味著什么?)
請參閱下面更新的代碼(請注意,這尚未經過測試,但主要思想就在那里):
<?php
$the_query = new WP_Query( 'posts_per_page=12&offset=1' );
if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="<?php the_permalink() ?>" class="article">
<div class="articlepic">
<?php $image_obj = get_field('coverpic', $post_id );
if ( $image_obj ) : ?>
<img src="<?= $image_obj[ 'sizes' ]['small'] ?>">
<?php endif; ?>
</div>
<div class="articleabout">
<?php the_title(); ?>
<br>
<?php
// DON'T USE YOUR POST_ID VARIABLE FOR THE AUTHOR PAGE!!
// Save it into a new variable
$author_post_id = get_field( 'author_link', false, false );
if( $author_post_id ):
echo get_the_title( $author_post_id );
endif; ?>
<br>
Text about article.
</div>
</a>
<?php endwhile; ?>
<?php wp_reset_postdata(); endif; ?>
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報