0
我有這個問題創建一個導航,與我的get_posts($ args)作出反應。試過了所有的東西,我在網上找到的所有解決方案都是用wp查詢完成的。Bootstrap acf wp與get_posts分頁
我使用ACF和Bootstrap,所以我真的想堅持get_posts。
這裏的代碼是我目前的代碼,完美的作品只顯示5篇文章。但是,如何爲分頁創建導航?
<div class="articles">
<?php
$args = array( //'numberposts' => -1
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'paged' => $paged,);
$posts= get_posts($args);
if ($posts) :
$counter = 1;
foreach ($posts as $p) :
$classCount = 'post-'.$counter;
if($classCount == 'post-1') : echo '<div class="mediumPost col-xs-12 col-sm-6 col-md-6 col-lg-6">';
elseif($classCount == 'post-2' || $classCount == 'post-3') : echo '<div class="smallPost col-xs-12 col-sm-6 col-md-6 col-lg-6">';
elseif($classCount == 'post-4') : echo '<div class="largePost col-xs-12 col-sm-12 col-md-12 col-lg-12">';
elseif($classCount == 'post-5') : echo '<div class="mediumPost col-xs-12 col-sm-6 col-md-6 col-lg-6">';
elseif($classCount == 'post-6' || $classCount == 'post-7') : echo '<div class="smallPost col-xs-12 col-sm-6 col-md-6 col-lg-6">';
else : echo '<div class="smallPost col-xs-12 col-sm-6 col-md-6 col-lg-6">';
endif; ?>
<?php $postImg = get_field('post_image', $p->ID); if(!empty($postImg)): ?>
<img src="<?php echo $postImg['url']; ?>" alt="<?php if(!empty($postImg['alt'])): echo $postImg['alt']; else : echo the_title(); endif; ?>" />
<?php endif; ?>
<div class="iconBox">
<?php $getIcon = get_field('post_type', $p->ID); ?>
<?php $catIcon = get_field($getIcon, 132); ?>
<?php if(!empty($catIcon)): ?>
<img class="iconImg" src="<?php echo $catIcon['url']; ?>" alt="<?php if(!empty($catIcon['alt'])): echo $catIcon['alt']; else : echo the_title(); endif; ?>" />
<?php endif; ?>
</div>
<?php $categories = get_the_category($p->ID);
$category_id = $categories[0]->cat_ID; ?>
<?php if($category_id == 9) : ?>
<h4 data-toggle="modal" data-target="#myModal-<?php echo $counter ?>"><?php echo get_the_title($p->ID); ?></h4>
<span class="articles-btn" data-toggle="modal" data-target="#myModal-<?php echo $counter ?>">Watch link</span>
<!-- Modal -->
<div class="modal fade" id="myModal-<?php echo $counter ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h5 class="modal-title" id="myModalLabel"><?php echo get_the_title($p->ID); ?></h5>
</div>
<div class="modal-body">
<div class="embed-container">
<?php // get iframe HTML
$iframe = get_field('post_embed', $p->ID);
// use preg_match to find iframe src
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];
// add extra params to iframe src
$params = array(
'controls' => 1,
'hd' => 1,
'autohide' => 1
);
$new_src = add_query_arg($params, $src);
$iframe = str_replace($src, $new_src, $iframe);
// add extra attributes to iframe html
$attributes = 'frameborder="0"';
$iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $iframe); ?>
<?php echo $iframe; ?>
</div>
</div>
</div>
</div>
</div>
<?php else : ?>
<a href="<?php echo get_permalink($p->ID); ?>"><h4><?php echo get_the_title($p->ID); ?></h4></a>
<a href="<?php echo get_permalink($p->ID); ?>"><span class="articles-btn">READ MORE</span></a>
<?php endif; ?>
</div> <!--postSize div-->
<?php $counter++; if (11 === $counter) $counter = 1; endforeach; wp_reset_postdata();?>
<?php endif; ?>
</div>
嗨,首先感謝百萬迴應:)我做了你所建議的一切,但沒有出現在custom_pagination。試圖從if語句中迴應'hello',然後顯示出來。所以它不能得到custom_pagination($ posts,「」,$ paged);展示任何東西。 –
看到我剛剛更新的答案中的最後一塊代碼.. custom_pagination(count($ posts),「」,$ paged) –
令人驚歎!非常感謝你:) –