Useful GitHub repos

Javascripts Trianglify Get random triangle Canvas image https://github.com/qrohlf/trianglify qrious Qrcode generate https://github.com/neocotic/qrious Emojionearea Emoji picker https://github.com/mervick/emojionearea jQuery file upload Drag file to upload https://github.com/blueimp/jQuery-File-Upload Unveil Lazy load image https://github.com/luis-almeida/unveil Animsition Link Transition on webpages ...

2021-06-10 · 1 min · Duke Yin

不能选择数据库 Can’t Select Database

导出原有数据库删除原有数据库新建一个数据库按照不同的名字修改wp-config.php中数据库信息done

2020-11-02 · 1 min · Duke Yin

Single Cron job

add_action('example_action', 'example', 1, 3); $args = array ( 2, 1, 3 ); wp_schedule_single_event(time(), 'example_action', $args); function example($a, $b, $c) { //doing things here }

2020-10-23 · 1 min · Duke Yin

Wordpress通过IP获得地理位置

<?php if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip_address = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip_address = $_SERVER['REMOTE_ADDR']; } $content = wp_remote_retrieve_body( wp_remote_get('https://apis.map.qq.com/ws/location/v1/ip?ip='.$ip_address.'&key='.get_option( 'p2_qqmap_key' ) ) ); $content_obj = json_decode($content, true); print_r($content_obj); $region_id = $content_obj['result']['ad_info']['adcode']; $region_ct = $content_obj['result']['ad_info']['city']; echo $region_id; echo $region_ct; ?>

2019-12-02 · 1 min · Duke Yin

Hooks简介2:自定义挂钩和可插拔功能简介

如果您已经阅读了WordPress Hooks简介的第1部分 ,则应该清楚地了解什么构成“动作”或“过滤器”钩子以及可以在何处使用它们。 今天,我们将深入探讨“兔子洞”,讨论可插拔功能以及创建自己的“动作”和“过滤器”挂钩点的概念,以及如何利用它们并在主题和主题之间建立关系。使用各种WordPress Hooks的插件。 注意:本教程不适合胆小的人(有一些高级知识)。 如果您还没有阅读第1部分,我强烈建议您在继续阅读之前阅读。 什么是自定义动作和过滤点? 如前所述,可以在WordPress页面加载过程中使用操作在关键点运行您自己的代码,以及使用过滤器修改文本,设置或几乎所有带有过滤器的内容,以量身定制WordPress安装完全符合您的要求。 那主题和插件呢? 我该如何在其中注入自己的定制特效? 这就是自定义操作和过滤点的来源。 使用WordPress核心本身内置的相同功能,我们可以在主题和插件中创建我们自己的动作点(例如“ wp_head”或“ wp_footer”)。 从本质上讲,这是相对简单的,可以以标准方式或更高级的方式使用。 假设我们正在开发一个名为“ WPCandy News”的插件,则可以在显示最新新闻的小部件的顶部添加以下内容: <?php do_action( 'wpcandy_news_widget_before' ); ?> 这是构成WordPress操作点的核心。 do_action()函数指示WordPress查找附加到指定标签的钩子(在我们的示例中为“ wpcandy_news_widget_before”)并运行该函数。 简单吧? 等一下,这还不是全部。 do_action()函数还可以接受多个参数(参数),然后根据需要将其传递给我们所连接的函数。 听起来很复杂,对吧? 并不是的。 让我们使用上面相同的示例,但将其扩展一点。 <?php do_action( 'wpcandy_news_widget_before', $limit, $id ); ?> 在代码段中,我添加了两个额外的参数。 $ limit和$ id变量。 这些是由插件创建的示例变量,分别包含要显示的文章数和我们分配给窗口小部件中元素的ID。 如果我们正确设置了add_action()调用,则应该在函数中接收这些值,以备使用。 等等,add_action()在哪里出现? 没有add_action() ,`do_action()`毫无意义。 `add_action()`函数允许我们以及其他主题或插件分配要在WordPress达到我们的操作后运行的功能。 从根本上讲,我们如何抓住新的行动要点的一个例子是: <?php add_action( 'wpcandy_news_widget_before', 'wpcandy_news_widget_before_content' ); function wpcandy_news_widget_before_content () { echo '<p>' . __( ' This is our custom text.', 'wpcandy' ) . </p>'; } // End wpcandy_news_widget_before_content() ?> 现在一切都很好,但是$ limit和$ id呢? 输入我们的最后两个参数; “优先”和“可接受的论点”。 ...

2019-11-10 · 1 min · Duke Yin

Hooks简介1:基本的WordPress构建块

WordPress钩子可以说是WordPress开发的基础,构成了核心功能的很大一部分,迄今为止几乎所有可用的插件和主题都在使用它。 对于刚开始使用WordPress开发的用户来说,钩子的概念也可能有些令人生畏。 今天,我们将深入了解WordPress钩子的确切含义,以及它们如何在您成为WordPress摇滚明星的途中为您提供帮助。 无论如何,WordPress钩子到底是什么? WordPress钩子实质上是一种触发器,允许用户使用简短的代码片段来修改WordPress主题或插件的区域,或将自己的代码添加到WordPress的各个部分而无需修改原始文件。 例如,“当WordPress选择要加载的模板文件时,运行我们的自定义代码”或“当为每个帖子生成内容时,在内容末尾添加社交书签链接”。 一旦我们对不同类型的钩子有了更多的了解,这些示例将得到扩展。 挂钩可以分为“动作”和“过滤器”挂钩,前者允许在各个点插入自定义代码(与JavaScript中的事件不同),后者允许对内容的各种位进行操作(例如,内容页面或博客文章)。 让我们仔细看看其中的每个,对吧? 动作挂钩 动作钩子是WordPress核心,主题和插件代码中的指定点,可以在外部资源(钩子所在范围的范围之外……在核心,主题或插件中)插入其他代码,并由此插入自定义代码以执行他们可能需要的其他功能。 一个例子是常用的wp_head操作钩,许多主题和插件都使用它来注入其他CSS样式表,处理代码或它们需要放置在WordPress主题的XHTML结构的<head>和</head>标签之间的任何其他内容。 这就是包含wp_head();的原因wp_head(); 在所有WordPress主题中。 要挂接一个动作,请在主题的functions.php文件(或插件的代码)中创建一个函数,然后使用add_action()函数将其挂接,如下所示: <?php add_action( 'wp_head', 'wpcandy_actionhook_example' ); function wpcandy_actionhook_example () { echo '&lt;meta name="description" content="This is the meta description for this page." /&gt;' . " “; } // End wpcandy_actionhook_example() ?> ...

2019-11-10 · 2 min · Duke Yin

Mobile app

Basics <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-title" content="KeepMins" /> <meta name="theme-color" content="#fffff" /> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" /> <link rel="apple-touch-icon-precomposed" href="/i/iosicon.png" /> <link rel="manifest" href="/static/manifest.json" /> iOS Status Bar <meta name="apple-mobile-web-app-status-bar-style" content="取值"> default black-translucent black White manifest.json { "name": "Keep Minutes", "short_name": "KeeMins", "theme_color": "#53c5e7", "background_color": "#53c5e7", "display": "fullscreen", "orientation": "portrait", "Scope": "/", "start_url": "/", "icons": [ { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-72x72.png", "sizes": "72x72", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-96x96.png", "sizes": "96x96", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-144x144.png", "sizes": "144x144", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-152x152.png", "sizes": "152x152", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-192x192.png", "sizes": "192x192", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-384x384.png", "sizes": "384x384", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-512x512.png", "sizes": "512x512", "type": "image/png" } ], "splash_pages": null } <meta name="msapplication-navbutton-color" content="#3f51b5"> <meta name="msapplication-starturl" content="/?utm_source=homescreen"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="application-name" content="Add To Home"> <meta name="apple-mobile-web-app-title" content="ADH"> <meta name="apple-mobile-web-app-status-bar-style" content="#3f51b5"> <link rel="manifest" href="manifest.json"> <link rel="apple-touch-icon" sizes="192x192" href="icons/android-chrome-192x192.png" /> <link rel="apple-touch-icon" sizes="144x144" href="icons/android-chrome-144x144.png" /> <link rel="apple-touch-icon" sizes="114x114" href="icons/android-chrome-114x114.png" /> <link rel="apple-touch-icon" sizes="72x72" href="icons/android-chrome-72x72.png" /> <link rel="apple-touch-icon" sizes="57x57" href="icons/android-chrome-57x57.png" /> <link rel="apple-touch-icon" sizes="48x48" href="icons/android-chrome-48x48.png" /> <link rel="apple-touch-icon" sizes="36x36" href="icons/android-chrome-36x36.png" /> <link rel="icon" sizes="192x192" href="/icons/android-chrome-192x192.png" /> <link rel="icon" sizes="144x144" href="icons/android-chrome-144x144.png" /> <link rel="icon" sizes="114x114" href="icons/android-chrome-114x114.png" /> <link rel="icon" sizes="72x72" href="icons/android-chrome-72x72.png" /> <link rel="icon" sizes="57x57" href="icons/android-chrome-57x57.png" /> <link rel="icon" sizes="48x48" href="icons/android-chrome-48x48.png" /> <link rel="icon" sizes="36x36" href="icons/android-chrome-36x36.png" /> <link rel="icon" type="image/x-icon" href="icons/favicon.ico" /> <meta name="msapplication-TileColor" content="#3f51b5"> <meta name="theme-color" content="#3f51b5">

2019-07-14 · 2 min · Duke Yin

Wordpress中简单的社交媒体meta SEO

<meta property="og:site_name" content="<?php bloginfo( 'name' ); ?>" /> <meta property="og:title" content="<?php if(!is_home()){the_title();echo '-';} bloginfo( 'name' ); ?>" /> <meta property="og:url" content="<?php if(is_home()){echo esc_url( home_url( '/' ) ); }else{echo esc_url( the_permalink() ); }; ?>" /> <meta property="og:type" content="website" /> <meta name="twitter:site" content="@<?php echo $dukeyin_options['acc_tw']; ?>" />   社交媒体meta是一种针对各种社交媒体的的信息提示,当网站被分享到社交媒体时,会作为标题、URL以及图像优先摘取,有利于网站的SEO,在不借助第三方插件的情况下,将这些meta信息放置在header中,有利于网站的seo。

2018-09-11 · 1 min · Duke Yin

Wordpress useful functions

1 全局添加图像链接参数 有时候调用Lightbox插件,需要在图片链接上加某些参数,已发布的文章也是,用以下代码添加data-lightbox=“lightbox”(或其他需要的参数) 来实现。 /** *Lightbox to image link globally */ add_filter('the_content', 'dukeyin_addlightbox'); function dukeyin_addlightbox($content) { global $post; $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replacement = '<a$1href=$2$3.$4$5 data-lightbox="lightbox" title="'.$post->post_title.'"$6>'; $content = preg_replace($pattern, $replacement, $content); return $content; } 另一种方式,修改单张图片,也修改相册的链接 <?php /** * Add data attributes for Fancybox */ // Gallery images function ccd_fancybox_gallery_attribute( $content, $id ) { // Restore title attribute $title = get_the_title( $id ); return str_replace('<a', '<a data-type="image" data-fancybox="gallery" title="' . esc_attr( $title ) . '" ', $content); } add_filter( 'wp_get_attachment_link', 'ccd_fancybox_gallery_attribute', 10, 4 ); // Single images function ccd_fancybox_image_attribute( $content ) { global $post; $pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replace = '<a$1href=$2$3.$4$5 data-type="image" data-fancybox="image">'; $content = preg_replace( $pattern, $replace, $content ); return $content; } add_filter( 'the_content', 'ccd_fancybox_image_attribute' ); ?>   ...

2018-08-14 · 4 min · Duke Yin

获取特色图像如果为空则获取第一张图

Wordpress主题制作过程中经常要获得特色图像的URL以用来裁切或者呈现,但是有时候日志中不包含特色图像,比较好的方法是建立一个方程获得文章内容的第一张特色图像。 获得第一张图的方程在网上有很多,但是缺点是每次必须要用if去判断,有特色图像如何,没有特色图像如何。 所以为何我们不将判断的工作直接放进方程里,让这个方程去获取特色图像,没有的话就调用第一张图呢? /** Get First image */ function get_first_image() { global $post, $posts; $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); if(empty($featured_img_url)){ $first_img = ''; ob_start(); ob_end_clean(); if($output = preg_match_all(’//i’, $post->post_content, $matches)){ $first_img = $matches [1] [0]; }else{ $first_img = ‘’; }; }else{ $first_img= $featured_img_url; } ...

2018-08-05 · 1 min · Duke Yin