First thing, English is not my native language, and I am pretty new to programming, PHP and WordPress, so please be patient and very simple in your answers :)
I am creating a custom theme for a multi-feature blog displaying videos, articles, movie reviews, image galleries, events and a shopping area where visitors can buy and download some e-books.
In the front page I want to show a sort of general summary of last entries, including:
- last 3 entries for each of 3 different blog-post categories (articles, movie reviews, videos);
- next 3 incoming events
- last 3 past events
- last 3 published galleries
- last 3 downloadable e-books
My question is: do I need to call 7 different WP_Query objects to have it working, one for each category/post_type, or are there better ways to get it done?
Maybe using the pre_get_posts hook, or some conditional tags like get_post_type() or is_category()? I tried those and some other ways but my lack of programming skills got me nowhere. Any suggestion is very welcome.
(added the relevant parts of code I am actually using)
<!-- // start Front Page contents - BLOG-->
<!-- start tab dei post -->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','category_name' => 'post' ) ); ?>
<!--// seleziona risultati per categoria - POST -->
// here is included the Loop for - POST
<?php wp_reset_postdata(); ?>
<!-- end tab dei post -->
<!-- start tab rece -->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','category_name' => 'rece' ) ); ?>
<!--// seleziona risultati per categoria - RECE -->
// here is included the Loop for - REVIEWS
<?php wp_reset_postdata(); ?>
<!-- end tab rece -->
<!-- start tab video -->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','category_name' => 'vide' ) ); ?>
<!--// seleziona risultati per categoria - VIDE -->
// here is included the Loop for - VIDEOS
<?php wp_reset_postdata(); ?>
<!-- end tab video -->
<!-- // end Front Page contents - BLOG-->
<!-- // start Front Page contents - GALL-->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','category_name' => 'gall' ) ); ?>
<!--// Start our WP Query-->
// here is included the Loop for - GALLERIES
<?php wp_reset_postdata(); ?>
<!-- // end Front Page contents - GALL-->
<!-- // start Front Page contents - BOOK-->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','post_type' => 'download' ) ); ?>
<!--// seleziona risultati per categoria - BOOK -->
// here is included the Loop for - DOWNLOADS
<?php wp_reset_postdata(); ?>
<!-- // end Front Page contents - BOOK-->
<!-- // start Front Page contents - EVEN-->
<!-- start tab EVENTI FUTURI -->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','post_type' => 'event','scope' => 'future' ) ); ?>
<!--// Start our WP Query-->
// here is included the Loop for - Incoming Events
<?php wp_reset_postdata(); ?>
<!-- end tab EVENTI FUTURI -->
<!-- start tab EVENTI PASSATI -->
<!-- // Define our WP Query Parameters-->
<?php $the_query = new WP_Query( array( 'posts_per_page' => '3','post_type' => 'event','scope' => 'past' ) ); ?>
<!--// Start our WP Query-->
// here is included the Loop for - Past Events
<?php wp_reset_postdata(); ?>
<!-- end tab EVENTI PASSATI -->
<!-- // end Front Page contents - EVEN-->