Created
April 30, 2015 11:13
-
-
Save dendeffe/6b9f59012ef9f93b0022 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* EXAMPLE CUSTOM LOOP (WPQUERY) WITH PAGINATION | |
function video_testimonial_loop() { | |
$per_page = 8; | |
$paged = get_query_var( 'page' ); | |
$args = array ( | |
'post_type' => 'defunktnutestimon', | |
'posts_per_page' => $per_page, | |
'paged' => $paged, | |
'meta_query' => array( | |
array ( | |
'key' => 'youtube_link', | |
'compare' => 'EXISTS' | |
) | |
) | |
); | |
$posts = new WP_Query($args); | |
$loop = "<ul id=\"testimon_list\" class=\"video\">\n"; | |
while($posts->have_posts()) { | |
$posts->the_post(); | |
$image_url= get_field('afbeelding_overzicht'); | |
$image= wp_get_attachment_image_src( $image_url , 'width=100&height=100&crop=1crop_from_position=center,left' ); | |
$loop .= "<li>\n"; | |
$loop .= "<a href=\"" . get_field('youtube_link') ."\">\n"; | |
$loop .= "\t<img class=\"video_img\" src=\"" . $image[0] ."\" />\n"; | |
$loop .= "\t<h3 class=\"video_title\">" . get_the_title() . "</h3>\n"; | |
$loop .= "\t<span class=\"video_click\">" . __("Klik", "van_kelst") . " >></span>\n"; | |
$loop .= "</a>\n"; | |
$loop .= "</li>\n"; | |
} | |
$loop .= "</ul>"; | |
wp_reset_postdata(); | |
// Pagination | |
$how_many_pages = ceil($posts->found_posts/$per_page); | |
$current_page = 1; | |
if(isset($paged)) { | |
if($paged !== 0 && $paged != "") { | |
$current_page = $paged; | |
} | |
} | |
global $wp; | |
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); | |
$current_url = explode("?", $current_url); | |
$current_url = $current_url[0]; | |
$prev_page = ""; | |
$next_page = ""; | |
if($current_page > 1) { | |
$prev_page_number = $paged - 1; | |
if($prev_page_number < 0) { | |
$prev_page_number = 0; | |
} | |
$prev_page = "<a class=\"prev_page\" href=\"" . $current_url . "/?page=" . $prev_page_number . "\"> << </a> "; | |
} | |
if($current_page < $how_many_pages) { | |
if($current_page === 0) { | |
$next_page_number = $current_page + 1; | |
} | |
$next_page_number = $current_page + 1; | |
$next_page = " <a class=\"next_page\" href=\"" . $current_url . "/?page=" . $next_page_number . "\"> >> </a>"; | |
} | |
$loop .= "<div class=\"pagination\">" . $prev_page . "<span class=\"counter\">" . $current_page . "/" . $how_many_pages . "</span>" . $next_page . "</div>"; | |
return $loop; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment