我正在尝试在wordpress中显示自定义帖子类型。我可以显示theubnail但我想根据项目类型调整大小:
我的代码如下:
<?php
$args = array('post_type' => 'package','package-category'=>'Kenya', 'posts_per_page'=>6 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();?>
<?php
$item_type == '1/4 Grid Style';
$item_class = $package_div_size_num_class[$item_type]['class'];
$item_size = $package_div_size_num_class[$item_type];
function print_package_mythumbnail( $post_id, $item_size, $last_minute = 'normal-type', $last_text = 'Read More' ){
$thumbnail_id = get_post_thumbnail_id( $post_id );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id , $item_size );
$alt_text = get_post_meta($thumbnail_id , '_wp_attachment_image_alt', true);
if( !empty($thumbnail) ){
echo '<div class="package-media-wrapper gdl-image">';
echo '<a href="' . get_permalink() . '">';
echo '<img src="' . $thumbnail[0] .'" alt="'. $alt_text .'"/>';
echo '</a>';
echo '</div>'; // package-media-wrapper
}
}
$thumbnail_id = get_post_thumbnail_id( $post_id );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id , $item_size );
$alt_text = get_post_meta($thumbnail_id , '_wp_attachment_image_alt', true);
if( !empty($thumbnail) ){
echo '<div class="package-media-wrapper gdl-image">';
echo '<a href="' . get_permalink() . '">';
echo '<img src="' . $thumbnail[0] .'" alt="'. $alt_text .'"/>';
if( !empty($last_minute) && !empty($last_text) ){
echo '<div class="package-ribbon-wrapper">';
echo '<div class="package-type ' . $last_minute . '">';
echo $last_text;
echo '</div>';
echo '<div class="clear"></div>';
echo '<div class="package-type-gimmick"></div>';
echo '<div class="clear"></div>';
echo '</div>';
}
echo '</a>';
echo '</div>'; // package-media-wrapper
}
&GT;
$item_type == '1/4 Grid Style'
定义为:
$package_div_size_num_class = array(
"1/4 Grid Style" => array(
"no-sidebar"=>"400x300",
"one-sidebar"=>"400x400",
"both-sidebar"=>"400x400",
"class"=>"gdl-package-widget"
)
)
如何根据项目类型调整缩略图的大小?
答案 0 :(得分:0)
使用css快速修复(为图像创建div并设置尺寸。)
你的style.css中的
.package-media-wrapper{
min-width: 30%;
max-width: 30% !important;
}
.package-image{
width: 100%;
}
如果你试图检测出有多少侧边栏,你的问题有点令人困惑?在大多数模板中,这是在代码中相当晚的页面模板上设置的吗?要对html进行更改,您可以检测
正在使用的模板 if(is_page_template('2column')) {
$imagehtml= ............;
} else if (etc) {}
除此之外,您正在查询查询以获取包含div的属性(在您的情况下,我猜是列大小?)
jQuery(document).ready(function() {
var width=jQuery('.package-media-wrapper').width();
if(width===300px) {
jQuery('.package-image').width('300px');
}
}