admin管理员组文章数量:1126078
This is what I have tried so far:
<?php /* Template Name: Archive-posts */ ?>
<?php get_header(); ?>
<main id="primary" class="site-main">
<div class="page-header" id="page-header=news">
<h1>Archive</h1>
</div>
<div class="archived">
<div class="archive-grid">
<!-- Query list of archive posts -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'archive',
'posts_per_page' => 12, // Change this to the number of posts you want to display per page
'paged' => $paged,
'meta_key' => 'event_date', // Specify the meta key
'orderby' => 'meta_value', // Order by the meta value
'order' => 'DESC', // Order in descending order
);
query_posts($args);
if (have_posts()) :
while (have_posts()) : the_post();
?>
<a href="<?php the_permalink(); ?>" class="archive-item">
<h2><?php the_title(); ?></h2>
<?php
// Get the event_date custom field value
$event_date = get_post_meta(get_the_ID(), 'event_date', true);
if ($event_date) {
// Convert the date to a more readable format
$formatted_date = date('F j, Y', strtotime($event_date));
echo '<div class="event-date">' . esc_html($formatted_date) . '</div>';
}
?>
</a>
<?php endwhile; ?>
</div>
<div class="pagination-news">
<?php echo paginate_links(array('total' => $wp_query->max_num_pages)); ?>
</div>
<?php endif; ?>
</div>
</main>
<?php wp_reset_postdata(); // Reset the post data ?>
<?php get_footer(); ?>
tried to fix following this question, but couldn't sort it: Custom post type pagination not working in index.php file
本文标签: theme developmentTrying to create a cutom query with pagination and page 2 breaking Any help
版权声明:本文标题:theme development - Trying to create a cutom query with pagination and page 2 breaking. Any help? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736631471a1945787.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论