-
-
Save tommcfarlin/b1b2c403a39ebb8b907a328ab10148ac to your computer and use it in GitHub Desktop.
[WordPress] Custom Archive Templates: A Short Guide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$eventQuery = new \WP_Query([ | |
'post_type' => 'acme-events', | |
'post_status' => 'publish', | |
'orderby' => 'meta_value', | |
'order' => 'desc', | |
'meta_key' => 'acme-event-start-date-time', | |
'posts_per_archive_page' => 5, | |
'paged' => get_query_var('paged') ? get_query_var('paged') : 1 | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('pre_get_posts', 'setCustomQueryVariable'); | |
public function setCustomQueryVariable($query) | |
{ | |
if (is_admin() || !is_archive()) { | |
return; | |
} | |
if ($query->is_archive('acme-events')) { | |
set_query_var('posts_per_page', 5); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<a class="next page-numbers" href="<?php echo esc_attr(get_next_posts_page_link($eventQuery->max_num_pages)); ?>"> | |
Next Page | |
</a> | |
<a class="prev page-numbers" href="<?php echo esc_attr(get_previous_posts_page_link()); ?>"> | |
Previous Page | |
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment