質問

本当にあなたの助けが必要です。

私のsingle.phpでは、同じカテゴリで次の投稿を取得する必要がありました

(私はすでに持っています:

$ in_same_cat = true;

$ explued_categories = '';

$前= false;

$ next_post = get_adjacent_post($ in_same_cat、$ explued_categories、$ fortion);)

今、私は必要です 次に また、反対方向に投稿します 前の前 役職

ありがとう

役に立ちましたか?

解決 3

驚くべきことに、私は自分で答えを見つけました...

次の投稿/前の投稿に使用したのと同じ機能を使用しています

(get_adjacent_post())が、すでにパラメーターとして見つけた次の/前の投稿を送信する

$in_same_cat = true;

$excluded_categories = '';

$previous = true;

$previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);

$previous_previous_post = 
get_adjacent_post($in_same_cat,$excluded_categories,$previous,$previous_post);

$previous = false;

$next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);

$next_next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous,$next_post); 

しかし...まだ終了していません。このコードをWP-Includes/link-template.phpの関数宣言に追加する必要があります

function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true,$mypost = null) {
    global  $wpdb;

//if specific post wasnt sent to function it takes the global one and checks if its empty before using it.

    if ( empty( $mypost ) )
    {
        global $post;
        if(empty( $post ))
            return null;
        $mypost=$post;
    }
//...

他のヒント

いくつかの隣接する投稿を取得するコードについては、こちらの回答を参照してください。

サイドバーで次の投稿タイトルを取得しますか?

やあ
このリンクに従ってget_adjacent_post関数を使用してみてください
http://wordpress.org/support/topic/how-to-get-next-post-id
次の投稿のIDを取得する小さなループを作成し、次のIDを取得するために受け取ったIDの関数を再度使用できます。

$prevPost = get_previous_post();
$i = 0;  
$num_prev_posts = 4;  
while ($i < $num_prev_posts) //needs to check if $prevPost exists. while ($i < $num_prev_posts && !empty($prevPost)) doesn't work. 
{  
    get_permalink($post->ID); //and other such functions that work on the global $post should now work.  
    $i++;  
    $prevPost = get_previous_post(); // and then there should be a check if $prevPost is empty or not  
    print_r($prevPost);  
}

これにより、以前の4つの投稿がもたらされます。http://wordpress.org/support/topic/get-next-5-posts-from-the-urrent-post

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top