我一直在关注使用quicksand.js做过滤器动画的投资组合许多教程。在函数中,我可以用slu create创建过滤器(类别)。经过无尽的阅读后,我无法弄清楚如何只显示某个过滤器的缩略图。WordPress的组合页面只显示某些过滤器的图片
我已经从我functions.php
包括投资组合的部分,我知道这是一个很大的代码,但是这是一个不得已而为之。我无法得到它的工作,所以我希望一些PHP/WordPress的大师可能会指出我错过的东西。
通过它阅读了,我也设法通过使用拉出刚刚发布的“特色”的特色照片:
<?php
$args = array(
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'filter',
'field' => 'slug',
'terms' => 'featured'
)
)
);
$query = new WP_Query($args);
?>
然而,这只是翻出图像和它的标题,没有格式化我需要HTML。但将此应用到我已经使用的地方,就是我完全失去了自己的地方。
在此先感谢。
我的index.php
h2>Featured Work</h2>
<ul id="image_gallery" class="group index_gallery filterable-grid">
<?php
// Query Out Database
$wpbp = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' =>'9'));
?>
<?php
$terms = get_terms("filter");
$count = count($terms);
if ($count > 0){
echo "<ul>";
foreach ($terms as $term) {
echo "<li>" . $term->name . "</li>";
}
echo "</ul>";
}
?>
<?php
// Begin The Loop
if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post();
?>
<?php
// Get The Taxonomy 'Filter' Categories
$terms = get_the_terms(get_the_ID(), 'filter');
?>
<?php
$large_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '');
$large_image = $large_image[0];
?>
<?php
//Apply a data-id for unique indentity,
//and loop through the taxonomy and assign the terms to the portfolio item to a data-type,
// which will be referenced when writing our Quicksand Script
?>
<li class="gallery_image" data-id="id-<?php echo $count; ?>" data-type="<?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->name)). ' '; } ?>">
<?php
// Check if wordpress supports featured images, and if so output the thumbnail
if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) :
?>
<?php // Output the featured image ?>
<a rel="prettyPhoto[gallery]" class="zoom" href="<?php echo $large_image ?>">
<img class="mag" src="<?php bloginfo('template_url'); ?>/imgs/mag.png"/><div class="thumb_bg"></div><?php the_post_thumbnail('portfolio'); ?>
</a>
<?php endif; ?>
<!--<?php // Output the title of each portfolio item ?>
<p><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></p>-->
</li>
<?php $count++; // Increase the count by 1 ?>
<?php endwhile; endif; // END the Wordpress Loop ?>
<?php wp_reset_query(); // Reset the Query Loop?>
</ul>
<div class="gallery_control">
<a href="<?php echo home_url(); ?>/portfolio/" class="gallery-btn artwork"><span class="icon-search"></span>View more</a>
</div>
<?php
$taxonomy = 'filter';
$terms = get_terms($taxonomy, '');
if ($terms) {
foreach($terms as $term) {
echo '<p>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $term->name) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
}
}
?>
投资组合的运作:
// function: post_type BEGIN
function post_type()
{
$labels = array(
'name' => __('Portfolio'),
'singular_name' => __('Portfolio'),
'rewrite' => array(
'slug' => __('portfolio')
),
'add_new' => _x('Add Item', 'portfolio'),
'edit_item' => __('Edit Portfolio Item'),
'new_item' => __('New Portfolio Item'),
'view_item' => __('View Portfolio'),
'search_items' => __('Search Portfolio'),
'not_found' => __('No Portfolio Items Found'),
'not_found_in_trash' => __('No Portfolio Items Found In Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array(
'title',
'editor',
'thumbnail'
)
);
register_post_type(__('portfolio'), $args);
} // function: post_type END
// function: portfolio_messages BEGIN
function portfolio_messages($messages)
{
$messages[__('portfolio')] =
array(
0 => '',
1 => sprintf(('Portfolio Updated. <a href="%s">View portfolio</a>'), esc_url(get_permalink($post_ID))),
2 => __('Custom Field Updated.'),
3 => __('Custom Field Deleted.'),
4 => __('Portfolio Updated.'),
5 => isset($_GET['revision']) ? sprintf(__('Portfolio Restored To Revision From %s'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
6 => sprintf(__('Portfolio Published. <a href="%s">View Portfolio</a>'), esc_url(get_permalink($post_ID))),
7 => __('Portfolio Saved.'),
8 => sprintf(__('Portfolio Submitted. <a target="_blank" href="%s">Preview Portfolio</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
9 => sprintf(__('Portfolio Scheduled For: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Portfolio</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
10 => sprintf(__('Portfolio Draft Updated. <a target="_blank" href="%s">Preview Portfolio</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
);
return $messages;
} // function: portfolio_messages END
// function: portfolio_filter BEGIN
function portfolio_filter()
{
register_taxonomy(
__("filter"),
array(__("portfolio")),
array(
"hierarchical" => true,
"label" => __("Filter"),
"singular_label" => __("Filter"),
"rewrite" => array(
'slug' => 'filter',
'hierarchical' => true
)
)
);
} // function: portfolio_filter END
add_action('init', 'post_type');
add_action('init', 'portfolio_filter', 0);
add_filter('post_updated_messages', 'portfolio_messages');
是什么,如果你不介意我问这个变化呢? – Doidgey
在你的代码中,你给'$ large_image分配一些值,然后在第二行中,你将同一个变量设置为同一个变量索引为0的元素的值。该元素不存在因为变量不是数组。在我的代码中,我添加了一个数组变量。 – RST