• 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
    Beer

    How 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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m not sure if this would make your life easier or not, but if it was me doing that, I’d scrap the custom meta boxes for the differet catgories, and register a custom taxonomy for your ‘beer’ content type. Then, make sure that the beer content type is set to allow an archive and that it’s hierarchical when it’s registered. That way you can use the standard WordPress categories and you can post everything where you want it to go.

    After that, you just need to set up your categories:

    America
    –Abita Brewing
    –Anchor Brewing
    Italy
    –Birra Peroni

    And set up an archive-beers.php template page to display it all.

    And what is it with no Aussie beers except Fosters??? It’s strange… No one drinks Fosters in Australia. There’s better ones out there, just keep looking. ??

    Thread Starter dclardy

    (@dclardy)

    Thanks for the idea. I have toyed around with moving this to a taxonomy, but it seems like so much work! I guess that I will just have to do it. I saw that scribu has a plugin to convert everything.

    I guess that I will have to convert the Country first. Then move the Brewers.

    How would I go about setting up the archive page. I want it to show like this.

    Country
    –Brewer
    —-Beer

    Also, sorry for not representing Australia properly. I will make an effort to find more from that country. They just don’t seem to have that many of them in Texas.

    Thread Starter dclardy

    (@dclardy)

    I tried setting this up, but I have gotten nowhere! The taxonomy is not the route that I want to go. Any help would be appreciated.

    Thread Starter dclardy

    (@dclardy)

    I tried setting this up, but I have gotten nowhere! The taxonomy is not the route that I want to go. Any help would be appreciated.

    If you don’t want to / can’t do this… the only other option that I’d suggest is creating a custom post type, and using that as a base to register individual beers against. It’s a lot more work, and it’s going to be a big leaning curve for you to do it that way, but that’s where you’re at now.

    Thread Starter dclardy

    (@dclardy)

    I already have the custom post type for beers built. Are you saying to create another custom post type? I don’t understand why I can’t just modify the loop that I am running. I guess that I am just making it too simple.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Twenty Eleven Custom Query Help’ is closed to new replies.