How to use shortcode inside page templates?
WordPress has a great function, do_shortcode(), that will allow you to use shortcodes inside your theme files. For example, to output Posts in a Theme file, you would do this:
<?php echo do_shortcode('[gs_wpposts theme="gs_wppost_grid_1"]'); ?>
GS Posts Grid’s shortcode usage
[gs_wpposts theme="gs_wppost_grid_1"]
GS Posts Grid’s Shortcode attributes Usage
[gs_wpposts theme="gs_wppost_grid_1" cols="4" num="9" desc_limit="250" group="" order"DESC" orderby="date"]
Shortcode PHP Usage
<?php echo do_shortcode( '[gs_wpposts theme="gs_wppost_grid_1"]' ); ?>
Template Usage – Add the shortcode anywhere you need to display GS Posts Grid in template files (header.php, front-page.php, etc.)
<?php echo do_shortcode( '[gs_wpposts theme="gs_wppost_grid_1" cols="4" num="9" desc_limit="250" group="" order"DESC" orderby="date"]' ); ?>
No. | Attribute | Default value | options | Description |
---|---|---|---|---|
1 | num | -1 | -1 for all or any number | By default it’ll display all the Latest Posts but you can control it by num attribute. |
2 | theme | gs_wppost_grid_1 | gs_wppost_grid_1 gs_wppost_grid_2 gs_wppost_grid_3 gs_wppost_horizontal_1 gs_wppost_horizontal_2 gs_wppost_horizontal_3 gs_wppost_horizontal_4 gs_wppost_horizontal_5 gs_wppost_horizontal_6 gs_wppost_list_1 gs_wppost_list_2 gs_wppost_list_3 gs_wppost_list_4 gs_wppost_card_1 gs_wppost_card_2 gs_wppost_table_1 gs_wppost_table_2 gs_wppost_table_3 gs_wppost_grey_1 gs_wppost_grey_2 gs_wppost_slider_1 gs_wppost_slider_2 gs_wppost_slider_3 gs_wppost_popup_1 gs_wppost_popup_2 gs_wppost_filter_1 gs_wppost_filter_2 gs_wppost_filter_selected_cats gs_wppost_masonry1 gs_wppost_masonry2 gs_wppost_masonry3 gs_wppost_justified1 | Select preferred theme to display Posts |
3 | cols | 3(4 columns) | 6 (2 Columns) 4 (3 columns) 3 (4 columns) | Number of column/s to display Posts. Columns are based on 12 grids Bootstarp, so follow columns value |
4 | group | all | Post category slug, comma separated. | To get your category slug, go to Posts > Categorirs. Here you will find Categorirs & all the slugs |
5 | desc_limit | 100 | Any Number | Set maximum number of characters in Post details. Default 100 |
6 | order | DESC | DESC ASC | Normally Posts will display by descending order, latest will show first. But if you wish to display ascending order, oldest at first then pass order="ASC" parameter. |
7 | orderby | date | ID title modified rand | Use preffered orderby attribute |