0

I'm not familiar enough with wordpress to ask the question directly, so please bare with me as I explain what I'm looking for.

I have four primary sections of my business (A, B, C & D, for example).

  • each section has it's own page
  • each section also has a category with the same name
  • various pages and posts are categorized under each section

I want an area in the sidebar (probably a widget) to show N (probably ~5) summaries of items categorized as A on page A. And the same on pages B, C & D.

Remembering that I am a Drupal developer who does not know the Wordpress landscape very well, how would I go about this? Is there a ready-built widget or am I looking at something custom?

1

You can use this plugin http://wordpress.org/plugins/posts-in-sidebar/screenshots/

and use widget logic to display particular category posts http://wordpress.org/plugins/widget-logic/screenshots/

Please add is_page('A') in widget logic section Then select posts form category A in posts in sidebar

  • This does work but isn't particularly scaleable. – mrwweb Oct 23 '13 at 21:29
  • @mrwweb: agreed. I did end up using this but I don't love it for this reason. Required adding a widget to the sidebar for each category. I found the wordpress.org/plugins/related-posts plugin which uses it's own logic (it does not use categories in the way I had intended), but does a very nice job. If the client is careless about categorizing things, we may just use this instead. – doub1ejack Oct 24 '13 at 17:32
1

I would probably ditch categories and use the Parent field which is for establishing a hierarchical relationship between pages. You'd then use WP_Query to make a custom loop outputting your summaries.

You'd end up with something like this:

<?php $related_posts = new WP_Query( array(
    'post_type' => 'page',
    'posts_per_page' => 5,
    'post_parent' => $post->ID
));
if( $related_posts->have_posts() ) : while( $related_posts->have_posts() ) : $related_posts->the_post(); ?>
    <article class="hentry">
        <h1 class="entry-title"><?php the_title(); ?></h1>
        <div class="entry-summary"><?php the_excerpt(); ?></div>
    </article>
<?php endwhile; endif; ?>

Categories could work and you'd just need to use a different query, but the Parent field is made for this exact purpose. It lives for this. I could also imagine a solution using menus to manage the relationship, but I like Parent still.

If you want this to be a widget, it wouldn't take much to wrap this up as a widget.

  • I like this approach more, but due to time constraints didn't follow up on it. I was thinking of using your logic either with the php-code-widget or with the section-widget and your code in a custom shortcode (nice article here: wp.smashingmagazine.com/2012/05/01/…) – doub1ejack Oct 24 '13 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.