这只是将jquery ui选项卡标记转换为适当的wordpress函数的问题。文本是\\u title()或\\u摘录()。图像是\\u post\\u缩略图等。将其放在模板中希望滑块显示的位置:
// Get any existing copy of our transient data
if ( false === ( $featured_query_results = get_transient( \'featured_query_results\' ) ) ) {
// It wasn\'t there, so regenerate the data and save the transient
$args = array( \'numberposts\' => 5, \'cat\' => 11 );
$featured_query_results = get_posts( $args );
set_transient( \'featured_query_results\', $featured_query_results );
}
global $post;
$tmp_post = $post;
//if there are posts returned then we\'ll loop through them
if($featured_query_results): ?>
<div id="featured">
<?php
$i=1;
$ul = \'<ul class="ui-tabs-nav">\';
$divs = \'\';
foreach( $featured_query_results as $post ) : setup_postdata($post);
//create the li nav element
$ul .= \'<li><a href="#fragment-\'.$i.\'">\'.get_the_post_thumbnail(get_the_ID(),"thumbnail").\'<span>\'.get_the_title().\'</span></a></li>\';
//create the div tab
$divs .= \'<div id="fragment-\'.$i.\'">\';
$divs .= get_the_post_thumbnail(get_the_ID(),"large");
$divs .= \'<div class="info" >\';
$divs .= \'<h2><a href="\'.get_permalink().\'" >\'.get_the_title().\'</a></h2>\';
$divs .= \'<p>\'.get_the_excerpt().\'<a href="\'.get_permalink().\'" >read more</a></p>\';
$divs .= \'</div>\';
$divs .= \'</div>\';
$i++;
endforeach;
//close out the unordered list
$ul .= \'</ul><!--.ui-tabs-nav-->\';
//echo out the results
echo $ul;
echo $divs;
?>
</div><!--#featured-->
<?php else: ?>
No matching posts found.
<?php endif; ?>
<?php $post = $tmp_post;
这就是你的功能。php
// Create a simple function to delete our transient when posts are saved/created
function delete_featured_query_transient() {
delete_transient( \'featured_query_results\' );
}
add_action( \'save_post\', \'delete_featured_query_transient\' );
请注意,我正在使用
$args = array( \'numberposts\' => 5, \'cat\' => 11 );
作为我的查询的参数。你会想用你自己的。您可能想注释掉
set_transient( \'featured_query_results\', $featured_query_results );
行当您进行设置时,b/c它将在瞬态中存储查询结果,这样就不必反复进行相同的查询。当你写一篇新文章(我说的放在functions.php中的函数)时,transient会被删除,所以它总是最新的。通过将save\\u post挂钩中的delete函数更改为始终运行的函数(如init),可以始终删除瞬态。