Title: Display Category Box with posts inside
Last modified: August 19, 2016

---

# Display Category Box with posts inside

 *  Resolved [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/)
 * I would appreciate any help with this. I’m teaching myself how to customize WordPress
   and I’ve run into a roadblock.
 * URL – [http://www.journeysbysteve.com/sandnsun](http://www.journeysbysteve.com/sandnsun)
 * On this theme, there are a series of boxes beneath the slider (under the heading
   Latest News). Currently, this theme is set up to display the most recent post
   from a category.
 * I would like to change this so that the box shown has a permanent category, and
   I can have some intro text with a list of that category’s last three posts linked
   within the box. (Lordy, I hope I explained that well enough..)
 * I’ve tried this and that and broken the theme so many times that I admit needing
   help!
 * Can anyone guide me here? Thanks!!

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/display-category-box-with-posts-inside/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/display-category-box-with-posts-inside/page/2/?output_format=md)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454724)
 * To clarify what you’re asking, let me see if i have this right..
 * Instead of each of those boxes pulling in the content/title, etc. from seperate
   posts, you’d like to change that to now pull in a category each, and list 3 posts
   from each of those categories.
 * Would that be correct?
 * 8 boxes, currently 8 posts, to be switched for 8 categories showing the 3 most
   recent posts for each relevant category.
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454741)
 * Yes, that’s correct!
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454742)
 * If you paste the contents of whatever file renders those boxes into a [pastebin](http://wordpress.pastebin.com/),
   and report the link back here we can work from there… 🙂
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454803)
 * Here you are – the portion of the code that creates the current view, and the
   stylesheet portion that relates to that code.
 * [http://wordpress.pastebin.com/hTK7y7Y4](http://wordpress.pastebin.com/hTK7y7Y4)
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454808)
 * Great.. 🙂 Do you have 8 categories in mind you want to use, or do you have a
   particular number of categories in mind? And how do you want to determine which
   categories to use? By name, by ID, or by pulling the data from somewhere you’ve
   stored it in the database already?
 * What should happen if a chosen category doesn’t have posts? .. hide the box, 
   or show it with a message?
 * Should be pretty simple, but i’d rather not have to make dozens of changes, so
   i just want to be clear about how you are expecting the code to work… 😉
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454830)
 * I do prefer to use category IDs. I have set categories but want to be able to
   change them later if needed – cat id’s seem to be the best way to do that. Keeping
   the box even if there are no posts is kosher, too. Kind of need to do that to
   maintain integrity of the design, methinks.
 * I like how the design is now, with a picture for the box (optional) – not sure
   how to add that unless I do it “traditionally.”
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454859)
 * I see an issue here in that in order to query for 3 posts from each category 
   you’ll end up needing 8 queries to the database to archieve you want (one per
   category).
 * If that’s acceptable i can provide something no problem, but there may obviously
   be downsides to doing so if you’re loading this on the main page, since those
   8 queries will run in additional to any other queries throughout the page.. (
   you’ll like have anything upwards of 15 queries on your main page(looking at 
   what you have on there already)).
 * I’m going to have a little think about how i/we might be able to create a custom
   query to do it in one, rather than several.
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454864)
 * I hadn’t thought about that – I don’t want to drive up the calls (I think there’s
   plenty already1) needed to load the page. We can eliminate the calls, and have
   a “read more” type of link that will link to the category page listing all the
   posts. If that’s done, I’d like to be able to custom edit text within the box
   as a teaser – doesn’t have to be something queried but can be hardcoded into 
   the code itself.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454872)
 * I think writing a single query for this is beyond me (i’m not sure such a query
   could be written either), what do you want to do about displaying data in those
   boxes?..
 * Maybe a comprimise would be limit those posts to one particular category? (that’s
   dead easy to do – leaving it still pulling posts).
 * Or another idea could be.. to pull the category descriptions into those boxes(
   assuming you’ve given them descriptions), and have a link that points to that
   given category’s page? You’d then having something to fill the boxes with. Basically,
   the title would become the category name, the post content becomes the category
   description, and the readmore link becomes a link to that category’s archive 
   page (or something like that).
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454917)
 * I like the category description idea. I’ve rarely used that field in WP but I’ve
   seen themes that do use them. I’ll have to dig around and see how to put that
   together; not really sure how to do that AND keep an image in the box too, since
   the original theme pulls the image from a post custom field (I think).
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454927)
 * Well i’m sure we could find a way to pull some images to go alongside the category
   data if you want to.
 * Something like, if an image exists with a name that matches the category, put
   it in, else use a default(or none)… Or if you’re using 8 set categories anyway,
   then we could pull the images and categories both in by ID/name (if they’re not
   changing, i think it would make sense to just pull them in via ID or name).
 * I’m here if you need to some help with implementation, or if you’d like an example
   to work from, then i’m sure i could provide one.. 🙂
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454935)
 * I would appreciate an example – all my attempts at changing it screw things up
   horribly and don’t turn out how I thought they would.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454938)
 * Give this a try, taking care to insert it correctly (it’s just the only opening
   and closing PHP tags you need be aware of).
 * [http://wordpress.pastebin.ca/1859071](http://wordpress.pastebin.ca/1859071)
 * Adjust the string at the top so it contains the IDs of the categories you wish
   to use..
 * **NOTE:** Unfortunately i couldn’t find an easy way to reference or lookup an
   attachment based on name, so the alternative(which may or may not be suited),
   was to opt for looking in the theme’s folder for images with a name matching 
   the category. If you’re using 8 set categories i can’t see why this should be
   problematic.
 * A few things were assumed(which you can easily change), firstly that the files
   would be directly in the theme’s main folder, secondly that the image would have
   a PNG extension, and additionally that an image called defaultcat.png exists 
   to sit in place of those that don’t exist. Each of these things can be changed
   wtih relative ease though.
 * Let me know how the code works out for you..
 *  Thread Starter [Steve Cousino](https://wordpress.org/support/users/sacousino/)
 * (@sacousino)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454956)
 * Sorry I haven’t gotten back before now. I’ve been out of town at a conference(
   yecch).
 * Thanks for the code – it worked! (Took me a few minutes to get it right along
   with the original code) I’m studying it to see what you did and why, and if I
   have any questions I will ask.
 * I appreciate it very much!
 *  [michaelmf](https://wordpress.org/support/users/michaelmf/)
 * (@michaelmf)
 * [16 years ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/#post-1454989)
 * This is exactly what I need. Just a question, where exactly do I paste it in 
   the code? Do I replace another part of the Main Index code?
 * Thanks!

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/display-category-box-with-posts-inside/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/display-category-box-with-posts-inside/page/2/?output_format=md)

The topic ‘Display Category Box with posts inside’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 17 replies
 * 4 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/display-category-box-with-posts-inside/page/2/#post-1455007)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
