如何在自定义模板中显示多个后缩略图插件自定义后缩略图图像 [英] How to display Multiple Post Thumbnails plugin custom post thumbnail image in custom template

查看:279
本文介绍了如何在自定义模板中显示多个后缩略图插件自定义后缩略图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用wordpress 多个帖子缩略图插件添加自定义帖子元框图像字段。

I have used wordpress Multiple Post Thumbnails plugin to add custom post meta box image field.


if(class_exists('MultiPostThumbnails')){
new MultiPostThumbnails(
array($ b) $ b'label'=>'主页全宽',
'id'=>'主页全宽',
'post_type'=>'发布'

);
}

我想在我的网站上显示这个全尺寸的全新特色图片首页大横幅默认特色图片( http://nimb.ws/YelErQ )。

I want to display this new featured image with full size in my site Home page big banner default featured image (http://nimb.ws/YelErQ).

现在主题上面的帖子使用主题front-page.php文件中的以下代码显示图片显示。

Right now theme above post featured image display using following code in theme front-page.php file.

<?php
$ lead_article = ot_get_option('lead_article');
if(has_post_thumbnail($ lead_article)):
$ lead_article_img_horizo​​ntal = wp_get_attachment_image_src(get_post_thumbnail_id($ lead_article),tol-horizo​​ntal);
$ lead_article_img_vertical = wp_get_attachment_image_src(get_post_thumbnail_id($ lead_article),tol-vertical);
$ lead_article_img_horizo​​ntal_src = esc_url($ lead_article_img_horizo​​ntal [0]);
$ lead_article_img_vertical_src = esc_url($ lead_article_img_vertical [0]);
?>

< div id =lead-articleclass =post featured -style10 post-header>

< div data-interchange =[<?php echo $ lead_article_img_horizo​​ntal_src?>,landscape],[<?php echo $ lead_article_img_vertical_src?>,portrait]class =parallax_bg skrollable skrollable-betweendata-bottom-top =transform:translate3d(0px,-20%, 0像素); data-top-bottom =transform:translate3d(0px,20%,0px); style =transform:translate3d(0px,0.382158%,0px); background-image:url(<?php echo $ lead_article_img_horizo​​ntal_src?>)>< / div>

< / div>

<?php endif; ?>

我已按照插件说明 https://github.com/voceconnect/multi-post-thumbnails/wiki 但是在我的front-page.php文件中无效。

I have follow plugin instruction https://github.com/voceconnect/multi-post-thumbnails/wiki but that can't work in my front-page.php file.

所以任何人都知道解决方案,请帮助我。

So any one know solutions for this then please help me.

谢谢。

推荐答案

根据文档,您需要做的就是将此代码添加到模板中以显示您的自定义缩略图:

According to the documentation, all you need to do is add this code to your template to display your custom thumbnail:

<?php if (class_exists('MultiPostThumbnails')) :
MultiPostThumbnails::the_post_thumbnail(
    get_post_type(),
    'homepage-full-width'
);
endif; ?>

请注意,要使此代码正常工作,您需要将其置于 The Loop

Note that for this code to work as is you need to put it somewhere inside The Loop.

更新:

假设 ot_get_option('lead_article')返回一个ID,请尝试:

Assuming ot_get_option('lead_article') returns an ID, try this:

<?php
$lead_article = ot_get_option('lead_article');
$lead_article_img_horizontal = null;
$lead_article_img_vertical = null;

if (
    class_exists('MultiPostThumbnails') 
    && MultiPostThumbnails::has_post_thumbnail( get_post_type($lead_article), 'homepage-full-width', $lead_article )
):
    $lead_article_img_horizontal = MultiPostThumbnails::get_post_thumbnail_url( get_post_type($lead_article), 'homepage-full-width', $lead_article );
    $lead_article_img_vertical = esc_url( wp_get_attachment_image_src(get_post_thumbnail_id($lead_article), "tol-vertical")[0] );
// Fallback to featured image if available
elseif ( has_post_thumbnail($lead_article) ):
    $lead_article_img_horizontal = esc_url( wp_get_attachment_image_src(get_post_thumbnail_id($lead_article), "tol-horizontal")[0] );
    $lead_article_img_vertical = esc_url( wp_get_attachment_image_src(get_post_thumbnail_id($lead_article), "tol-vertical")[0] );
endif;

if ( $lead_article_img_horizontal && $lead_article_img_vertical ):
?>
<div id="lead-article" class="post home-featured-post featured-style10 post-header">
    <div data-interchange="[<?php echo $lead_article_img_horizontal ?>, landscape], [<?php echo $lead_article_img_vertical ?>, portrait]" class="parallax_bg skrollable skrollable-between" data-bottom-top="transform: translate3d(0px, -20%, 0px);" data-top-bottom="transform: translate3d(0px, 20%, 0px);" style="transform: translate3d(0px, 0.382158%, 0px);background-image: url(<?php echo $lead_article_img_horizontal ?>)"></div>
</div>
<?php
endif;
?>

这篇关于如何在自定义模板中显示多个后缩略图插件自定义后缩略图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆