Building a wordpress site that needs to organize content by stream – e.g Mechanical, Electrical etc. Also, each page needs sections like News, Articles events etc. If you pick one page (say Mechanical) it has to have the following sections
- News
- Articles (category:articles)
- Events (category:events)
The other streams will have the same sections as well
Is there a plugin for achieving or would I be better off building a template page for each vertical and writing php code? Shown code for a page with a single section.
<?php
$args = array(
'posts_per_page' => 1,
'category_name' => 'news',
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args );
$the_query = new WP_Query($args);
//EXAMPLE NEWS SECTION
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_content();
echo $content;
}
} else {
// no posts found
}
?>
In my opinion you could just write a plugin which does that filtering.
Said plugin would have some kind on shortcode that would take a parameter (category for instance) and would return or echo all the posts associated with that category.
Shortcode registration :
Shortcode function:
Usage
In your case a page could be something like that
I don’t think there is one right way to do this… it depends on the scenario… How many posts, how often do sections or “main streams” get added / change, do you need other stuff on the pages etc.
One pretty simple and easily maintained solution would be to:
1.
Addmechanical
,electrical
, etc. as categories alongsidenews
,articles
andevents
2.
Modify (or add)category.php
to repeat the loop three times, and only display the posts that belong to each section (other category):Now just assign each post to one (or more) “parents”, fx
mechanical
, and also to one (and only one) ofnews
,articles
orevents
…mechanical
you get three sectionsnews
you get all news (but also two empty sections, so you should of course check for that).Note that this could be done using tags or even a custom taxonomy if you wanted, you’d just need to edit a different theme file – see the template hierarchy.
Beware though that this will not work very nicely with pagination, so if that is a concern you will need to deal with that.