Skip to content

Instantly share code, notes, and snippets.

@aisin
aisin / get_single_root_cat.php
Last active August 29, 2015 14:01
WordPress single.php 获取当前文章的分类的父级 ID 和名称
<?php
//获取ID
global $post;
$category = get_the_category($post->ID);
$cat_parent = get_category($category[0]->category_parent)->term_id;
if (!empty($cat_parent)) {
$cat_id = $cat_parent; //如果有父级分类,获取父级分类ID
@aisin
aisin / functions.php
Last active August 29, 2015 14:02
WordPress 修改摘要的默认字数
<?php
/**********************************************
**
**在主题文件夹下的functions.php中加入以下代码:
**
***********************************************/
//修改字数
@aisin
aisin / google_ip
Last active August 29, 2015 14:02
Google IP
203.208.48.151
203.208.46.176
203.208.46.147
203.208.46.148
203.208.46.212
203.208.46.158
203.208.46.180
203.208.46.198
203.208.46.200
203.208.41.150
@aisin
aisin / functions.php
Last active August 29, 2015 14:03
Replace Google Fonts&API with 360 in WordPress
<?php
// functions.php -- Theme
// 方法一:
if (!defined('ABSPATH')) exit;
class Replace_Google_Fonts
{
@aisin
aisin / gist:6710ca34376f45d3d334
Created July 16, 2014 03:36
WordPress getting post thumbnail URL
<?php
$domsxe = simplexml_load_string(get_the_post_thumbnail());
$thumbnailsrc = $domsxe->attributes()->src;
?>
@aisin
aisin / gist:719c296c8ab8dfde1f29
Created July 16, 2014 11:44
jQuery判断指定元素是否存在和删除数组中指定元素
/***********************************
*
* 判断指定元素是否存在
*
* *********************************/
var arr = ['a','b','c','d','e','f']
var str = 'b';
console.log( $.inArray(str , arr) );
//结果:
@aisin
aisin / header.php
Created August 20, 2014 03:46
WordPress 判断是否首页
<?php
/*
*
* 通常使用 is_home() 函数即可判断首页,但是有时候在首页不起作用
*
*/
if( is_home() || is_front_page() ) {
@aisin
aisin / functions.php
Created September 17, 2014 05:30
WordPress 获取文章内容里的首张图片和第一段,如果无图只显示第一段。
<?php
function get_con(){
global $post;
$content = get_the_content();
//获取内容的第一段
$str = wpautop( $content );
$str = substr( $str, 0, strpos( $str, '</p>' ) + 4 );
@aisin
aisin / note.php
Created October 31, 2014 01:26
PHP 字符串转数组
<?php
//explode用法:
$var = '10, 24, 29, 32, 56';
$ary = explode(",", $var);
print_r ( $ary ); // Array ( [0] => 10 [1] => 24 [2] => 29 [3] => 32 [4] => 56 )
@aisin
aisin / earth.js
Created February 10, 2015 08:20
The Earth
eval(z='p="<"+"pre>"/* ,.oq#+ ,._, */;for(y in n="zw24l6k\
4e3t4jnt4qj24xh2 x/* =<,m#F^ A W###q. */42kty24wrt413n243n\
9h243pdxt41csb yz/* #K q##H######Am */43iyb6k43pk7243nm\
r24".split(4)){/* dP cpq#q##########b, */for(a in t=pars\
eInt(n[y],36)+/* p##@###YG=[#######y */(e=x=r=[]))for\
(r=!r,i=0;t[a/* d#qg `*PWo##q#######D */]>i;i+=.05)wi\
th(Math)x-= /* aem1k.com Q###KWR#### W[ */.05,0>cos(o=\
new Date/1e3/* .Q#########Md#.###OP A@ , */+x/PI)&&(e[~\
~(32*sin(o)*/* , (W#####Xx######.P^ T % */sin(.5+y/7))\
+60] =-~ r);/* #y `^TqW####P###BP */for(x=0;122>\