Twenty Eleven Custom Query Help
-
I am using Twenty Eleven on my site, and I have setup a custom post type for a Beers section of my site. It has all of the beers that I have consumed in my life. At this current time, it works, but I would like it to work better.
You can see it here: https://drewclardy.com/beers
I am organizing everything by the brewer and listing the beers I have had from them below it. Here is the code that I am using.
<?php /** * @package WordPress * @subpackage Twenty Eleven */ ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h1 class="entry-title"><?php the_title(); ?></h1> </header><!-- .entry-header --> <div class="entry-content"> <?php the_content(); ?> <div class="beers-consumed"> <?php $total_beers = wp_count_posts('beer')->publish; echo 'Total Different Beers Consumed: '. $total_beers; ?> </div> <div class="beer-list"> <?php $beers = new WP_Query( array( 'post_type' => 'beer', 'orderby' => 'meta_value', 'meta_key' => 'brewing_company', 'order' => 'ASC', 'showposts' => -1 ) ); ?> <?php if ( $beers->have_posts() ) : ?> <ul> <?php while ( $beers->have_posts() ) : $beers->the_post(); $brewing_company = get_post_meta($beers->post->ID, 'brewing_company', true); $brewing_country = get_post_meta($beers->post->ID, 'brewing_country', true); $brewing_style = get_post_meta($beers->post->ID, 'beer_styles', true); if ( $brewing_company != $brewing_company_name) { echo '<li><span class="brewing-company">'. $brewing_company .'</span>, <span class="brewing-country">'. $brewing_country .'</span></li>'; $brewing_company_name = $brewing_company; } ?> <ul> <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><span class="beer-name"><?php the_title(); ?></span>, <span class="beer-type"><?php echo $brewing_style ?></span></a></li> </ul> <?php endwhile; ?> </ul> <?php endif; wp_reset_query(); ?> </div><!-- .beer-list --> <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyeleven' ), 'after' => '</div>' ) ); ?> <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-content --> </article><!-- #post-<?php the_ID(); ?> -->
If you look at the source of the page, you can see that there are a ton of extra lists in there, and it just looks bad from that side of things.
To make it better, I wanted to group everything like this.
Country
Brewer
BeerHow can I do this? Everything is using custom meta boxes. I have tried several different things, but it never works.
Any ideas on how I can get this working?
- The topic ‘Twenty Eleven Custom Query Help’ is closed to new replies.