• I’ve used WP for blogs for a while and love it. But for my main site I’ve used joomla. I really do like the WP admin and style better and would like to change over. However I’m having some trouble finding plugins to set my site the way I like.

    In Joomla I could have a section ie. recipes and then sub categories ie. breakfast, canning etc. It was easy to have a main page with the sub cat. title then the post listed under it. I’m trying to figure out something similar in WP.

    I can use Post to Link plug in to get the page to go right to a category. The problem is it will list all the sub’s of that category together in stead of breaking them up…

    What basically I’m looking for something that would let me lay it out like this.
    Page “Recipes”
    Category “Breakfast”
    recipe 1
    recipe 2
    Category “Canning”
    recipe 1

    I’m also hoping that I could have an excerpt and image beside it. I’m not to picky eh? lol I’ve seen other sites laid out similar and I would really appreciate any help and ideas for plugins.
    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • MichaelH

    (@michaelh)

    Suppose you could do something like this in your index.php:

    <?php
    //get terms (e.g. categories or post tags), then display all posts in each retrieved term
    $taxonomy = 'category';//  e.g. post_tag, category
    $param_type = 'category__in'; //  e.g. tag__in, category__in
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC',
      'child_of' => 6
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'showposts' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts in '.$taxonomy .' '.$term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
           the_excerpt(); //
          endwhile;
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Then use a plugin such as this to provide a thumbnail for your excerpt:
    https://www.ads-software.com/extend/plugins/thumbnail-for-excerpts/

    Thread Starter homesteadmommy

    (@homesteadmommy)

    Thanks! I tried it but it didn’t change anything…Maybe I posted it in the wrong place. This is my index file can you tell me were I should past the code? Thanks!

    <?php get_header(); ?>
    <div class=”contentLayout”>
    <div class=”sidebar1″>
    <?php include (TEMPLATEPATH . ‘/sidebar1.php’); ?>
    </div>
    <div class=”content”>

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”Post”>
    <div class=”Post-body”>
    <div class=”Post-inner article”>
    <?php ob_start(); ?>
    <h2 class=”PostHeaderIcon-wrapper”>
    <span class=”PostHeader”>” rel=”bookmark” title=”<?php printf(__(‘Permanent Link to %s’, ‘kubrick’), the_title_attribute(‘echo=0’)); ?>”>
    <?php the_title(); ?>
    </span>
    </h2>
    <?php $icons = array(); ?>
    <?php if (!is_page()): ?><?php ob_start(); ?><img src=”<?php bloginfo(‘template_url’); ?>/images/PostDateIcon.png” width=”18″ height=”18″ alt=”PostDateIcon” />
    <?php the_time(__(‘F jS, Y’, ‘kubrick’)) ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (!is_page()): ?><?php ob_start(); ?><img src=”<?php bloginfo(‘template_url’); ?>/images/PostAuthorIcon.png” width=”18″ height=”18″ alt=”PostAuthorIcon” />
    <?php _e(‘Author’, ‘kubrick’); ?>: “><?php the_author() ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (current_user_can(‘edit_post’, $post->ID)): ?><?php ob_start(); ?><img src=”<?php bloginfo(‘template_url’); ?>/images/PostEditIcon.png” width=”15″ height=”15″ alt=”PostEditIcon” />
    <?php edit_post_link(__(‘Edit’, ‘kubrick’), ”); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (0 != count($icons)): ?>
    <div class=”PostHeaderIcons metadata-icons”>
    <?php echo implode(‘ | ‘, $icons); ?>

    </div>
    <?php endif; ?>
    <?php $metadataContent = ob_get_clean(); ?>
    <?php if (trim($metadataContent) != ”): ?>
    <div class=”PostMetadataHeader”>
    <?php echo $metadataContent; ?>

    </div>
    <?php endif; ?>
    <div class=”PostContent”>
    <?php if (is_search()) the_excerpt(); else the_content(__(‘Read the rest of this entry »’, ‘kubrick’)); ?>

    </div>
    <div class=”cleared”></div>
    <?php $icons = array(); ?>
    <?php if (!is_page()): ?><?php ob_start(); ?><img src=”<?php bloginfo(‘template_url’); ?>/images/PostCategoryIcon.png” width=”18″ height=”18″ alt=”PostCategoryIcon” />
    <?php printf(__(‘Posted in %s’, ‘kubrick’), get_the_category_list(‘, ‘)); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (!is_page() && get_the_tags()): ?><?php ob_start(); ?><img src=”<?php bloginfo(‘template_url’); ?>/images/PostTagIcon.png” width=”18″ height=”18″ alt=”PostTagIcon” />
    <?php the_tags(__(‘Tags:’, ‘kubrick’) . ‘ ‘, ‘, ‘, ‘ ‘); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (!is_page() && !is_single()): ?><?php ob_start(); ?><img src=”<?php bloginfo(‘template_url’); ?>/images/PostCommentsIcon.png” width=”18″ height=”18″ alt=”PostCommentsIcon” />
    <?php comments_popup_link(__(‘No Comments »’, ‘kubrick’), __(‘1 Comment »’, ‘kubrick’), __(‘% Comments »’, ‘kubrick’), ”, __(‘Comments Closed’, ‘kubrick’) ); ?>
    <?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (0 != count($icons)): ?>
    <div class=”PostFooterIcons metadata-icons”>
    <?php echo implode(‘ | ‘, $icons); ?>

    </div>
    <?php endif; ?>

    </div>

    </div>
    </div>

    <?php endwhile; ?>
    <?php
    $prev_link = get_previous_posts_link(__(‘Newer Entries »’, ‘kubrick’));
    $next_link = get_next_posts_link(__(‘« Older Entries’, ‘kubrick’));
    ?>
    <?php if ($prev_link || $next_link): ?>
    <div class=”Post”>
    <div class=”Post-body”>
    <div class=”Post-inner article”>

    <div class=”PostContent”>

    <div class=”navigation”>
    <div class=”alignleft”><?php echo $next_link; ?></div>
    <div class=”alignright”><?php echo $prev_link; ?></div>
    </div>

    </div>
    <div class=”cleared”></div>

    </div>

    </div>
    </div>

    <?php endif; ?>
    <?php else : ?>
    <h2 class=”center”><?php _e(‘Not Found’, ‘kubrick’); ?></h2>
    <p class=”center”><?php _e(‘Sorry, but you are looking for something that isn’t here.’, ‘kubrick’); ?></p>
    <?php if(function_exists(‘get_search_form’)) get_search_form(); ?>
    <?php endif; ?>

    </div>
    <div class=”sidebar2″>
    <?php include (TEMPLATEPATH . ‘/sidebar2.php’); ?>
    </div>

    </div>
    <div class=”cleared”></div>

    <?php get_footer(); ?>

    MichaelH

    (@michaelh)

    Oops, if you are wanting that in a category archive then you’ll need to put that in a Category Template.

    See Template Hierachy for further info on what WordPress uses to render posts in particular situations.

    nicksoper

    (@nicksoper)

    Hi HomesteadMommy

    I actually figured this one out on friday for a site of mine, where I wanted to list FAQ’s by sub category – https://www.fluxsites.com/articles/faqs/

    I am not sure if it is the most graceful way to do it (loop in a loop) but it works and is fairly easy to understand – well if I can understand the code it must be fairly trivial.

    Here is my solution if anyone wants to check it out. You could change “child_of=7” to your “Recipes” category id or remove it all together if there are no other categories, I would make recipes a sub category though, in case you want to add other categories, like news..

    <? 
    
    /* FIRST LOOP THROUGH THE CATEGORIES */			
    
    $categories=get_categories('child_of=7'); //outputs an array of child categories of category 7
    
    foreach($categories as $category) { ?>
    
    <?php $current_cat = $category->term_id; ?>
    
    <h2><a href="<?php echo get_category_link($current_cat); ?>" title="<?php sprintf( __( "View all posts in %s" ), $category->name ) ?>"><?php echo $category->name ?></a></h2>
    
    <?php 
    
    /* SECOND LOOP THROUGH THE POSTS IN THE CATEGORY WHILST IN THE FIRST LOOP */ 					
    
    $cat_post = new WP_Query('cat='.$current_cat); ?>
    
    <ul>
    <?php
    while ($cat_post->have_posts()) : $cat_post->the_post();
    $do_not_duplicate = $post->ID;
    $preview = get_post_meta($post->ID, 'preview', true);
    ?>
    
    <li><a href="<?php the_permalink(); ?>" title="Peralink to FAQ: <?php the_title(); ?>"><?php the_title(); ?></a></li>
    
    <?php endwhile; ?>
    
    </ul>
    
    <?php  } ?>

    I don’t think it would be too difficult to include a thumb or excerpt too…

    You would add that in this line, I think you could also use the normal code (the_excerpt), but I can’t say for sure as I haven’t tried.

    <li><a href="<?php the_permalink(); ?>" title="Peralink to FAQ: <?php the_title(); ?>"><?php the_title(); ?></a></li>

    Good luck

    gavindaron

    (@gavindaron)

    that works with no error
    [spam link moderated]

    odrecipes

    (@odrecipes)

    Is the above code by nicksober entered in the categories.php? If so, where?

    Thanks

    I just got this email about this thread and thought I’d post my reply here, just incase it helps:

    How did you change the link for FAQs in the sidebar to link back to your FAQs index page and not list all of the individual FAQ posts?

    The page is using a template file with the above code in it. My sidebar.php is using wp_list_categories() which is pretty much default and I haven’t really done anything in there.

    Here is the solution:
    If you put a file in your theme folder called category-ID.php where ID is the ID of the category you want to have a custom template for that specific category.

    Here is the link to the documentation explaining this functionality: https://codex.www.ads-software.com/Category_Templates#What_Template_File_is_Used.3F

    So in my case, FAQ’s is category 7, so I made a new file called category-7.php and put my code (above) in that file.

    So when you are in category 7, that template page will show.

    (You can use the category slug, or name instead of the ID, but I’d recommend using the ID incase you end up changing the name or slug of your category, or if you end up using qTranslate or something like that)

    Hope that helps.

    THANK YOU THANK YOU THANK YOU…

    that is EXACTLY what I was trying to do… brilliant!

    and especially thank you for explaining it so clearly. I’ve been able to hack my way thru a lot, but your post made this VERY simple.

    Really appreciate you sharing your learning with the rest of us. Shortened my curve substantially, today.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Listing categories and posts on pages’ is closed to new replies.