Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function major_trips_cpt() {
- $args = array(
- 'labels' => array(
- 'name' => 'Major Trips',
- 'singular_name' => 'Major Trip',
- 'all_items' => 'All Major Trips',
- ),
- 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields' ),
- 'menu_position' => 4,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_admin_bar' => true,
- 'description' => ( 'New Major Trip Entry'),
- 'public' => true,
- 'has_archive' => true,
- 'menu_icon' => get_stylesheet_directory_uri() . '/images/fwdaus-icon.png',
- 'rewrite' => array('slug' => '4wdaus-major_trips')
- );
- register_post_type( 'major_trip', $args );
- }
- add_action( 'init', 'major_trips_cpt' );
- ?>
- //Code for displaying grid of blog posts for the relevant category
- <!-- Search all posts for those with the category for this major_trip -->
- <?php
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => 6,
- 'order' => 'desc',
- 'orderby' => 'date',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'category',
- 'field' => 'slug',
- 'terms' => get_field('category_to_display'), // category from the Advanced Custom Field variable
- ),
- ),
- );
- if ( get_query_var('paged') ) {
- $args['paged'] = get_query_var('paged');
- } elseif ( get_query_var('page') ) {
- $args['paged'] = get_query_var('page');
- } else {
- $args['paged'] = 1;
- }
- $the_query = new WP_Query( $args );
- // Pagination fix
- $temp_query = $wp_query;
- $wp_query = NULL;
- $wp_query = $the_query;
- ?>
- <div id="fwd-blog-grid">
- <?php if ( $the_query->have_posts() ) : ?>
- <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
- <div class="fwd-grid-item">
- <?php if ( has_post_thumbnail() ) {
- the_post_thumbnail();
- } ?>
- <h2><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></h2>
- <div class="entry-content">
- <a href='<?php the_permalink(); ?>'><?php the_excerpt(); ?></a>
- </div>
- </div>
- <?php endwhile; ?>
- <?php
- wp_reset_postdata();
- echo "<div style='clear: both;'>";
- //wp_pagenavi( array( 'query' => $the_query ) );
- echo "<div style='float: left;'>";
- next_posts_link( '« Older Posts' );
- echo "</div>";
- echo "<div style='float: right;'>";
- previous_posts_link( 'Newer Posts »' );
- echo "</div>";
- echo "</div>";
- // Reset main query object
- $wp_query = NULL;
- $wp_query = $temp_query;
- ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement