如果有一个相当复杂的函数,我们将使用它来生成一个包含 3 个最新帖子的自定义循环。我只是想在最后一个名为“last”的 li 元素中添加一个类,但并没有真正把它记下来。我尝试了一堆 jquery 来 addClass 但没有运气。我敢肯定这只是我愚蠢。任何帮助将不胜感激。这是我的功能:
<?php function custom_readmore_after_excerpt($text) {
global $post;
//set default Read More
$link_text = '[continue]';
$custom_fields = get_post_custom() ;
$thesis_content_fields = unserialize( $custom_fields['_thesis_post_content'][0] );
if ( $thesis_content_fields['read_more'] )
$link_text = $thesis_content_fields['read_more'];
$link = '<span><a href="'. get_permalink($post->ID) . '" class="feed_read_more">' . $link_text . '</a></span>';
if (!empty($post->post_excerpt)) {
$text = $text . $link;
}
else {
$text = str_replace('[...]', $link, $text);
}
return $text;
}
add_filter('get_the_excerpt', 'custom_readmore_after_excerpt');
function excerpt_front($length) {
return 16;
}
add_filter('excerpt_length', 'excerpt_front');
$custom_loop = new WP_Query('showposts=3&orderby=date');
$output = "";
if ( $custom_loop->have_posts() ) :
/* open box wrapper */
$output .= "<ul class=\"feed_wrapper\">\n";
while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
/* load post data */
global $post;
/* prepare necessary variables */
$img = "";
$post_url = get_permalink($post->ID);
$post_title = get_the_title($post->ID);
$post_excerpt = get_the_excerpt($post->ID);
$a_title = esc_attr($post_title); /* - double Title on some post .. humm ?? - */
$thumbnail_data = get_post_meta($post->ID, '_thesis_post_thumbnail', true);
/* do only if thumbanil_data is not empty and is an array of values */
if(!empty($thumbnail_data) && is_array($thumbnail_data)) {
$thumbnail_url = (!empty($thumbnail_data['image']['url'])) ? $thumbnail_data['image']['url'] : "";
$img = "<img src=\"{$thumbnail_url}\" class=\"feed_thumbnail\" alt=\"{$a_title}\" />";
}
$a_before = "<a href=\"{$post_url}\">";
$a_after = "</a>";
/* start html constructor */
/* open post wrapper */
$output .= "<li>\n<div class=\"feed_container\">\n";
/* headline */
$output .= "<div class=\"feed_headline\">\n<h4 class=\"feed_title\">{$a_before}{$post_title}{$a_after}</h4>\n</div>\n";
/* thumbnail */
$output .= "<div class=\"feed_thumb\">\n{$a_before}{$img}{$a_after}\n</div>\n";
/* thumbnail */
$output .= "<div class=\"feed_excerpt\">\n{$post_excerpt}</div>\n";
/* close and clear post wrapper */
$output .= "<div class=\"clear\"></div>\n</div></li>\n";
endwhile;
/* close and clear box wrapper */
$output .= "<div class=\"cleared\"></div>\n</ul>\n";
endif;
wp_reset_query();
wp_reset_postdata();
/* display result */
echo $output;
?>