0

wordpressの次の前の投稿でコンテンツを表示するにはどうすればよいですか。例えば。次の投稿にはタイトル付きのリンクがありますが、その投稿の内容 (100 ワード) を表示することはできますか?

       <div class="alignleftfp">
        <?php next_post_link('%link', '%title'); ?>
<?php get_next_post();?>
        </div>
        <div class="alignrightfp">
        <?php previous_post_link('%link', '%title'); ?>
<?php get_previous_post();?>
        </div>

何か反応があれば大歓迎です。. .

4

5 に答える 5

2

get_next_postget_previous_postが役に立ちます。

于 2013-07-18T09:05:52.190 に答える
1

The Loop 内にある場合は、要件に応じてthe_excerpt()またはを使用できます。get_the_excerpt()

The Loop の外にある場合は、次のような関数を使用して、投稿 ID で投稿の抜粋を取得できます。

function get_excerpt_by_id($post_id){
    $the_post = get_post($post_id); //Gets post ID
    $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
    $excerpt_length = 35; //Sets excerpt length by word count
    $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
    $words = explode(' ', $the_excerpt, $excerpt_length + 1);

    if(count($words) > $excerpt_length) :
        array_pop($words);
        array_push($words, '…');
        $the_excerpt = implode(' ', $words);
    endif;

    $the_excerpt = '<p>' . $the_excerpt . '</p>';

    return $the_excerpt;
}

お役に立てれば!

于 2013-07-18T09:06:37.200 に答える
0
function content($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}   
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $content;
}

投稿ページで、次のように単語制限を入力します--> echo content(100)。これがあなたを助けることを願っています。

于 2013-07-18T10:07:36.570 に答える
0

次の機能を使用できます

次の投稿へのリンク

<?php next_post_link('format', 'link', 'in_same_cat', 'excluded_categories'); ?>

以前の投稿のリンクについて

<?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = ''); ?> 
于 2013-07-18T12:29:43.577 に答える