我有一个问题:如何在照片中添加灯箱。我一直坐在这里,我无法应付。
<?php
//Dynamic Portfolio With Shortcode
function portfolio_shortcode($atts){
extract( shortcode_atts( array(
\'category\' => \'\'
), $atts, \'\' ) );
$q = new WP_Query(
array(\'posts_per_page\' => 50, \'post_type\' => \'portfolio\')
);
//Portfolio taxanomy query
global $paged;
global $post;
$args = array(
\'post_type\' => \'portfolio\',
\'paged\' => $paged,
\'posts_per_page\' => -1,
);
$portfolio = new WP_Query($args);
if(is_array($portfolio->posts) && !empty($portfolio->posts)) {
foreach($portfolio->posts as $gallery_post) {
$post_taxs = wp_get_post_terms($gallery_post->ID, \'portfolio_category\', array("fields" => "all"));
if(is_array($post_taxs) && !empty($post_taxs)) {
foreach($post_taxs as $post_tax) {
$portfolio_taxs[$post_tax->slug] = $post_tax->name;
}
}
}
}
?>
<!--Category Filter-->
<ul class="portfolio_button_area fix">
<li class="filter portfolio_button active" data-filter="all">Pokaż wszystkie</li>
<?php foreach($portfolio_taxs as $portfolio_tax_slug => $portfolio_tax_name): ?>
<li class="filter portfolio_button" data-filter=".<?php echo $portfolio_tax_slug; ?>"><?php echo $portfolio_tax_name; ?></li>
<?php endforeach; ?>
</ul>
<!--End-->
<?php
echo\'<div id="Container">\';
while($q->have_posts()) : $q->the_post();
$idd = get_the_ID();
//Get Texanmy class
$item_classes = \'\';
$item_cats = get_the_terms($post->ID, \'portfolio_category\');
if($item_cats):
foreach($item_cats as $item_cat) {
$item_classes .= $item_cat->slug . \' \';
}
endif;
echo\'<div class="mix \'.$item_classes.\'">\'.get_the_post_thumbnail().\'</div>\';
endwhile;
echo\'</div>\';
wp_reset_query();
}
add_shortcode(\'portfolio\', \'portfolio_shortcode\');
SO网友:Xavier C.
如果只需要向每个元素添加一个“lightbox”类,则只需更改以下内容:
echo\'<div class="mix \'.$item_classes.\'">\'.get_the_post_thumbnail().\'</div>\';
对此:
echo\'<div class="mix lightbox \'.$item_classes.\'">\'.the_post_thumbnail(\'thumbnail\', array(\'class\' => \'lightbox\')) .\'</div>\';
如果要添加要打开的全尺寸图像,请尝试以下操作:
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),\'full\');
echo\'<div class="mix lightbox \'.$item_classes.\'"><a href="\' . esc_url($featured_img_url) . \'">\' . the_post_thumbnail(\'thumbnail\', array(\'class\' => \'lightbox\')) .\'</a></div>\';
检查
this 适用于所有可用尺寸