Title: Modifying a category view
Last modified: August 24, 2016

---

# Modifying a category view

 *  [MC](https://wordpress.org/support/users/mcsolas/)
 * (@mcsolas)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/modifying-a-category-view/)
 * I am working on porting a site over from drupal 6. It has been very tricky, since
   I used views to build several of the pages and it has several content types. 
   One of them is a tide chart. The view for this page shows the oldest first. This
   allows the most recent chart to display first, then at the end of the month, 
   I take that page down as the chart is expired. Each year I generate a new grouping
   of these charts as well. One idea was to manually set the dates so the newer 
   ones are ‘older posts’ and thus display in the right order ( current months first).
   I have been considering using them as pages as well, but I like it when you can
   browse from one month to the next. Currently, I show 3 months at a time on the
   page:
    [http://crsurfcam.com/tidecharts](http://crsurfcam.com/tidecharts)
 * How can I modify this category to display the oldest post first?
 * From there, I can work more on the display of the content. I also will have several
   other types of content but I usually exclude this one from showing up on the 
   front page. I will address that next ( if I end up leaving them in the ‘posts’)
   section of the site.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/modifying-a-category-view/#post-6074961)
 * Hi MC,
 * Never used them but I hear these plugins are similar to Drupals types and views:
   
   [https://wordpress.org/plugins/types/](https://wordpress.org/plugins/types/) 
   [http://wp-types.com/home/views-create-elegant-displays-for-your-content/](http://wp-types.com/home/views-create-elegant-displays-for-your-content/)
 * Without the plugins create a post type ‘tidecharts’. Set the publish date the
   same as the chart date when publishing a tide chart post.
    [https://codex.wordpress.org/Post_Types](https://codex.wordpress.org/Post_Types)
 * This in your theme’s functions.php file creates the post type and changes the
   query for the charts archive to show the posts in the current and next two months
   ordered from current to future charts.
 * With this you don’t need to remove old charts anymore because it will update 
   the archive automatically.
 *     ```
       // Register Custom Post Type
       function custom_post_type() {
   
       	$labels = array(
       		'name'                => _x( 'Tide Charts', 'Post Type General Name', 'text_domain' ),
       		'singular_name'       => _x( 'Tide Chart', 'Post Type Singular Name', 'text_domain' ),
       		'menu_name'           => __( 'Tide Charts', 'text_domain' ),
       		'name_admin_bar'      => __( 'Tide Charts', 'text_domain' ),
       		'parent_item_colon'   => __( 'Parent Item:', 'text_domain' ),
       		'all_items'           => __( 'All Charts', 'text_domain' ),
       		'add_new_item'        => __( 'Add New Chart', 'text_domain' ),
       		'add_new'             => __( 'Add New', 'text_domain' ),
       		'new_item'            => __( 'New Chart', 'text_domain' ),
       		'edit_item'           => __( 'Edit Chart', 'text_domain' ),
       		'update_item'         => __( 'Update Chart', 'text_domain' ),
       		'view_item'           => __( 'View Chart', 'text_domain' ),
       		'search_items'        => __( 'Search Chart', 'text_domain' ),
       		'not_found'           => __( 'Chart Not found', 'text_domain' ),
       		'not_found_in_trash'  => __( 'Chart Not found in Trash', 'text_domain' ),
       	);
       	$args = array(
       		'label'               => __( 'Tide_chart', 'text_domain' ),
       		'description'         => __( 'Tide Chart', 'text_domain' ),
       		'labels'              => $labels,
       		'supports'            => array( ),
       		'taxonomies'          => array( ),
       		'hierarchical'        => false,
       		'public'              => true,
       		'show_ui'             => true,
       		'show_in_menu'        => true,
       		'menu_position'       => 5,
       		'show_in_admin_bar'   => true,
       		'show_in_nav_menus'   => true,
       		'can_export'          => true,
       		'has_archive'         => true,
       		'exclude_from_search' => false,
       		'publicly_queryable'  => true,
       		'capability_type'     => 'page',
       	);
       	register_post_type( 'tidecharts', $args );
   
       }
   
       // Hook into the 'init' action
       add_action( 'init', 'custom_post_type', 0 );
   
       function tidecharts_queries( $query ) {
   
       	// not an admin page and is the main query
       	if ( !is_admin() && $query->is_main_query() ) {
   
       		// query for the post type 'tidecharts' archive
   
       		if ( is_post_type_archive( 'tidecharts' ) ) {
   
       			// show three charts per page on this archive
       			$query->set( 'posts_per_page', 3 );
   
       			// published and future dates
       			$query->set( 'post_status', array( 'publish', 'future' ) );
       			$query->set( 'order', 'ASC' );
   
       			// query for posts from this month and later
       			$date_query = array(
       				'after'    => array(
       					'year'  => date( 'Y' ),
       					'month' => date( 'm' ),
       					'day'   => 01,
       				),
       				'inclusive' => true,
       			);
   
       			$query->set( 'date_query', $date_query );
       		}
       	}
       }
   
       add_action( 'pre_get_posts', 'tidecharts_queries' );
       ```
   
 * btw:
    consider creating a [child theme](http://codex.wordpress.org/Child_Themes)
   instead of editing your theme directly – if you upgrade the theme all your modifications
   will be lost. Or [create a plugin](https://wordpress.org/plugins/pluginception/)
   with the code above.
 *  Thread Starter [MC](https://wordpress.org/support/users/mcsolas/)
 * (@mcsolas)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/modifying-a-category-view/#post-6075328)
 * I am using the code you created in the new site. I am adding tide charts to the
   custom post type. The one place I am stuck is trying to display, what after reading
   the docs, looks like the ‘archive’ page correctly. The first post has the url:
   /
   tidecharts/january-2015/ which works and shows the page.
 * However when I pull up /tidecharts/ it says there is nothing in the archive page
   to display.
 * 1. I want to get that url working if possible. 2. I would like to ensure that
   it display the posts in the reversed date order. I see in the code, the query
   is already re-sorted to display in oldest first order. So it looks like I just
   need to figure out how to display the data that gets loaded in the $tidecharts_queries
   variable in the last line of the function on the /tidecharts/ page.
 * This may have something to do with adding a file called archive-{post_type}.php
   or archive-tidecharts.php file in my case to the child theme. I am not sure exactly
   how to structure that file. I figure I may need to reference the tidecharts_queries
   variable in it somehow.
 * I cannot yet provide a working url, its on a development server. Shortly after
   figuring this out, I am going to switch the dns over soon.. wanted to get this
   working first but really I have an idea how I can at least make it work in the
   interim another way which would allow me to go ahead and switch the dns, then
   I could post a url ..
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/modifying-a-category-view/#post-6075329)
 * Do you have any tide chart posts with the publish date in January, February or
   march 2016?
 *  Thread Starter [MC](https://wordpress.org/support/users/mcsolas/)
 * (@mcsolas)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/modifying-a-category-view/#post-6075330)
 * That was all it took, I had started on it in December and .. it had expired, 
   that was the only reason why it wasn’t listed. Looks like I am all set, will 
   launch the site as soon as I load it up with content now.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Modifying a category view’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [MC](https://wordpress.org/support/users/mcsolas/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/modifying-a-category-view/#post-6075330)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
