Skip to content

Instantly share code, notes, and snippets.

@mattboon
Created June 29, 2011 21:57
Show Gist options
  • Save mattboon/1055110 to your computer and use it in GitHub Desktop.
Save mattboon/1055110 to your computer and use it in GitHub Desktop.
WordPress Section Index w/ shortcode and many options
<?php $the_content = apply_filters('the_content', $post->post_content);
$the_content = explode("<p>[MENU]</p>",$the_content); ?>
<?= $the_content[0]; ?>
<?php
/* GET CUSTOM FIELDS */
$menu_type = get_post_meta($post->ID, 'menu_type', true);
$menu_page_curl = get_post_meta($post->ID, 'menu_page_curl', true);
$menu_custom_array = get_post_meta($post->ID, 'menu_custom_array', true);
$menu_more_text = get_post_meta($post->ID, 'menu_more_text', true);
$menu_more_id = get_post_meta($post->ID, 'menu_more_id', true);
/* SET TYPE CONDITONALS */
if($menu_type=='' || $menu_type=='Default' || $menu_type=='Square') {
$menu_type_class = ' square';
$menu_columns_class = ' three-cols';
$menu_thumb_type = 'square-thumb';
$menu_fallback_width = 210;
$menu_fallback_height = 210;
}
elseif($menu_type=='Polaroid') {
$menu_type_class = ' polaroid';
$menu_columns_class = ' three-cols';
$menu_thumb_type = 'polaroid-thumb';
$menu_fallback_width = 188;
$menu_fallback_height = 146;
}
elseif($menu_type=='Letterbox (White)') {
$menu_type_class = ' letterbox';
$menu_columns_class = ' two-cols';
$menu_thumb_type = 'letterbox-thumb';
$menu_fallback_width = 80;
$menu_fallback_height = 80;
}
elseif($menu_type=='Letterbox (Green)') {
$menu_type_class = ' letterbox related';
$menu_columns_class = ' two-cols';
$menu_thumb_type = 'letterbox-thumb';
$menu_fallback_width = 80;
$menu_fallback_height = 80;
}
?>
<?php global $pages_array; ?>
<?php $menu_custom_array ? $pages_array = explode(",", $menu_custom_array) : $pages_array = ''
/* IF NO CUSTOM ARRAY, SET NULL */ ?>
<?php query_posts( array( 'post_parent' => $post->ID, 'post_type' => 'page', 'posts_per_page' => -1, 'orderby' => 'title,menu_order', 'order' => 'ASC', 'post__not_in' => $excluded_pages_array, 'post__in' => $pages_array ) );
/* QUERY PAGES */ ?>
<?php if (have_posts()) : ?>
<section class="sub-pages<?= $menu_type_class; ?><?= $menu_columns_class; ?><?= $menu_page_curl==1 ? ' curl' : '' ?>">
<?php while (have_posts()) : the_post(); ?>
<article>
<a href="<?php the_permalink(); ?>">
<h2>
<?php the_title(); ?>
</h2>
<?php if ($post->post_excerpt!==''): ?>
<p>
<?php the_excerpt(); ?>
</p>
<?php endif; ?>
<?php if(has_post_thumbnail()):?>
<?php the_post_thumbnail($menu_thumb_type, array('alt' => ''.get_the_title().'', 'title' => '' )); ?>
<?php else: ?>
<img src="/assets/images/fallback.gif" alt="<?php the_title(); ?>" width="<?= $menu_fallback_width; ?>" height="<?= $menu_fallback_height; ?>" />
<?php endif; ?>
</a>
</article>
<?php endwhile;?>
<?php if($menu_more_text && $menu_more_id): ?>
<p class="more">
<a href="<?= get_page_link($menu_more_id); ?>">
<?= $menu_more_text; ?>
</a>
</p>
<?php endif; ?>
</section>
<?php endif; ?>
<?php wp_reset_query();?>
<?= $the_content[1]; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment