当前位置: 首页 > news >正文

手机网站微信链接怎么做自己搭建一个网站

手机网站微信链接怎么做,自己搭建一个网站,微信小店可以做分类网站,珠海建网站要为WordPress注册一个Carousel轮播区块,你可以创建一个自定义Gutenberg块。以下是一个简单的示例,说明如何创建一个Carousel轮播区块: 1. 在你的主题目录中创建一个名为carousel-block的子文件夹。在这个文件夹中,创建一个名为c…

要为WordPress注册一个Carousel轮播区块,你可以创建一个自定义Gutenberg块。以下是一个简单的示例,说明如何创建一个Carousel轮播区块:

1. 在你的主题目录中创建一个名为`carousel-block`的子文件夹。在这个文件夹中,创建一个名为`carousel-block.php`的文件。将以下代码添加到该文件中:

```php
<?php
/*
Plugin Name: Carousel Block
Description: A simple Carousel block for WordPress Gutenberg.
Version: 1.0
Author: Your Name
Author URI: https://example.com
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

function carousel_block_register() {
    wp_register_script(
        'carousel-block-editor',
        plugins_url('carousel-block-editor.js', __FILE__),
        array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components'),
        filemtime(plugin_dir_path(__FILE__) . 'carousel-block-editor.js')
    );

    wp_register_style(
        'carousel-block-editor',
        plugins_url('carousel-block-editor.css', __FILE__),
        array(),
        filemtime(plugin_dir_path(__FILE__) . 'carousel-block-editor.css')
    );

    register_block_type('carousel-block/carousel', array(
        'editor_script' => 'carousel-block-editor',
        'editor_style' => 'carousel-block-editor',
    ));
}
add_action('init', 'carousel_block_register');
```

2. 在`carousel-block`文件夹中创建一个名为`carousel-block-editor.js`的文件,并将以下代码添加到该文件中:

```javascript
const { registerBlockType } = wp.blocks;
const { RichText, MediaUpload } = wp.editor;
const { Button } = wp.components;

registerBlockType('carousel-block/carousel', {
    title: 'Carousel',
    icon: 'images-alt',
    category: 'common',
    attributes: {
        title: {
            type: 'string',
            source: 'html',
            selector: 'h2',
        },
        imageUrl: {
            type: 'string',
            source: 'attribute',
            attribute: 'src',
            selector: 'img',
        },
        imageId: {
            type: 'number',
        },
    },
    edit({ attributes, setAttributes }) {
        const { title, imageUrl, imageId } = attributes;

        const onSelectImage = (image) => {
            setAttributes({
                imageUrl: image.url,
                imageId: image.id,
            });
        };

        return (
            <div className="carousel-block">
                <h2>Carousel</h2>
                <RichText
                    tagName="h2"
                    value={title}
                    onChange={(value) => setAttributes({ title: value })}
                    placeholder="Title..."
                />
               <MediaUpload
                    onSelect={onSelectImage}
                    type="image"
                    value={imageId}
                    render={({ open }) => (
                       <Button onClick={open}>
                            {imageUrl ? 'Edit Image' : 'Select Image'}
                        </Button>
                    )}
                />
                {imageUrl && <img src={imageUrl} alt={title} />}
            </div>
        );
    },
    save({ attributes }) {
        const { title, imageUrl } = attributes;
        return (
            <div className="carousel-block">
                <h2>{title}</h2>
                {imageUrl && <img src={imageUrl} alt={title} />}
            </div>
        );
    },
});
```

3. 在`carousel-block`文件夹中创建一个名为`carousel-block-editor.css`的文件,并将以下代码添加到该文件中:

```css
.carousel-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
}

.carousel-block h2 {
    margin-bottom: 10px;
}

.carousel-block img {
    max-width: 100%;
    height: auto;
}
```

4. 在你的主题的`functions.php`文件中,添加以下代码以激活Carousel轮播区块插件:

```php
function my_theme_register_carousel_block() {
    include_once('carousel-block/carousel-block.php');
}
add_action('init', 'my_theme_register_carousel_block');
```

现在,你应该能够在WordPress编辑器中看到一个名为“Carousel”的新块。你可以在编辑器中添加Carousel块,设置标题和图片,然后将其添加到页面中。

请注意,这个示例仅用于演示目的,实际项目中可能需要更多的功能和优化。在使用此插件时,请确保遵循WordPress最佳实践和安全性原则。

来源 https://www.mymoban.com/wp/

http://www.hengruixuexiao.com/news/19629.html

相关文章:

  • 娱乐网站模板品牌网站建设解决方案
  • 个人免费网站怎么建设google官网进入
  • 沈阳市建设工程安全监督站网站指数基金怎么买
  • 襄阳市建设局网站品牌公关公司
  • android 网站模板下载怎么优化关键词
  • 怎么做县城分类信息网站it菜鸡网seo
  • 网站开发项目业务要求b2b关键词排名工具
  • 自己怎么做淘宝网站衡水网站优化推广
  • 美国哪个网站做diy电脑外贸网站哪个比较好
  • 关于幼儿建设网站ppt模板百度云搜索引擎入口
  • 做响应式的网站电商平台推广方式有哪些
  • 台州 网站建设手机百度搜索引擎
  • 搭建公司网站南昌seo优化公司
  • 的网站建设公司哪家好营销网站建设流程
  • 惠州做网站乐云seo轻松上线seo排名优化的方法
  • 网站是怎么做爱用建站
  • 花钱做的网站推广被骗深圳招聘网络推广
  • 网站开发实例社区优化关键词推广
  • 极兔24小时在线客服系统泉州关键词优化软件
  • 网站制作资质百度网页游戏
  • 网站建设教程皆赞湖南岚鸿完成seo线上培训机构
  • 独山子区做网站哪里好淘宝关键词排名查询工具免费
  • 防疫网站网页设计网站如何做推广
  • 广州高档网站建设app推广平台
  • 网站建设在开封找谁做seo外包费用
  • asp本地网站无法打开产品怎么做推广和宣传
  • 北京科技网站制作怎样才能在百度上面做广告宣传
  • 黄冈市建设银行网站免费信息推广平台
  • 医院做网站运维班级优化大师的优点
  • 网站开发课表查询浙江网站seo