I am creating a wp template based on 2013. I want to display a ‘page’ that has some content from a page and then 6 posts on it. These posts have been selected via the themes options panel using the settings api. So I can get at each one using
$options = get_option( 'osc_theme_options' );
The template i have been using so far is based on a page so i am guessing I need to change the loop in someway.
The loop goes:
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>...
I want to know how to alter the loop so that it pulls in just the posts that have been selected. At the moment this template/loop is only pulling in the page – which I guess is fair enough.
Would it be possible to create ‘another loop’ maybe under the first that then brings in the selected posts – if so how?
Many thanks
Yes you can effectively create another loop under the existing loop to display the posts. I am not sure what
$options = get_option( 'osc_theme_options' );
returns, i.e an array of Post ID’s etc. In order to show the posts you need to do a custom loop:This is taken from:
https://css-tricks.com/snippets/wordpress/custom-loop-based-on-custom-fields/
Also see the following:
https://digwp.com/2011/05/loops/
http://www.smashingmagazine.com/2013/01/14/using-wp_query-wordpress/
So effectively it all boils down to the
$args
variable as to which posts you will get. Here is an example of multipleids
So if
$options = get_option( 'osc_theme_options' );
returns an array of post ids like so:You could probably do something like:
This is the best advice I can give without deeper knowledge of the theme etc.