Created
April 2, 2012 07:27
-
-
Save anonymous/2281398 to your computer and use it in GitHub Desktop.
Start with Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CPT | |
function create_destinations() { | |
$labels = array( | |
'name' => _x('Destinations', 'post type general name'), | |
'singular_name' => _x('Destination', 'post type singular name'), | |
'add_new' => _x('Add New', 'Destination'), | |
'add_new_item' => __('Add New Destination'), | |
'edit_item' => __('Edit Destination'), | |
'new_item' => __('New Destination'), | |
'view_item' => __('View Destination'), | |
'search_items' => __('Search Destinations'), | |
'not_found' => __('No Destinations found'), | |
'not_found_in_trash' => __('No Destinations found in Trash'), | |
'parent_item_colon' => '' | |
); | |
$supports = array('title', 'editor', 'author', 'custom-fields', 'revisions', 'excerpt','thumbnail','comments'); | |
register_post_type( 'destination', | |
array( | |
'labels' => $labels, | |
'public' => true, | |
'show_ui' => true, | |
'rewrite' => array('slug' => 'destination','with_front' => FALSE), | |
'hierarchical' => true, | |
'capability_type' => 'page', | |
'menu_position' => 5, | |
'supports' => $supports, | |
'taxonomies' => array('category', 'post_tag') | |
) | |
); | |
} | |
//Display destination and related icon | |
<div id="alphabet"> | |
Show: | |
<a href="/guides?orderby=">ALL</a> | | |
<a href="/guides?orderby=A">A</a> | | |
<a href="/guides?orderby=B">B</a> | | |
etc.. | |
</div> | |
<?php | |
$listitems = get_option('tp_listitems'); | |
$theletter = $_GET['orderby']; | |
$paged = get_query_var('paged') ? get_query_var('paged') : 1; | |
if( !empty($theletter) ) { | |
$args = array( 'post_type' => 'destination','paged' => $paged, 'posts_per_page' => $listitems ,'order' => 'ASC', 'orderby' => 'title', 'query' => $wp_query,'startswith'=>$theletter) ; | |
}else{ | |
$args = array( 'post_type' => 'destination','paged' => $paged,'posts_per_page' => $listitems ,'order' => 'ASC', 'orderby' => 'title', 'query' => $wp_query) ; | |
} | |
$temp = $wp_query; // assign original query to temp variable for later use | |
$wp_query = null; | |
$wp_query = new WP_Query(); | |
$wp_query->query($args); | |
$post_count = $wp_query->post_count; // should be the result count for the current page | |
$loop_count = 0; | |
//Find connected Articles | |
p2p_type('posts_to_destinations' )->each_connected( $wp_query, array(), 'articles' ); | |
if($wp_query->have_posts()) :$curr_letter = '';while($wp_query->have_posts()) : $wp_query->the_post(); | |
$loopid = $post->ID; | |
$loop_count++; | |
$this_letter = strtoupper(substr($post->post_title,0,1)); | |
if ($this_letter != $curr_letter) { | |
$curr_letter = $this_letter; | |
} | |
?> | |
<div id="itemlisting"> | |
<?if(has_post_thumbnail()){?> | |
<div id="itempic"><a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div> | |
<?}?> | |
<div id="itemheader"> | |
<div id="ititle"><h4><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h4></div> | |
<div id="ioptions"> | |
<?php | |
//Only display icon if connected articles exist | |
if($post->articles){ | |
echo display_article_icon($post->ID); | |
} | |
?> | |
</div> | |
</div> | |
<div id="itemcontent"> | |
<?php | |
$intro = excerpt('36'); | |
$introstripped = str_replace("Overview",'',$intro); | |
echo $introstripped; | |
//echo excerpt('36'); | |
?> | |
</div> | |
</div> | |
<?php endwhile; else : ?> | |
Sorry, no destination to display. | |
<?php endif; ?> | |
<div id="navlist"> | |
<?php | |
if(function_exists('wp_pagenavi')) { wp_pagenavi(); } | |
?> | |
</div> | |
<?php | |
$wp_query = null; | |
$wp_query = $temp; | |
wp_reset_postdata(); | |
wp_reset_query(); | |
//echo $loopid; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment