What i’m missing in the query loop is being able to add a parent page. Even though, while writing this, i might have overlooked something.
It’s not that obvious, but it’s there.
Click the +
next to FILTER and select PARENT. This will enable the PARENT filter. Begin typing the title of the parent page into the PARENT filter box, and the page will appear for you to select it.
Would i then create a new page-{slug}.php
and put all coding there? Preferably i would like to have the query/ function neatly embedded in the wp file system. And subsequently call the function via a shortcode..
The last sentence is not necessary at all: there’s no need to create any shortcode function to use your custom template.
If you create the template file named page-{slug}.php
… you simply have to create a PAGE with the same slug used in the file name, and this page will automagically use the custom template you created, loading all the content + code in that template file.
For eg, if you created the template file page-community.php
, you’ll create a PAGE with the slug community
…
… and the permalink https://example.com/community/
will automatically use the custom template you created.
The page can be completely blank (loading all its content from the template), or you could add additional content in the editor.
See the documentation pages below on creating custom template files and the WordPress template hierarchy, which determines the template file WordPress uses to display content in different contexts.
Note that you could also create a generic template if you want to reuse this across multiple pages and even posts. Even here, you don’t need to create/use any shortcode: in the editor, you can select the desired custom template to use for individual posts/pages if these custom templates exist.
https://developer.wordpress.org/themes/basics/template-hierarchy/
https://developer.wordpress.org/themes/template-files-section/page-template-files/
-
This reply was modified 1 week, 2 days ago by
George Appiah. Reason: Fixed formatting