1
我需要自定義默認設計的相關文章從噴墨包在wordpress到我的自定義設計我無法找到錯誤,在我的代碼錯了。我在functions.php文件中寫了一個鉤子。自定義噴氣包相關文章到我自己的設計在wordpress
這是我的functions.php鉤
function jetpackme_custom_related() {
$posts = '<div class="single-article-popularGi">';
$posts .= '<h1>related</h1><div class="row">';
if (class_exists('Jetpack_RelatedPosts') && method_exists('Jetpack_RelatedPosts', 'init_raw')) {
$related = Jetpack_RelatedPosts::init_raw()
->get_for_post_id(
get_the_ID(),
array('size' => 2)
);
if ($related) {
foreach ($related as $result) {
// Get the related post IDs
$title = get_the_title($result[ 'id' ]);
$link = get_permalink($result[ 'id' ]);
$image = featuredOrFirstImage($result[ 'id' ], 'blog-post-image');
$category_name = get_the_category($result[ 'id' ]);
$posts .= '<div class="col-sm-3 col-3"><span class="thumbnail-image"><a href="'.$link.'">'.$image.'</a></span></div>';
$posts .= '<div class="post-details col-sm-3 col-3 align-self-center"><div class="entry-cat post-category">'.$category_name.'</div>';
$posts .= '<div class="mostPopularTitle"><h2 class="entry-title"><a class="post-title" href="%s" rel="bookmark">'.$title.'</a></h2>';
$posts .= '<div class="readArticle"><a class="readMorePost" href="'.$link.'">MORE GI></a>';
}
}
}
$posts .= '</div>';
$posts .= '</div>';
// Return a list of post titles separated by commas
if($related){
return $posts;
}else{
return false;
}
}
add_action('admin_init', 'jetpackme_custom_related');
我曾經在single.php中稱它是這樣
<?php echo $related = jetpackme_custom_related();?>
但沒有什麼顯示和獲得錯誤,不顯示一些時間沒有。任何人都可以請讓我解決出來..