Neurotic Forums » Neurotic Plugins » Organize Series WordPress Plugin » Usage Help

Link to first post in a series?

(4 posts)
  • Started 7 months ago by vigevenoj
  • Latest reply from vigevenoj
  1. vigevenoj
    Member

    Is there already a token or internal function to link to the first post in a series? I didn't see one in series-template-tags.php, but I saw things that could be tweaked into doing what I want. I figured I would check here, and if you think it's something useful for others, I'd be willing to implement it like the other tokens were implemented and contribute that back.

    Posted 7 months ago #
  2. Sorry for the delay in posting a reply - been busy.
    Nope, there isn't a token for what you suggested. As for working something in yourself go for it :)!

    Posted 7 months ago #
  3. vigevenoj I would personally love to see the ability to link to just the first post of a series. Definitely keep us posted on your progress.

    Posted 7 months ago #
  4. vigevenoj
    Member

    Apologies for not coming back earlier. I didn't end up getting this into a token, but I was able to get something that works for me. I added these two functions to series-template-tags.php. Pretty sure this can be improved, but like I said, it works for my use so far.

    function wp_series_nav_href($series_ID, $next = FALSE, $first = FALSE, $customtext = FALSE) {
            global $post;
            $cur_id = $post->ID;
            $cur_part = get_post_meta($cur_id, SERIES_PART_KEY, true);
            $settings = get_option('org_series_options');
            $custom_next = $settings['series_nextpost_nav_custom_text'];
            $custom_prev = $settings['series_prevpost_nav_custom_text'];
    
            if (!isset($series_ID)) {
                    $series = get_the_series();
                    if (!empty($series) ) {
                            foreach ($series as $ser) {
                                    $series_ID = $series->term_ID;
                            }
                    }
            }
    
            $series_posts = get_objects_in_term($series_ID, 'series');
            $posts_in_series = array();
            $posts_in_series = get_series_order($series_posts, $cur_id);
            $link = '';
    
            foreach ($posts_in_series as $seriespost) {
                    if ($next && !$first) {
                            if ( ($seriespost['part'] - $cur_part) == 1) {
                                    $link = get_permalink($seriespost['id']);
                            }
                    }
                    if (!$next && !$first) {
                            if ( ($cur_part - $seriespost['part']) == 1) {
                                    $link = get_permalink($seriespost['id']);
                            }
                    }
                    if (!$next && $first) {
                            if ($cur_part != 1 && $seriespost['part'] == 1) {
                                    $link = get_permalink($seriespost['id']);
                            }
                    }
            }
            return $link;
    }
    
    function custom_series_nav() {
            global $post;
            $series_part = get_post_meta($post->ID, "series_part",true);
            $series = get_the_series(false);
            $series_id = $series[0]->term_id;
            $postid = $post->ID;
            $links = '';
    
            if ($series) {
                    if ($series_part != 1) {
                            $links .= '<a href="' . wp_series_nav_href($series_id, FALSE, TRUE, FALSE) . '">First</a> ';
    
                            $links .= '<a href="' . wp_series_nav_href($series_id, FALSE, FALSE, FALSE) . '">Previous</a> ';
                    }
                    $next_link = wp_series_nav_href($series_id, TRUE, FALSE, FALSE);
                    if ($next_link != '') {
                            $links .= '<a href="' . $next_link . '">Next</a>';
                    }
                    return $links;
            }
    }

    [edit: I missed the "put code between backticks" the first time around]

    Posted 4 months ago #

RSS feed for this topic

Reply

You must log in to post.