get_adjacent_post [ WordPress Function ]
get_adjacent_post ( $in_same_cat = false, $excluded_categories = '', $previous = true )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: get_adjacent_post_rel_link, adjacent_post_link, get_next_post, wp_get_recent_posts, get_current_site
Retrieve adjacent post.
Can either be next or previous post.
Source
<?php
function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {
global $post, $wpdb;
if ( empty( $post ) )
return null;
$current_post_date = $post->post_date;
$join = '';
$posts_in_ex_cats_sql = '';
if ( $in_same_cat || ! empty( $excluded_categories ) ) {
$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
if ( $in_same_cat ) {
$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
}
$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
if ( ! empty( $excluded_categories ) ) {
if ( ! is_array( $excluded_categories ) ) {
// back-compat, $excluded_categories used to be IDs separated by " and "
if ( strpos( $excluded_categories, ' and ' ) !== false ) {
_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded categories.' ), "'and'" ) );
$excluded_categories = explode( ' and ', $excluded_categories );
} else {
$excluded_categories = explode( ',', $excluded_categories );
}
}
$excluded_categories = array_map( 'intval', $excluded_categories );
if ( ! empty( $cat_array ) ) {
$excluded_categories = array_diff($excluded_categories, $cat_array);
$posts_in_ex_cats_sql = '';
}
if ( !empty($excluded_categories) ) {
$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
}
}
}
$adjacent = $previous ? 'previous' : 'next';
$op = $previous ? '<' : '>';
$order = $previous ? 'DESC' : 'ASC';
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
$query_key = 'adjacent_post_' . md5($query);
$result = wp_cache_get($query_key, 'counts');
if ( false !== $result )
return $result;
$result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
if ( null === $result )
$result = '';
wp_cache_set($query_key, $result, 'counts');
return $result;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/get adjacent post « WordPress Codex
Description. Retrieve adjacent post. Can either be next or previous post. Usage. <?php get_adjacent_post( $in_same_cat, $excluded_categories, $previous ) ?> ...
codex.wordpress.org - get_adjacent_post doesn't work due to timestamps - WordPress
Hey there! I have several thousands of posts, that I import using the CSV Importer . During my imports I've subsequently been setting the timestamp on some of ...
wordpress.org - Is it possible to filter get_adjacent_post() with tags? - WordPress
Dec 2, 2010 ... I've been using get_adjacent_post() to determine the previous and next posts. How would I go about determining the next and previous links to ...
wordpress.stackexchange.com - Optimizing WordPress Post Navigation | Digging into WordPress
Dec 13, 2009 ... Here we are using the get_adjacent_post function to determine whether or not ... The get_adjacent_post tag accepts the following parameters: ...
digwp.com
Kullanýcý Tartýþmalarý [ wordpress.org ]
- Chouby on "[Plugin: Polylang] (fix for) adjacent post function not working with v.0.6"
- serban on "[Plugin: Polylang] (fix for) adjacent post function not working with v.0.6"
- lookslikepat on "get_adjacent_post doesn't work due to timestamps"
- lalindsey on "Changing next and previous post links"
- lalindsey on "Changing next and previous post links"
- spamherefool on "get_adjacent_post help!"
- Daniel Flodin on "Check category ID/name of next/previous posts in a loop…?"
- alchymyth on "Check category ID/name of next/previous posts in a loop…?"
- Peter vanDoorn on "Check category ID/name of next/previous posts in a loop…?"
- Daniel Flodin on "Check category ID/name of next/previous posts in a loop…?"