如何在没有插件的情况下为wordpress帖子创建画廊 [英] How to create galleries for wordpress posts without plugin

查看:89
本文介绍了如何在没有插件的情况下为wordpress帖子创建画廊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的帖子创建画廊,如下所示:

I want to create galleries for my posts working like this :

  1. 我在wordpress新页面中选择图片并上传
  2. Wordpress会创建由这些图像组成的数组
  3. 最后,我使用该数组并将图库放入我的single.php文件中

实际上woocommerce使用的是您在图片中看到的确切内容(对不起,我没有安装英语wordpress)

Actually woocommerce is using the exact thing as you see in the picture ( sorry i didn't have English wordpress installed )

有什么建议吗?

推荐答案

您可以根据需要使用默认的画廊行为

you can use the default gallery behavior to your need

  • 在巡回展览中插入一个画廊,它将创建一个简短的代码,例如

  • Insert a gallery in tour post, it will create a shortcode like

[gallery ids="12,45,67,34"]

  • 覆盖默认的画廊简码功能,以使其不显示在您的帖子中

  • override the default gallery shortcode function to not display it in your post

    remove_shortcode( 'gallery', 'gallery_shortcode' );
    add_shortcode( 'gallery', 'my_gallery');
    function my_gallery(){
        return '';
    }
    

  • 检索图像ID的数组

  • retrieve an array of images ids

    $post_content = get_the_content();
    preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
    if($ids){
        $array_id = explode(",", $ids[1]);
    }
    

  • 这篇关于如何在没有插件的情况下为wordpress帖子创建画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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