Adding IssueM articles to your homepage posts list

Let’s say the main component of your current homepage is a list of the most recent posts. You’ve installed IssueM, created articles and now you’d like that list to include articles as well.

By default, WordPress will not include any custom post types, such as articles. This is a sensible approach as WordPress doesn’t really know what types it should or should not include, so it plays it safe and just sticks to posts.

So, you have to specifically let WordPress know that you want to include <em>articles</em> in that homepage list. The bad news is that there’s no switch you can just throw in the admin interface; the good news is that you just have to add a snippet of code to a single file in your WordPress theme.

Open up your theme’s functions.php file* and add this code at the bottom:

<br> function add_articles_to_homepage( $query ) {<br> if ( !is_admin() && is_home() && $query->is_main_query() ) {<br> $query->set( 'post_type', array( 'post', 'article') );<br> }<br> return $query;<br> }<br> add_action( 'pre_get_posts', 'add_articles_to_homepage' );

Click Save and you're done.

This function will cause WordPress to look for articles as well as posts when building the list. Of course, you don’t want WordPress to do that every time it’s retrieving content so you’ve narrowed it down to the main list on the home page of the public site.

Using A Shortcode Or Page Designer For Your Home Page?

If you are using a shortcode or a page designer for your home page then unfortunately this approach probably won’t work. The plugin will likely be using its own query to get a post list and therefore will not be considered the main query.

In this case, check the plugin’s documentation or settings panel in the admin interface. The better solutions will support custom post types and it may be as simple as clicking on a checkbox.

Adding Code To The functions.php File

Just be aware that if you add code to the functions.php file of your theme, then you are likely to lose it if the theme is updated.

The best way to make these sorts of changes to a theme is to create a child theme. The WordPress Codex has plenty of guidance on how to create child themes.

Still need help? Contact Us Contact Us