标签: WordPress开发

  • 2021年4月,WordPress CMS市场份额已经超过40%

    2021年4月,WordPress CMS市场份额已经超过40%

    在2021年4月,市场份额已经超过40%,足以证明WordPress作为内容管理系统(CMS)的实力。

    2020 1 Apr2020 1 May2020 1 Jun2020 1 Jul2020 1 Aug2020 1 Sep2020 1 Oct2020 1 Nov2020 1 Dec2021 1 Jan2021 1 Feb2021 1 Mar2021 1 Apr2021 4 Apr
    None43.4%43.1%41.6%40.8%40.5%39.8%39.5%39.0%38.7%38.3%37.8%37.3%36.8%36.8%
    WordPress35.7%36.0%37.0%37.6%37.8%38.3%38.5%38.8%39.1%39.5%39.9%40.4%40.8%40.9%
    Shopify2.1%2.2%2.4%2.5%2.7%2.8%2.9%3.1%3.1%3.2%3.3%3.3%3.4%3.4%
    Joomla2.4%2.4%2.4%2.4%2.3%2.3%2.3%2.2%2.2%2.2%2.2%2.1%2.1%2.1%
    Squarespace1.4%1.4%1.4%1.4%1.5%1.4%1.4%1.4%1.4%1.4%1.6%1.6%1.6%1.6%
    Wix1.3%1.3%1.4%1.4%1.5%1.5%1.5%1.6%1.5%1.5%1.5%1.5%1.5%1.5%
    Drupal1.6%1.6%1.6%1.6%1.6%1.5%1.5%1.5%1.5%1.5%1.5%1.5%1.5%1.5%
    Bitrix1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.1%1.0%1.0%1.0%1.0%
    Blogger0.9%0.9%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%1.0%
    Magento0.8%0.8%0.8%0.8%0.8%0.8%0.7%0.7%0.7%0.7%0.7%0.7%0.7%0.7%
    OpenCart0.5%0.6%0.6%0.6%0.6%0.6%0.6%0.6%0.6%0.6%0.6%0.7%0.7%0.7%
    PrestaShop0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%0.5%
    Weebly0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%
    TYPO30.4%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%
    Webflow0.1%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.3%0.3%0.3%0.3%
    Bigcommerce0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.3%0.3%0.3%0.3%0.3%
    GoDaddy Website Builder0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.3%0.2%0.2%0.2%0.2%0.2%0.2%
    Adobe Dreamweaver0.3%0.3%0.3%0.3%0.3%0.3%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%
    Tilda0.1%0.1%0.1%0.1%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%
    HubSpot CMS0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.2%0.2%0.2%0.2%0.2%0.2%
    DataLife Engine0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%
    Prom.ua0.1%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%
    Gatsby0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.2%0.2%0.2%0.2%0.2%0.2%0.2%
    FrontPage0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%
    Duda0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.2%0.1%0.1%0.1%0.1%0.2%0.2%
    GitHub Pages0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.2%0.2%0.2%0.2%
    DotNetNuke0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.1%0.1%
    XenForo0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    phpBB0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Craft CMS0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    vBulletin0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Adobe Muse0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Dealer.com0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Hugo0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Sitecore CMS0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    ExpressionEngine0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    MODx0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    CMS.S30.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    uCoz0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    nopCommerce0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    IPS Community Suite0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    CS-Cart0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Concrete50.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Shopware0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    MediaWiki<0.1%<0.1%<0.1%0.1%<0.1%<0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    October CMS0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Kentico0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Cafe240.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Progress Sitefinity0.2%0.2%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Ghost<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%0.1%0.1%0.1%
    Simple Machines Forum<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%0.1%0.1%0.1%
    Ticimax<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%0.1%0.1%0.1%0.1%0.1%
    SharePoint0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Discuz!0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%
    Google Sites<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%0.1%0.1%0.1%
    Zendesk<0.1%0.1%
    Jekyll<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%0.1%
    Liferay0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%<0.1%<0.1%<0.1%
    Mobirise<0.1%<0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%<0.1%<0.1%<0.1%
    Adobe Experience Manager0.1%0.1%0.1%0.1%0.1%0.1%0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%
    Jimdo0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%<0.1%<0.1%
    Contao0.1%0.1%0.1%0.1%0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%
    Volusion0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%<0.1%<0.1%<0.1%<0.1%<0.1%
    osCommerce0.1%0.1%0.1%0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%
    Zen Cart0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%<0.1%

    WordPress说是一个CMS系统,其实意义还是比较传统的看法,其实WordPress能做的东西是越来越多,如我用其做过下载、企业、个人博客、多用户博客、自媒体、商城、外贸等各类形式的站点。

    在我看来WordPress更像是一个介于面对后端开发人员的开发框架和面对前端开发人员模板引擎之间的一个系统。只要会jQuery、JavaScript、CSS、html和简单的PHP判断语言,利用函数即可非常容易的写出WordPress主题

  • wordpress子主题:如何覆盖模板.php文件

    wordpress子主题:如何覆盖模板.php文件

    我在wordpress中设置了子主题, 并且子主题中的style.css和functions.php正常工作。我现在想用子主题中的版本覆盖其他模板.php文件。我似乎无法使这些文件覆盖父主题。

    子主题functions.php:

    <?php
    //enqueue styles
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 'overwrite' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    //overwrite template pages
    function overwrite() {
        wp_enqueue_script( get_template_directory_uri() . '/inc/structure/hooks.php' );
        wp_enqueue_script( get_template_directory_uri() . '/inc/structure/header.php' );
    }

    我在/ child-theme / inc / structure /中有一个hooks.php和header.php

    对于子主题, 你无需排队任何模板(PHP)文件, 只需将一个PHP文件添加到你的子主题中, 其名称和路径与你试图覆盖父主题的名称和路径完全相同, 它将自然地替换它。

  • WordPress 后台列表中 如何显示自定义文章分类

    WordPress 后台列表中 如何显示自定义文章分类

    前面我们写到WordPress插件开发中,如何自定义文章的一些问题。

    wordpress使用register_post_type 函数创建自定义文章类型

    WordPress函数:register post type (自定义文章类型)用法和范例

    WordPress 插件开发 自定义文章类型中 add_meta_box 如何使用原生的分类/标签显示并保存数据?

    WordPress 插件开发 自定义文章类型 置顶

    本文中我们将给出如何将我们自定义的文章之后,相关联的自定义类型显示在后台的列表中。

    显示效果

    主要函数: get_the_terms

    官方说明:

    get_the_terms()

    代码示例:

    	public function columns_data( $column ) {
    		global $post;
    		
    		$$column = get_post_meta( $post->ID, self::$key.$column, true );
    		// echo $column.'--'.$$column;
    		$allowed_tags = array(
    			'a' => array(
    				'href' => array(),
    				'rel'  => array(),
    			),
    		);
    		if( 'brand' == $column ){
    			echo get_the_term_list($post->ID,'jvps_tax');
    		}
    		elseif( 'stock' === $column ){
    			echo esc_html( $stock ? '有货' : '无货');
    		}
    		else{
    			echo $$column;
    		}
    		// if ( 'url' === $column ) {
    		// 	echo wp_kses( make_clickable( esc_url( $url ? $url : '' ) ), $allowed_tags );
    		// } elseif ( 'permalink' === $column ) {
    		// 	echo wp_kses( make_clickable( get_permalink() ), $allowed_tags );
    		// } elseif ( 'stock' === $column ) {
    		// 	echo esc_html( $count ? $count : 0 );
    		// }else{
    		// 	echo $column;
    		// }
    	}
  • WordPress 如何获取文章发表用户ID

    WordPress 如何获取文章发表用户ID

    WordPress插件/主题开发中,如何获取文章发表用户的ID ?

    LOOP循环中

    官方文档:

    get_the_author_meta( string $field = '', int|false $user_id = false )

    Retrieves the requested data of the author of the current post.

    Description 

    Valid values for the $field parameter include:

    • admin_color
    • aim
    • comment_shortcuts
    • description
    • display_name
    • first_name
    • ID
    • jabber
    • last_name
    • nickname
    • plugins_last_view
    • plugins_per_page
    • rich_editing
    • syntax_highlighting
    • user_activation_key
    • user_description
    • user_email
    • user_firstname
    • user_lastname
    • user_level
    • user_login
    • user_nicename
    • user_pass
    • user_registered
    • user_status
    • user_url
    • yim

    Parameters

    $field

    (string) (Optional) The user field to retrieve.

    Default value: ”$user_id

    (int|false) (Optional) User ID.

    Default value: false

    Return

    (string) The author’s field from the current author’s DB object, otherwise an empty string.

    在循环外面通过以下方法获取用户ID

    $author_id = get_post_field ('post_author', get_the_ID() );
  • WordPress 插件开发 激活插件时添加通知 代码实例

    WordPress 插件开发 激活插件时添加通知 代码实例

    最近我们在重构WordPress采集插件WP-JPost,这里记录一下当我们激活插件时在面板中添加通知的方法。

    使用场景

    我们插件使用register_post_type方法来构建了自定义文章(wordpress使用register_post_type 函数创建自定义文章类型)后出现了404的错误。这里我们使用添加通知的方法来告知用户必须设置一下【固定链接】(WordPress 固定链接设置)才能正常使用。下面我们记录一下具体的实现方法。

    添加通知方法

    可以通过admin_notices的add_action来实现。

    		add_action( 'admin_notices', array( $this, 'jpost_notice' ) );

    实现方法函数

    做好输出工作即可。

    	public function jpost_notice(){
    		if( get_post_type() == $this->post_type )
    			printf('<div class="jads"></div>');
    		/* Check transient, if available display notice */
    		if (! get_option('permalink_structure') ){
    			printf('<div class="updated notice notice-warning is-dismissible">');
    			printf('<p>%s</p>', __( 'WP-JPost need Navigate to [ <strong>Dashboard</strong> ] -> [ <strong>Settings</strong> ] -> [ <strong>Permalink</strong> ] page -> click [ <strong>Save</strong> ] button to flush rewrite rules. [ <a href="https://www.jiloc.com/44235.html">?</a> ]') );
    			printf('</div>');
    			/* Delete transient, only display this notice once. */
    			// delete_transient( 'jpost-notice' );
    		}
    	}

    激活插件事件

    当没有设置固定链接的时候输出 jpost-notice 的通知。

    	static function active() {
    		if (! get_option('permalink_structure') )
    			set_transient( 'jpost-notice', true );
    		flush_rewrite_rules();
    	}

    全部代码

    //register activation function
    register_activation_hook( __FILE__, array( 'WP_JPost', 'active') );
    //register deactivation function
    register_deactivation_hook( __FILE__ , array( 'WP_JPost', 'deactive') );
    class WP_JPost {
    	protected $jpost_readme = 'https://www.jiloc.com/wp-jpost';
    	protected $post_type = 'wp-jpost';
    	protected $rewrite_slug = 'jpost';
    	/**
    	 * Constructor.
    	 */
    	public function __construct() {
                    add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
    		add_action( 'init', array( $this, 'register_post_type' ) );
    		// add_filter( 'post_type_link', array($this , 'custom_link' ), 1, 3);
    		add_filter( 'query_vars', array( $this, 'jpost_query_vars') );
    		add_filter( 'post_updated_messages', array( $this, 'updated_message' ) );
    		// add_action( 'admin_init',array($this,'register_setting_page'));
    		add_action( 'admin_menu', array( $this, 'add_meta_box' ) );
    		add_action( 'save_post', array( $this, 'meta_box_save' ), 1, 2 );
    		add_action( 'manage_wp-jpost_posts_custom_column', array( $this, 'columns_data' ) );
    		add_filter( 'manage_wp-jpost_posts_columns', array( $this, 'columns_filter' ) );
    		add_action( 'template_redirect', array( $this, 'jpost_grab' ) );
    		add_action( 'admin_notices', array( $this, 'jpost_notice' ) );
    	}
    	
    	public function custom_link( $permalink, $post ){
    		if ( $post->post_type == $this->post_type ){
    			return $permalink . ( strpos( $permalink ,'?' ) !== false ? '&' : '?') . 'jpage='.get_post_meta( get_the_ID(), '_jpost_task_list_max_page', true ) . '&debug=1';
    		} else {
    			return $permalink;
    		}
    	}
    	public function jpost_notice(){
    		if( get_post_type() == $this->post_type )
    			printf('<div class="jads"></div>');
    		/* Check transient, if available display notice */
    		if (! get_option('permalink_structure') ){
    			printf('<div class="updated notice notice-warning is-dismissible">');
    			printf('<p>%s</p>', __( 'WP-JPost need Navigate to [ <strong>Dashboard</strong> ] -> [ <strong>Settings</strong> ] -> [ <strong>Permalink</strong> ] page -> click [ <strong>Save</strong> ] button to flush rewrite rules. [ <a href="https://www.jiloc.com/44235.html">?</a> ]') );
    			printf('</div>');
    			/* Delete transient, only display this notice once. */
    			// delete_transient( 'jpost-notice' );
    		}
    	}
    	static function active() {
    		if (! get_option('permalink_structure') )
    			set_transient( 'jpost-notice', true );
    		flush_rewrite_rules();
    	}
    }
  • WordPress插件开发 register_post_type 设定菜单 位置 结合 add_submenu_page 添加自定义设置页面

    WordPress插件开发 register_post_type 设定菜单 位置 结合 add_submenu_page 添加自定义设置页面

    前面我们讲述了利用 register_post_type 进行注册了自定义的文章(wordpress使用register_post_type 函数创建自定义文章类型), 然后我们为这个自定义的文章添加了自定义的设置页面。要把菜单放在一个栏目中。如下图所示:

    下面我们直接给出示例代码。

    plugin.php 设置前后台使用不同的类

    require_once JPOST_DIR . '/includes/class-wp-jpost.php';
    new WP_JPost();
    if ( is_admin() ) {
    	require_once JPOST_DIR . '/includes/class-wp-jpost-settings.php';
    	new JPostSettings();
    }

    WP_JPost 类

    在 admin_menu 钩子中添加add_meta_box

     add_action( 'admin_menu', array( $this, 'add_meta_box' ) ); 

    add_meta_box 里添加菜单

    	public function add_meta_box() {
    		add_menu_page( 'wp_jpost', 'wp-jpost', 'administrator', 'wp-jpost', '', '', 100);
    		add_submenu_page('wp-jpost', __('Add New','wp-jpost'), __('Add New','wp-jpost'), 'administrator', 'post-new.php?post_type=wp-jpost', '' );
                    // do something
    	}

    注册自定义文章

    		register_post_type(
    			$slug,
    			array(
    				'labels'              => $labels,
    				'public'              => true,
    				'exclude_from_search' => apply_filters( 'jposts_exclude_from_search', true ),
    				'show_ui'             => true,
    				'query_var'           => true,
    				'menu_position'       => 999,
    				'supports'            => $supports_array,
    				'rewrite'             => array(
    					'slug'       => $rewrite_slug,
    					'with_front' => false,
    				),
    				'show_in_menu'	=>	'wp-jpost',
    				'show_in_rest'        => true,
    			)
    		);

    注意参数 show_in_menu 。这里设置显示的位置。

    JPostSettings 类中创建设置菜单

        public function __construct(){
            add_action( 'admin_menu', array( $this, 'settings' ) );
        }

    添加子菜单

        // Add Menu 
        public function settings(){
            add_submenu_page('wp-jpost', __('Settings','wp-jpost'), __('Settings','wp-jpost'), 'administrator', 'wp-jpost', array($this, 'create_admin_page'));
        }
    
        /**
         * Options page callback
         */
        public function create_admin_page(){
            // Set class property
            $this->options = get_option( '_jpost_setting' );
            settings_errors();//show settings messages.
            printf( '<div class="wrap"><h1>%s</h1><form method="post" action="options.php">',__('WP-JPost Settings','wp-jpost') );
            settings_fields( '_jpost_option_group' );
            do_settings_sections( '_jpost_settings' );
            submit_button();
            printf( '</form></div>' );
        }

    到这里我们的菜单就建立完成了。

WeChat