/**
 * wp_series_nav() - assembles the links for the next or previous post links.
 * YOU can call this if you simply want to output either the next post in a series or the previous post in a series but it will not return both.
 *
 * @package Organize Series WordPress Plugin
 * @since 2.0
 *
 * @uses get_post_meta() - will get the current series part for the displayed post.
 * @uses get_option() - will get the template for series nav.
 * @uses get_objects_in_term() - will get all the posts that belongs to the series the current post belongs to.
 * @uses get_series_order() - will take the list of posts and sort them by their order in the series.
 * @uses get_the_title() - post title.
 * @uses get_permalink() - permalink of a post
 *
 * @param int $series_ID REQUIRED
 * @param bool $next  if TRUE will output the next post in the series.  if FALSE will output the previous post in the series.
 * @param bool $customtext (THIS paramater is deprecated as of Organize Series 2.3.6)
 * @param bool $display if TRUE will echo the linked post.  if FALSE will return the linked post.
 * @param bool $calc = indicates whether the function should try to figure out the $series_id for the user.
 *
 * @return string $result contains the linked post (next OR previous post depending on  $next param)
*/
function wp_series_nav($series_ID, $next = TRUE, $customtext = 'deprecated', $display = FALSE, $calc = false)
{
    global $post, $orgseries;
    if (empty($series_ID) && $calc) {
        $series = get_the_series();
        if (!empty($series)) {
            $series_ID = $series[0]->term_id;
        }
    }
    if (empty($series_ID)) {
        return false;
    }
    //we can't do anything without the series_ID;
    $cur_id = $post->ID;
    $settings = $orgseries->settings;
    $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_ID);
    $cur_part = get_post_meta($cur_id, $series_part_key, true);
    $series_posts = get_objects_in_term($series_ID, 'series');
    $posts_in_series = array();
    $posts_in_series = get_series_order($series_posts, $cur_id, $series_ID);
    $result = '';
    foreach ($posts_in_series as $seriespost) {
        $custom_next = esc_html(token_replace($settings['series_nextpost_nav_custom_text'], 'other', $seriespost['id'], $series_ID));
        $custom_prev = esc_html(token_replace($settings['series_prevpost_nav_custom_text'], 'other', $seriespost['id'], $series_ID));
        if ($next) {
            if ($seriespost['part'] - $cur_part == 1) {
                if (!empty($custom_next)) {
                    $title = $custom_next;
                } else {
                    $title = get_the_title($seriespost['id']);
                }
                $link = get_permalink($seriespost['id']);
                $result .= '<a href="' . $link . '" title="' . $title . '">' . $title . '</a>';
            }
        }
        if (!$next) {
            if ($cur_part - $seriespost['part'] == 1) {
                if (!empty($custom_prev)) {
                    $title = $custom_prev;
                } else {
                    $title = get_the_title($seriespost['id']);
                }
                $link = get_permalink($seriespost['id']);
                $result .= '<a href="' . $link . '" title="' . $title . '">' . $title . '</a>';
            }
        }
    }
    if ($display) {
        echo $result;
    } else {
        return $result;
    }
}
Exemplo n.º 2
0
function wp_reset_series_order_meta_cache($post_id = 0, $series_id = 0, $reset = FALSE)
{
    if (0 == $series_id) {
        return false;
    }
    //post is not a part of a series so no need to waste cycles.
    $post_ids_in_series = get_objects_in_term($series_id, 'series');
    $addvalue = 1;
    $series_posts = get_series_order($post_ids_in_series, $post_id, $series_id, true, false);
    $series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $series_id);
    if ($reset) {
        foreach ($post_ids_in_series as $spost) {
            if (array_key_exists('object_id', $post_ids_in_series)) {
                $spost_id = $spost['object_id'];
            } else {
                $spost_id = $spost;
            }
            delete_post_meta($spost_id, $series_part_key);
        }
        return true;
    }
    foreach ($series_posts as $spost) {
        $spost_status = get_post($spost['id'])->post_status;
        $newpart = $addvalue;
        delete_post_meta($spost['id'], $series_part_key);
        add_post_meta($spost['id'], $series_part_key, $newpart);
        $addvalue++;
    }
    return true;
}