There are quite a few ways to showcase your posts in WordPress, but I’ve found many of the archive functions to be pretty lacking. WordPress was conceived as a blog first, and a content management system second, so if you want users to be able to browse and locate particular content you might want to do just a bit if legwork. jQuery UI always offers some quick and efficient interfaces, if we couple this resource along with some mild modifications to a pretty basic wordpress post loop, we can get a nice clean easy to use index of posts. For a bonus, I’ve added the ability to designate a root category, so you can have multiple accordion on appropriate pages, or perhaps showcase something like an article category.
The php
I’ve borrowed from a few tutorials and examples in the codex to build a fairly bread and butter loop here. Note the child_of setting here. The divs, headings and list items are designed to be super friendly for the UI accordion. You could even leave things here for a nice clean archives page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | // Start building our HTML $accordion = '<div id="archives_accordion">'; // Define our parent category $categories = get_categories('child_of=8'); // Get all the children of the designated category foreach ( $categories as $category ) { $currentCat = $category->term_id; $accordion .= '<h2><a href="#">'.$category->cat_name.'</a></h2>'; $accordion .= '<div><ul>'; // Define the current category $queryargs = 'cat='.$currentCat; query_posts($queryargs); // The query if ( have_posts() ) : while ( have_posts() ) : the_post(); $accordion .= '<li><a href='.get_permalink().'>'.get_the_title().'</a></li>'; endwhile; else: endif; // Destory the previous query, get ready for the next wp_reset_query(); // End This Category $accordion .= '</ul></div>'; } // End The Accordion $accordion .= '</div>'; // Print the whole thing out echo $accordion; |
jQuery UI
For best performance you might want some local fallbacks, but if speed is in order using the Google APIs will get us going in a snap.
1 2 |
jQuery
We’ve already done most of the work, the jQuery can be squeezed into a single neat line at this point and we’re good to go!
The Demo
The final product can be inserted into a post template or inserted directly using exec-php.
Client Management
Planning a Website Development
Snippets and Demos
- Live Form Validation on Load
- Custom Careers Module for DNN with Xmod Pro
- Ajax Calls from an ASP Web Service
- Customizing the DNN login Header Stack
- Google Maps API V3 Integration Part 1
- Select Input/Combobox Based Navigation
- Clear on Focus, Watermark, or Hint Text Input Field
- A Simple jQuery FAQ style Show and Hide
DotNetNuke
The Website Design Process
Tips and Tricks
- A WordPress Post Category Accordion
- Make Visual Studio Front End Developer Friendly in 3 Easy Steps!
- Missing Windows from Using Multiple Monitors
- Adding an Image Rotator to your WordPress Site
- WordPress Monthly Archives for a Category
- A Google based calendar for wordpress.
- Adding Comments to a WordPress Page