Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the faculty-weekly-schedule domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/codebangers.com/httpdocs/wp-includes/functions.php on line 6114

Deprecated: Creation of dynamic property Simple_Code_Block_Loader::$shortcodes is deprecated in /var/www/vhosts/codebangers.com/httpdocs/wp-content/plugins/simple-code-block/core/class-simple-code-block-loader.php on line 61

Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /var/www/vhosts/codebangers.com/httpdocs/wp-content/themes/shop-isle/vendor/codeinwp/themeisle-sdk/load.php on line 31

Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /var/www/vhosts/codebangers.com/httpdocs/wp-content/themes/shop-isle/vendor/codeinwp/themeisle-sdk/load.php on line 36

Deprecated: Creation of dynamic property ThemeisleSDK\Product::$author_url is deprecated in /var/www/vhosts/codebangers.com/httpdocs/wp-content/themes/shop-isle/vendor/codeinwp/themeisle-sdk/src/Product.php on line 188

Deprecated: Creation of dynamic property Shopisle_Admin_Page::$theme_name is deprecated in /var/www/vhosts/codebangers.com/httpdocs/wp-content/themes/shop-isle/inc/admin/class-shopisle-admin-page.php on line 18

Deprecated: Creation of dynamic property Shopisle_Admin_Page::$theme_slug is deprecated in /var/www/vhosts/codebangers.com/httpdocs/wp-content/themes/shop-isle/inc/admin/class-shopisle-admin-page.php on line 19
Wordpress Shortcode to Display the Loop – CodeBangers

WordPress Shortcode to Display the Loop

Just paste this into your theme’s function file.

'true',
"query" => '',
"category" => '',
), $atts));
global $wp_query,$paged,$post;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
if($pagination == 'true'){
$query .= '&paged='.$paged;
}
if(!empty($category)){
$query .= '&category_name='.$category;
}
if(!empty($query)){
$query .= $query;
}
$wp_query->query($query);
ob_start();
?>

    have_posts()) : $wp_query->the_post(); ?>



Once your functions.php file is saved, you can display a loop :

[loop category="news" query="" pagination="false"]

Note that this code have been created to been used in pages. It have some oddity when used in a post.

Thanks to John Turner for this great piece of code!

Leave a Reply