Skip to content

Instantly share code, notes, and snippets.

@keithdevon
Created July 25, 2012 10:33
Show Gist options
  • Save keithdevon/3175471 to your computer and use it in GitHub Desktop.
Save keithdevon/3175471 to your computer and use it in GitHub Desktop.
The member archive show more
<?php
/* Archive listings */
global $slt_post_type_object, $slt_banner_id;
// Order resource by title ???? not working
if ( is_post_type_archive( 'knowledge' ) )
query_posts( 'post_type=member&orderby=post_title' );
// knowledge filter?
$slt_theme = null;
if ( isset( $_GET['locality_knowledge'] ) )
$slt_theme = get_term( $_GET['locality_knowledge'], 'knowledge' );
get_header();
?>
<div id="crumbs">
<a id="parent-crumb" href="<?php echo bloginfo('url'); ?>/members/">Our Members</a>
</div>
<div id="content">
<h1>Our members</h1>
<?php
if ( have_posts() ) {
$post = $posts[0]; // Hack. Set $post so that the_date() works.
// Output posts
echo '<ol class="posts">';
global $wp_query;
$query =& $wp_query;
echo '<p>$query->found_posts = '.$query->found_posts.'</p>';
echo '<p>$query->query_vars["posts_per_page"] = '.$query->query_vars["posts_per_page"].'</p>';
echo '<p>$query->max_num_pages = '.$query->max_num_pages.'</p>';
while ( have_posts() ) {
the_post();
get_template_part( 'members-in-loop' );
}
// More?
slt_more_posts_link(
'/our-members/', //$base_url
'member', //$post_type
__( "Older posts", SLT_THEME_SHORTNAME ), //$older_label
__( "Newer posts", SLT_THEME_SHORTNAME ), //$newer_label
'', //$taxonomy
'', //$term_id
50, //$posts_per_page
'' //$show_more_label
);
echo '</ol>';
do_action('wp_ajax_nopriv_slt_get_more_posts');
} else {
printf( __( 'Sorry, there are currently no %s posts under this theme.', SLT_THEME_SHORTNAME ), $slt_post_type_object->labels->singular_name );
}
?>
</div><!-- /#content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
// Output the link to pull in more posts
// Designed for jQuery to attach AJAX too, with basic fallback functionality
// Currently only works with one list of posts per page
if ( ! function_exists( 'slt_more_posts_link' ) ) {
function slt_more_posts_link( $base_url = '/', $post_type = 'post', $older_label = null, $newer_label = null, $taxonomy = '', $term_id = 0, $posts_per_page = null, $show_more_label = null, $custom_vars = array(), &$query = null, $exclude = array() ) {
if ( ! $query ) {
global $wp_query;
$query =& $wp_query;
}
if ( $older_label == null )
$older_label = __( "Older posts", 'slt-custom' );
if ( $newer_label == null )
$newer_label = __( "Newer posts", 'slt-custom' );
if ( $show_more_label == null )
$show_more_label = __( "Show more posts", 'slt-custom' );
if ( $posts_per_page == null )
$posts_per_page = get_option( 'posts_per_page' );
$page = $query->query_vars["paged"];
if ( ! $page )
$page = 1;
$qs = $_SERVER["QUERY_STRING"] ? "?" . $_SERVER["QUERY_STRING"] : "";
// Only necessary if there's more posts than posts per page
if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
if ( $page < $query->max_num_pages )
echo '<li id="older-posts" class="more-posts"><a href="' . esc_attr( $base_url . 'page/' . ( $page + 1 ) . '/' . $qs ) . '">' . wp_kses( $older_label, array() ) . '</a></li>';
if ( $page > 1 )
echo '<li id="newer-posts" class="more-posts"><a href="' . esc_attr( $base_url . 'page/' . ( $page - 1 ) . '/' . $qs ) . '">' . wp_kses( $newer_label, array() ) . '</a></li>';
?>
<script type="text/javascript">/* <![CDATA[ */
jQuery( 'li#older-posts a' ).text( '<?php echo wp_kses( $show_more_label, array() ); ?>' );
// Set vars for AJAX
var slt_ajax_more_data = {
'post_type': '<?php echo $post_type; ?>',
'taxonomy': '<?php echo $taxonomy; ?>',
'term_id': '<?php echo $term_id; ?>',
'found_posts': '<?php echo $query->found_posts; ?>',
'posts_per_page': '<?php echo $posts_per_page; ?>',
'post__not_in': '<?php echo implode( ",", $exclude ); ?>',
'is_vars': {
<?php
// Pass through conditional variables from query
$is_vars = array( 'archive', 'date', 'year', 'month', 'day', 'time', 'author', 'category', 'tag', 'tax', 'search', 'home', 'posts_page', 'post_type_archive' );
$array_query = (array) $query;
foreach ( $is_vars as $is_var ) {
echo "'$is_var': " . ( $array_query['is_' . $is_var] ? 'true' : 'false' );
if ( $is_var != $is_vars[ count( $is_vars ) -1 ] )
echo ',';
}
?>
}<?php
if ( ! empty( $custom_vars) ) {
echo ",\n";
echo "'custom_vars': {\n";
foreach ( $custom_vars as $custom_var_key => $custom_var_value )
echo "'" . esc_js( $custom_var_key ) . "': '" . esc_js( $custom_var_value ) . "',\n";
echo "}";
}
?>
};
/* ]]> */</script>
<?php
}
}
}
// AJAX wrapper to get more posts
if ( ! function_exists( 'slt_get_more_posts_ajax' ) ) {
add_action( 'wp_ajax_nopriv_slt_get_more_posts', 'slt_get_more_posts_ajax' );
function slt_get_more_posts_ajax() {
// Initialize
ob_end_clean();
global $slt_loop;
$args = array(
'post_type' => $_REQUEST['post_type'],
'posts_per_page' => $_REQUEST['posts_per_page'],
'offset' => $_REQUEST['offset'],
'post__not_in' => explode( ',', $_REQUEST['post__not_in'] ),
'post_status' => 'publish'
);
if ( $_REQUEST['taxonomy'] && $_REQUEST['term_id'] ) {
$args['tax_query'] = array( array(
'taxonomy' => $_POST['taxonomy'],
'field' => 'id',
'terms' => $_POST['term_id']
));
}
// Get posts
$slt_loop = new WP_Query( $args );
//mail( "gyruscope@gmail.com", "more posts query", print_r( slt_debug_query($slt_loop,false), true ) );
//mail( "gyruscope@gmail.com", "more posts query", print_r( $slt_loop, true ) );
// Force any conditional query variables
global $wp_query;
foreach ( $_REQUEST as $key => $value ) {
if ( strlen( $key ) > 3 && substr( $key, 0, 3 ) == 'is_' )
$wp_query->$key = $value;
}
// Build output
while ( $slt_loop->have_posts() ) {
$slt_loop->the_post();
get_template_part( 'post-in-loop' );
}
wp_reset_query();
exit( 0 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment