(Use the spacebar to cycle through slides)

Hello!

  • Michael Dance
  • Live in DC
  • Developer at

Let's talk about

Information Architecture

What content do I have on my website? How is that grouped into sections? How is that organized and listed within a section?

For example:

  • How do I show all blog posts in a category?
  • How do I list all products in the children's department?
  • How do I display all artifacts from the Bronze Age?

The Internet:
Detail Pages and Archive Pages

Detail Page

A page about a thing.

Archive Page

A list of things.

archive (or archives)
n. a collection of records.

In WordPress, detail pages = posts:

  • Blog posts
  • Pages
  • Media

Custom post types:

  • Products
  • Artifacts
  • Books
  • Staff Bios
  • Press Releases
  • ...

WordPress's archive pages:

  • Main blog page
  • Author archives
  • Date archives
  • (more...)
  • Category archives
  • Tag archives
  • Custom taxonomy archives
    • Product department
    • Artifact era
    • Book genre
  • Custom post type archives
  • Site search results
So that's archive pages.

But wait...

  1. How do I edit the heading? Or add a description at the top?
  2. How do I sort the content so it's not listed by date?
  3. How do I add filters and search forms?

I. Making archive pages editable

Usually:

  • They're not
  • or, they're buried in a big Theme Options page
  • or, you make your own archives with some complicated plugin setup

Our way:

  • Add a custom options page just for the archive
  • Put it where users can logically find it
  • Only use plugins for the really complicated stuff

						acf_add_options_sub_page( array(
							'page_title'  => 'Book Archive Page Settings',
							'menu_title'  => 'Archive Page',
							'menu_slug'   => 'book-archive',
							'parent_slug' => 'edit.php?post_type=book'
						) );
					

						

<?php the_field( 'books_title', 'option' ); ?>

<?php the_field( 'books_description', 'option' ); ?>

II. Organizing the posts on archive pages

Usually:

  • They're sorted by date published
  • There are 10 per page

Our way:

  • Sort them however you want
  • Display as many as you want

							function my_books_query( $query ) {

							}
							add_action( 'pre_get_posts', 'my_books_query' );
						

							function my_books_query( $query ) {

								if ( is_admin() || !$query->is_main_query() )
									return;

								if ( !is_post_type_archive( 'book' ) )
									return;

							}
							add_action( 'pre_get_posts', 'my_books_query' );
						

							function my_books_query( $query ) {

								if ( is_admin() || !$query->is_main_query() )
									return;

								if ( !is_post_type_archive( 'book' ) )
									return;

								$query->set( 'order', 'ASC' );
								$query->set( 'orderby', 'title' );
								$query->set( 'posts_per_page', '25' );

							}
							add_action( 'pre_get_posts', 'my_books_query' );
						

						$query->set( 'posts_per_page',
							get_field( 'books_per_page', 'option' ) );
					
https://codex.wordpress.org
/Function_Reference/WP_Query

III. Adding search filters


						<form method="get" action="/wp-content/plugins/raiders/slides/<?php echo esc_url( get_post_type_archive_link( 'book' ) ); ?>">
							Filter by:
							<?php wp_dropdown_categories( array(
								'taxonomy'        => 'genre',
								'name'            => 'book_genre',
								'show_option_all' => 'Genre',
								'selected'        => (int) $_GET['book_genre'],
							) ); ?>
							
							
						</form>
					

In your hook function:


						$genre = isset( $_GET['book_genre'] )
						         ? (int) $_GET['book_genre'] : '';

						if ( $genre ) {
							$query->set( 'tax_query', array(
								array(
									'taxonomy' => 'genre',
									'terms'    => $genre,
								)
							) );
						}
					

						$keyword = isset( $_GET['book_keyword'] )
						         ? sanitize_text_field( $_GET['book_keyword'] ) : '';

						if ( $keyword ) {
							$query->set( 's', $keyword );
						}
					
Questions?