I’m trying to sort of emulate the Views behaviour in Drupal with WordPress, but doing it in theme templates.
Now, I have pages that are assembled by using wp_query
in the template to get posts belonging to a certain category.
But now I also want to be able to create another page which performs a query to get all the pages above, but only the content actually in those pages, not the content in the posts within them. Taking this a step further, I would actually have wanted to be able to refer to specific fields within the target page and display them. The end result should be a sort of post list on this page with the titles and introductions of each of the “assembled” pages.
I should mention that I am quite new to both Drupal and WordPress, and am pretty much testing them both out to try to decide what suits my site best (not a blog!) So far I have liked the Views and Panels approach of Drupal, but in most other aspects WordPress has seemed more suitable.
But how would one go about doing the above task in WordPress?
I have managed to get the desired result by doing this (at least getting the page in question, and only the content in it, not the posts. But I cannot select more granular information though):
$my_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => array( 76, 151 )
) );
But that means having to specify particular page ids, which is undesirable. I want it to be possible for users to add pages to be included in the summary page just by adding a tag or category on them. I have not been able to manage to use categories or tags to select the same content as above though (even though I have plugins installed to allow both on pages).
It sounds like you really need to be using posts for your content rather than pages since you want to organize your content into categories. You can use a page to display a custom page template (the
Template Name:
comment as shown below defines a new page template; that template will then be available as a in a dropdown near the page “publish” button). This template can show metadata from posts in a particular category by using code similar to this: