2016-11-25 8 views
0

Wordpressのメインページでは、複数の異なるページの抜粋を使用しています。問題は、それが毎回同じ抜粋リンクを返すということです。ページの最後のリンク(3の)が毎回使用されているようです。複数の抜粋を使用して毎回同じリンクが返されます

<?php 
$post_id = 35; // post id 
$queried_post = get_post($post_id); 
$my_excerpt = get_excerpt_by_id_long($queried_post); //$post_id is the post id of the desired post 

echo '<a href="' . get_permalink($queried_post) . '" title="' . $queried_post->post_title . '">'; 
echo '<h3><strong>'; 
echo $queried_post->post_title; 
echo '</strong></h3>'; 
echo '</a>'; 

echo $my_excerpt; 
?> 

これはのfunctions.phpである

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 . '<a class="leesmeer" href="'.get_permalink($post_id).'">lees verder...</a></p>'; 

return $the_excerpt; 
} 
+0

解決策を見つけました:下記の回答を参照してください –

答えて

0

私は解決策を見つけ、気にしない:

コードは(もちろん私は、ID毎回;-)の数を変更し忘れてしまいました.get_permalink()で$ post_idを使用するには...上記のfunctions.phpのコードを編集しました

関連する問題