Skip to content

Instantly share code, notes, and snippets.

@barbwiredmedia
Created October 24, 2013 16:54
Show Gist options
  • Save barbwiredmedia/7140916 to your computer and use it in GitHub Desktop.
Save barbwiredmedia/7140916 to your computer and use it in GitHub Desktop.
WordPress Templates - Multidimensional Array , while loop , loopcount. Creates an array of multiple variables to loop through until finished. PageID is parent and is used to find children / ancestors
<?php
$argsArray = array(
array("pageID" => '496', "catID" => '41'),
array("pageID" => '519', "catID" => '35'),
array("pageID" => '522', "catID" => '40'),
array("pageID" => '1687', "catID" => '38'),
array("pageID" => '524', "catID" => '36'),
);
//print_r($argsArray);
$loopcount = 0;
while ($argsArray[$loopcount]) {
?>
<?php if (is_page($argsArray[$loopcount][pageID]) || $post->post_parent == $argsArray[$loopcount][pageID] || ($post->ancestors && in_array($argsArray[$loopcount][pageID], $post->ancestors) )) { ?>
<h3> News Posts</h3>
<ul>
<?php
//Query Post s belowing to a specific category related to the page
$args = array('post_type' => 'post', 'numberposts' => 5, 'category' => $argsArray[$loopcount][catID], 'order' => 'DESC', 'orderby' => 'date');
$lastposts = get_posts($args);
foreach ($lastposts as $post) : setup_postdata($post);
?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
</ul>
<h3>Case Studies</h3>
<ul>
<?php
//Queries for all pages that are childern of our parent ID
?>
<?php
query_posts(array('showposts' => 15, 'post_parent' => $argsArray[$loopcount][pageID], 'post_type' => 'page', 'order' => 'DESC', 'orderby' => 'date'));
while (have_posts()) {
the_post();
?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php } ?>
<?php wp_reset_query(); ?>
</ul>
<?php } ?>
<?php
$loopcount++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment