Slider Revolution WP
09.06.2016
Normally to create a post-based grid, you’d have to select at least one category or tag. But if you don’t have any categories or tags assigned to these Custom Post Type posts, you can still populate an Essential Grid with the CPT posts using the following PHP code.
To use, just modify the “23” part to whatever page you want the grid to show up on, and then edit the “essential_grid” part in the code to whatever the slug is for your CPT. Then add to one of your theme’s page template files, such as “page.php”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php // Where the grid would be added to the page with ID "23" if( get_the_ID() == '23' ) { $cpt_list = array(); // edit "essential_grid" with the slug name of your CPT $cpt_args = array( 'post_type' => 'essential_grid'); $cpt_loop = new WP_Query( $cpt_args ); while ( $cpt_loop->have_posts() ) : $cpt_loop->the_post(); $cpt_list[] = get_the_id(); endwhile; echo do_shortcode('[ess_grid alias="my-grid" posts="' . implode(',', $cpt_list) . '"]'); } ?> |