在functions.php中,這樣的事情...
function shortcodeFunction($atts) {
extract(shortcode_atts(array(
'cat' => '' //the attr in the shortcode
), $atts));
if($cat){ //$cat is extracted from $atts
$args = array(
'category' => $cat,
'orderby' => 'post_date',
'order' => 'DESC', // Show only latest, rejig as needed
'posts_per_page' => 1 // Only show 1
)
$allPosts = get_posts($args);
$return = '';
foreach($allPosts as $p){ // Bog standard get post foreach
$thePost = get_post($p);
$date = $thePost->post_date;
$date = strtotime($date);
$date = gmdate('jS F Y',$date);
$link = get_permalink($thePost->ID);
$return .= '<div class="three_fourth "><h2>'.$thePost->post_title.' - '.$date.'</h2></div><div class="one_fourth last"><a class="button" href="'.$link.'" style="background-color: #c62b02"></div>';
}
} return $return;
} else {
return false;
}
add_shortcode('top_post', 'shortcodeFunction');
我不得不做出一些調整,因爲它不會加載按原樣,但這工作。謝謝!! –
太棒了!聽到那個消息很開心! – ggdx