<div id="portfolio">
<ul id="portfolio-items" >
<?php $query = new WP_Query(); $count = 1;
//$catquery = new WP_Query( 'category_name=roomsandspecials&posts_per_page=10' );
$categories12 = get_terms('skill-type', $cat_args );
// These functions and add_filters could go in your functions.php file
function mam_posts_fields ($fields) {
global $mam_global_fields;
// Make sure there is a leading comma
if ($mam_global_fields) $fields .= (preg_match('/^(\s+)?,/',$mam_global_fields)) ? $mam_global_fields : ", $mam_global_fields";
return $fields;
}
function mam_posts_where ($where) {
global $mam_global_where;
if ($mam_global_where) $where .= " $mam_global_where";
return $where;
}
add_filter('posts_fields','mam_posts_fields');
add_filter('posts_where','mam_posts_where');
$mam_global_fields = ", $wpdb->term_relationships.term_taxonomy_id";
$mam_global_where = " AND post_date =
(SELECT MAX(p.post_date)
FROM $wpdb->posts p, $wpdb->term_relationships tr
WHERE p.ID = tr.object_id
AND tr.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id
AND p.post_type = 'portfolio'
AND p.post_status = 'publish'
AND p.post_date < NOW() ) ";
for ($i = 0; $i < count($categories12); $i++) {
query_posts( array(
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'skill-type',
'field' => 'id',
'terms' => $categories12[$i]->term_id
)
)
) );
//query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php get_the_image( array( 'size' => 'portfolio-thumb', 'width' => 220, 'height' => 140, 'link_to_post' => false ) ); ?>
<div class="meta">
<h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'wpzoom'), get_the_title()); ?>"> <?php the_title(); ?></a></h3>
<?php echo $categories12[$i]->name; ?>
</div>
</li>
<?php
//echo $categories12[$i]->term_id;
endwhile; endif; }
?>
</ul></div>
我正在使用上面的代码来显示类别中的最新帖子。当我不使用 add_filter('posts_fields','mam_posts_fields'); 时,使用此代码滑块在风险主题中不起作用 add_filter('posts_where','mam_posts_where'); 这显示了类别中的所有帖子。我想获得所有类别的最新帖子