1

I'm looking for the best way to go about creating, probably, custom post type where you can filter in the categories related to that custom post type in the sidebar.

Here is the website I'm working on. Originally the student and donor profiles should be some type of post or category that can dynamically be updated when a new profile is created. So Health & Science, Student Success and Creative community have their own set of specific profiles.

So lets say John Doe is a new student profile for Student Success I can tag him to feed through that page alone and when viewing his individual post I'm having trouble displaying the categories or profiles that are related, in this case Student Success. So when viewing John Doe's profile the other profiles under student success should be listed on the sidebar.

I noticed wordpress shares the single.php template file so the sidebar I have for the single.php file is being used for the profiles which we don't want.

Overall, if you run through Health & Science, Student Success and Creative community I'm looking for a set up like that but instead of a 4 step process that the client has to do when uploading a new profile I am looking for just a one step process.

My current set up is you add the new profile as a page then go to the menus area in the dashboard and add the new profile to the menu.

My current page template code.

  • So basically what you want, is for the sidebar that's in single.php to detect the post being pulled in the page template and use a category or post type to determine what related profiles/posts to show? So right now Health & Science, Student Success and Creative community are just pages with templates versus a custom post type? – RachieVee Jun 26 '14 at 15:08
  • Yes. I been looking into the conditional statements that wordpress uses but I can't figure how I can get it to read that page and show the related post. – jose Jun 26 '14 at 17:15
  • Ok give me a bit of time to try and imitate what you want in a WordPress install of mine and I'll see what I can provide. – RachieVee Jun 27 '14 at 14:32
  • I appreciate your help @RachieVee. If it starts to become to much trouble you don't have to worry about it. Thanks! – jose Jun 27 '14 at 15:03
  • Oh man, haha, yeah it's taking me a while, but if you don't mind that I don't provide code, I can at least try and point you in the right direction. I see in your template that you're querying posts with a category - why not create a new loop in your Donor Profiles area that gets posts by that category and lists out the links (assuming the category is something like Health-Science or one of your three sections)? Or you can use post meta in your profiles if you don't want to pull a category for a menu created with a get_posts loop. I feel like I didn't make sense? Let me know. – RachieVee Jun 27 '14 at 15:21
1
 <?php

$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5,'post_type' => 'news', 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
        <li>
        <?php  the_post_thumbnail(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>

        </li>

<?php }
wp_reset_postdata(); ?>
  • 3
    How does this answer the question? – Rarst Sep 9 '14 at 6:56
  • This did work for me.. – rwzdoorn Jul 15 '15 at 11:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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