将single.php图像添加到wordpress中的flickity滑块? [英] Add single.php images to flickity slider in wordpress?

查看:81
本文介绍了将single.php图像添加到wordpress中的flickity滑块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为WordPress托管网站上的所有single.php帖子添加标准的Flickity滑块。



我想抓住独特的附件一个帖子的图像,然后在滑块中显示它们,但我失败了。



我发现很难从帖子中调用图像并显示它们在滑块中。每个帖子的帖子图片总是不同的,每个帖子的图片数量也各不相同。



如果不使用任何WordPress插件我怎么能这样做?我想在single.php页面中编写代码。



资源: v [ ^ ]



我尝试了什么:



我已经尝试了以下代码,但是,这是从媒体页面(只显示一个奇怪的)。我可能完全错了 - 请原谅我的编码,我只是一个初级开发者。



我把它放在了single.php的顶部页面:



$ post-> ID,

'post_type'=> '附件',

'orderby'=> 'menu_order',//您还可以按日期对图片进行排序或者是名称

'order'=> 'ASC',

'numberposts'=> 10,//图像数量(幻灯片)

'post_mime_type'=> 'image'

);

if($ images = get_children($ args)){

//如果帖子中没有图片,不要显示任何东西

echo'

I'm looking to add a standard 'Flickity' slider to all single.php posts on a WordPress hosted website.

I want to grab the unique attached images of a post and then display them in the slider, but I'm failing.

I'm finding it difficult to call the images from the post and display them in the slider. The post images are always different per post and the number of images also vary per post.

How could I go about this without using any WordPress plugins? I'm looking to code it in the single.php page.

Resource: v[^]

What I have tried:

I've tried the following code, however, this is pulling images right from the media pages (displaying only one weirdly). I might be completely wrong with this - please forgive my coding, I'm only a junior dev.

I've placed this at the top of the single.php page:

$post->ID,
'post_type' => 'attachment',
'orderby' => 'menu_order', // you can also sort images by date or be name
'order' => 'ASC',
'numberposts' => 10, // number of images (slides)
'post_mime_type' => 'image'
);
if ( $images = get_children( $args ) ) {
// if there are no images in post, don't display anything
echo '

';

foreach($ images as $ image){

echo'
  • '。 wp_get_attachment_image($ image-> ID,'my​​_slider')。 '
  • ';

    }

    echo'
    ';
    foreach( $images as $image ) {
    echo '
  • ' . wp_get_attachment_image( $image->ID, 'my_slider' ) . '
  • ';
    }
    echo '

    ';

    }

    ? >

    ';
    }
    ?>

    推荐答案

    post-> ID,

    'post_type'=> '附件',

    'orderby'=> 'menu_order',//您还可以按日期对图片进行排序或者是名称

    'order'=> 'ASC',

    'numberposts'=> 10,//图像数量(幻灯片)

    'post_mime_type'=> 'image'

    );

    if(
    post->ID,
    'post_type' => 'attachment',
    'orderby' => 'menu_order', // you can also sort images by date or be name
    'order' => 'ASC',
    'numberposts' => 10, // number of images (slides)
    'post_mime_type' => 'image'
    );
    if (


    images = get_children(
    images = get_children(


    args )){

    //如果帖子中没有图片,不显示任何内容

    echo'
    args ) ) {
    // if there are no images in post, don't display anything
    echo '
    ';

    foreach(
    ';
    foreach(


    这篇关于将single.php图像添加到wordpress中的flickity滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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