• I need someone to write a script/hack for me, please.

    If I’ve got a post within 2 categories, I need to be able to tell next_post_link() tag from which category to pick.

    I’ve been looking through the template-funcions-links.php, but I really wouldn’t know what to do.

    ExcludedCategories parameter doesn’t help, please don’t suggest it.

    I got it conceptualized. It should be like this:

    function next_post_by_cat($cat_id = ”) {

    > get.category($cat).posts
    > get.current.post.date
    > select.next.post.by.date

    output

    }

    Easy, ain’t it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter barmin

    (@barmin)

    Asking for assistance. I did the following hack:

    Added the parameter “$for_category” to previous_post_link template tag, and to the casting of get_previous_post:

    (don’t know how to use markup to highlight)

    function previous_post_link($format=’« %link’, $link=’%title’, $in_same_cat = false, $excluded_categories = ”, $for_category) {

    if ( is_attachment() )
    $post = & get_post($GLOBALS[‘post’]->post_parent);
    else
    $post = get_previous_post($in_same_cat, $excluded_categories, $for_category);

    if ( !$post )
    return;

    $title = apply_filters(‘the_title’, $post->post_title, $post);
    $string = ‘ID).'”>’;
    $link = str_replace(‘%title’, $title, $link);
    $link = $pre . $string . $link . ‘
    ‘;

    $format = str_replace(‘%link’, $link, $format);

    echo $format;
    }

    Then, added the same parameter to get_previous_post function, but defaulting it to what comes by default for $cat_array, within the if ($in_name_cat): ‘get_the_category($post->ID)’.

    Then, replaced this original string with the parameter, so that the 5th value entered when casting prev_post_link, becomes the $cat_array:

    function get_previous_post($in_same_cat = false, $excluded_categories = ”, $for_category = ‘get_the_category($post->ID)’) {
    global $post, $wpdb;

    if( !is_single() || is_attachment() )
    return null;

    $current_post_date = $post->post_date;

    $join = ”;
    if ( $in_same_cat ) {
    $join = ” INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id “;
    $cat_array = $for_category;
    $join .= ‘ AND (category_id = ‘ . intval($cat_array[0]->cat_ID);
    for ( $i = 1; $i < (count($cat_array)); $i++ ) {
    $join .= ‘ OR category_id = ‘ . intval($cat_array[$i]->cat_ID);
    }
    $join .= ‘)’;
    }

    $sql_exclude_cats = ”;
    if (!empty($excluded_categories)) {
    ### ronr hack ###

    }
    return @$wpdb->get_row(“SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < ‘$current_post_date’ AND post_status = ‘publish’ $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT 1”);
    }

    When I run the site with this hack, the page turns white whenever I cast it. Any suggestions?

    Thread Starter barmin

    (@barmin)

    I’ve tried some variations of the above hack, but none worked out…

    Is someone out there who could help me with coding, please?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Selective next/prev_post_link – Coder highly needed!’ is closed to new replies.