{"id":4901,"date":"2020-06-03T11:28:16","date_gmt":"2020-06-03T11:28:16","guid":{"rendered":"https:\/\/the7kennisbank.nl\/?p=4901"},"modified":"2020-06-09T12:04:47","modified_gmt":"2020-06-09T12:04:47","slug":"function-render-template","status":"publish","type":"post","link":"https:\/\/the7kennisbank.nl\/nl\/wp-grid-builder\/functie-render-sjabloon\/","title":{"rendered":"Functie render-sjabloon"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>&nbsp;<\/p>\n<div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element \" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<div>\n<div class=\"container flex items-center justify-between\">\n<h1 class=\"entry-title\">wpgb_render_template<\/h1>\n<\/div>\n<\/div>\n<div id=\"article-wrapper\" class=\"container\">\n<p>This function allows to query and output posts, terms, or users with your own markup without the grid and card system. You will be able with this function to use the facet system as stand alone (thanks to <code><a href=\"https:\/\/the7kennisbank.nl\/resources\/function-render-facet\/\">wpgb_render_facet()<\/a><\/code> function) without creating grids or cards.<\/p>\n<table>\n<tbody>\n<tr>\n<td>Argument<\/td>\n<td>Type<\/td>\n<td>Description<\/td>\n<\/tr>\n<tr>\n<td>id<\/td>\n<td>mixed<\/td>\n<td>Template id\/name<\/td>\n<\/tr>\n<tr>\n<td>class<\/td>\n<td>string<\/td>\n<td>Class name of the layout wrapper holding posts<\/td>\n<\/tr>\n<tr>\n<td>source_type<\/td>\n<td>string<\/td>\n<td>Object type to query (post_type, term, user)<\/td>\n<\/tr>\n<tr>\n<td>is_main_query<\/td>\n<td>boolean<\/td>\n<td>To replace loop in archive\/index\/search.php templates<\/td>\n<\/tr>\n<tr>\n<td>query_args<\/td>\n<td>array<\/td>\n<td>Holds query arguments<\/td>\n<\/tr>\n<tr>\n<td>render_callback<\/td>\n<td>string<\/td>\n<td>Function name of the render callback<\/td>\n<\/tr>\n<tr>\n<td>noresults_callback<\/td>\n<td>string<\/td>\n<td>Function name of the no results callback<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can add this function anywhere in your PHP file to output a filterable template. This function can also replace the main loop of the <code>archive.php<\/code>, <code>index.php<\/code> or <code>search.php<\/code> files. In this case you need to set <code>is_main_query<\/code> to <code>true<\/code><\/p>\n<p><strong>If you set <\/strong><code>is_main_query <\/code><strong>to <\/strong><code>true<\/code><code>query_args<\/code><strong>parameter will be ignored<\/strong> because it\u2019s handle by WordPress template.<\/p>\n<div class=\"code-syntax-block code-syntax-wrapper\">\n<p>[pastacode lang=&#8221;php&#8221; manual=&#8221;wpgb_render_template(%0A%09%5B%0A%09%09&#8217;id&#8217;%20%3D%3E%20&#8217;my-template&#8217;%2C%0A%09%09&#8217;class&#8217;%20%3D%3E%20&#8221;%2C%0A%09%09&#8217;source_type&#8217;%20%3D%3E%20&#8217;post_type&#8217;%2C%0A%09%09&#8217;is_main_query&#8217;%20%3D%3E%20false%2C%0A%09%09&#8217;query_args&#8217;%20%3D%3E%20%5B%0A%09%09%09&#8217;post_type&#8217;%20%3D%3E%20&#8217;product&#8217;%2C%0A%09%09%09&#8217;posts_per_page&#8217;%20%3D%3E%2010%2C%0A%09%09%5D%2C%0A%09%09&#8217;render_callback&#8217;%20%3D%3E%20&#8217;prefix_render_callback&#8217;%2C%0A%09%09&#8217;noresults_callback&#8217;%20%3D%3E%20&#8217;prefix_noresults_callback&#8217;%2C%20%0A%09%5D%0A)%3B&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n<\/div>\n<p><strong>The callback functions must be placed in functions.php<\/strong> or in a plugin file for example. The facet system will not load the PHP file where you placed the function <code>wpgb_render_template()<\/code> for performance reason. For this reason the callback must be a string (function name) and not the function itself.<\/p>\n<div class=\"code-syntax-block code-syntax-wrapper\">\n<p>[pastacode lang=&#8221;php&#8221; manual=&#8221;%3C%3Fphp%0A%0A%2F**%0A*%20This%20callback%20is%20called%20for%20each%20post%20in%20the%20loop.%0A*%0A*%20%40param%20object%20%24post%20Holds%20post%2C%20term%20or%20user%20object%20(depending%20of%20the%20source_type).%20%0A*%2F%0Afunction%20prefix_render_callback(%20%24post%20)%20%7B%0A%0A%09%3F%3E%20%0A%09%3Carticle%3E%0A%09%09%3C%3Fphp%20the_title(%20&#8217;%3Ch3%3E&#8217;%2C%20&#8217;%3C%2Fh3%3E&#8217;%20)%3B%20%3F%3E%0A%09%09%3C%3Fphp%20the_excerpt()%3B%20%3F%3E%20%0A%09%3C%2Farticle%3E%0A%09%3C%3Fphp%0A%0A%7D%0A%0A%2F**%0A*%20This%20callback%20is%20called%20when%20no%20results%20match%20selected%20facets.%20%0A*%2F%0Afunction%20prefix_noresults_callback()%20%7B%0A%0A%09%3F%3E%0A%09%3Cp%3E%0A%09%3C%3Fphp%20esc_html_e(%20&#8217;Sorry%2C%20no%20results%20match%20your%20search%20criteria.&#8217;%2C%20&#8217;text-domain&#8217;%20)%3B%20%3F%3E%3C%2Fp%3E%0A%0A%09%3C%3Fphp%0A%7D&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n<\/div>\n<\/div>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>&nbsp;<\/p>","protected":false},"author":2,"featured_media":4996,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[44,50,43],"tags":[],"class_list":["post-4901","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation","category-php-functions","category-wp-grid-builder","category-44","category-50","category-43","description-off"],"acf":[],"_links":{"self":[{"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/posts\/4901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/comments?post=4901"}],"version-history":[{"count":6,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/posts\/4901\/revisions"}],"predecessor-version":[{"id":6095,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/posts\/4901\/revisions\/6095"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/media\/4996"}],"wp:attachment":[{"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/media?parent=4901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/categories?post=4901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the7kennisbank.nl\/nl\/wp-json\/wp\/v2\/tags?post=4901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}