我想为自定义wp\\U查询制作一个寻呼机,在这里我可以有上一个和下一个。我有一个名为family的CPT,我必须显示满足保留其状态条件的族,重要的是,我必须在每页中仅显示一个族,并且我必须放置分页器以逐个导航。
这是我的代码:
$paged = get_query_var( \'paged\' ) ? absint( get_query_var( \'paged\' ) ) : 1;
$args_families = array (
\'post_type\' => array( \'family\' ),
\'paged\' => $paged,
\'orderby\' => \'ASC\',
\'posts_per_page\' => 1,
\'meta_query\' => array(
array(
\'key\' => \'status\',
\'value\' => \'Retained\',
\'compare\' => \'=\',
)
)
);
$family_query = new WP_Query( $args_families );
<?php if ( $family_query->have_posts() ) : ?>
<?php while ( $family_query->have_posts() ) : ?>
<?php $family_query->the_post(); ?>
<?php
echo get_field(\'status\'). \'<br>\';
echo \' \'.\'fid_\'.get_field(\'family_id\') . \'<br>\';
echo \'ID + ACF\'.\' \'.\'fid_\'.get_field(\'family_id\' , $family_query->posts[$i]->ID);
$f_link = \'fid_\'.get_field(\'family_id\' , $family_query->posts[$i]->ID);
?>
<h3> <?php echo esc_attr( get_the_title() ); ?></h3>
<?php $profile_pic = get_field( \'profile_picture\' ); ?>
<img src="<?php echo esc_url( $profile_pic[\'sizes\'][\'family_large_thumb\'] ); ?>" width="300px" height="300px" style="display:block;" />
<!-- attempt 1 to create the pager -->
<a href="https://localhost/adoptionnetwork/adopting-families/fid_20074/">next1</a>
<a href="https://localhost/adoptionnetwork/adopting-families/<?php echo $f_link ?>">next2</a>
<?php
//attempt 1 to create the pager
$older_link = \'<a href="/adoptionnetwork/adopting-families/fid_\' . ( $paged - 1 ) . \'" rel="prev"><</a>\';
$newer_link = \'<a href="/adoptionnetwork/adopting-families/fid_\' . ( $paged + 1 ) . \'" rel="next">></a>\';
?>
<?php endwhile; ?>
<?php
// Clean up after the query and pagination.
wp_reset_postdata();
?>
但我不知道如何为这个案例创建寻呼机。
NOTE: 注意:我已经使用了这些函数,但它们不起作用。
get_next_post_link( \'%link\', \'<i class="far fa-angle-right"></i>\' );
get_previous_post_link( \'%link\', \'<i class="far fa-angle-left"></i>\' );
previous_post_link();
next_post_link();
谢谢你的帮助
SO网友:admcfajn
你是不是在找这样的东西?
/**
* Outputs blog / archive pagination
*
*/
function my_pagination(){
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1):
$current_page = max(1, get_query_var(\'paged\'));
echo paginate_links(array(
\'current\' => $current_page,
\'total\' => $total_pages,
\'prev_text\' => \'Prev\',
\'next_text\' => \'Next\',
\'type\' => \'list\'
));
endif;
}
然后把它包括在你的主题中
<?php if ( $family_query->have_posts() ) : ?>
<?php while ( $family_query->have_posts() ) : ?>
<?php $family_query->the_post(); ?>
<h3><?php echo esc_attr( get_the_title() ); ?></h3>
<?php endwhile; ?>
<?php my_pagination(); ?>