2016-11-25 48 views
0

在Wordpress的主頁上,我使用多個不同頁面的摘錄。問題在於它每次都返回相同的摘錄鏈接。似乎每次都使用頁面上的最後一個鏈接(3)。每次通過使用多個摘錄返回相同的鏈接

的代碼(當然我換了ID每次;-)數量:

<?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

沒關係,我找到了解決辦法:忘記使用.get_permalink()中的$ post_id ...編輯上述函數中的代碼

相關問題