functions.php 65.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
<?php 
require_once(TEMPLATEPATH . '/theme_setup.php');	
 
add_filter('home_url', 'lang_home_url', 1, 1);
function lang_home_url($result='', $show='') {
	global $wp_query;
      $get_lang = isset($wp_query->query_vars['prisna_translate_seo_request'])?urldecode($wp_query->query_vars['prisna_translate_seo_request']):'';
	  if ($get_lang!='') 	
		  $result = str_replace(".com/",".com/".$get_lang."/",$result);
	  else
		  return $result;
      return $result;
}
 
add_filter('redirect_canonical', 'cancel_redirect_canonical');    
function cancel_redirect_canonical($redirect_url)
{
    if( is_page()) return false;
    return $redirect_url;
}
function add_query_vars($aVars) {
    $aVars[] = 'prisna_translate_seo_request'; 
    return $aVars;
}
add_filter('query_vars', 'add_query_vars');
 
    function submitTrRequest($url, $regularParams)
    {
		$ch = curl_init ();
		// print_r($ch);
		curl_setopt ( $ch, CURLOPT_URL, $url );
		curl_setopt ( $ch, CURLOPT_POST, 1 );
		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, $regularParams );
		$response = curl_exec ( $ch );
		curl_close ( $ch );
		return json_decode($response,true);
    }
	
	
	
add_theme_support('post-thumbnails');
show_admin_bar(false);
 function tj_custom_post_type() {
    register_post_type( 'admin', tj_custom_post_type_args("admin"));
    register_post_type( 'ad_img', tj_custom_post_type_args("ad_img"));
    register_post_type( 'home', tj_custom_post_type_args("home"));
    register_post_type( 'transall', tj_custom_post_type_args("transall"));
    register_post_type( 'skype', tj_custom_post_type_args("skype"));
    register_post_type( 'qq', tj_custom_post_type_args("qq"));
    register_post_type( 'ww', tj_custom_post_type_args("ww"));
    register_post_type( 'pro_detail', tj_custom_post_type_args("pro_detail"));
    register_post_type( 'pro_shuxing', tj_custom_post_type_args("pro_shuxing"));
    register_post_type( 'xunpan', tj_custom_post_type_args("xunpan"));
    register_post_type( 'sitemap', tj_custom_post_type_args("sitemap"));
}
function tj_cutom_post_type_label_args($typeName){
    return $labels = array(
        'name' => $typeName,
        'singular_name' => $typeName,
        'add_new' => 'Add New',
        'add_new_item' => 'Add New '.$typeName,
        'edit_item' => 'Edit '.$typeName,
        'new_item' => 'New '.$typeName,
        'all_items' => 'All '.$typeName,
        'view_item' => 'View '.$typeName,
        'search_items' => 'Search '.$typeName,
        'not_found' =>  'No '.$typeName.' found',
        'not_found_in_trash' => 'No '.$typeName.' found in Trash', 
        'parent_item_colon' => '',
        'menu_name' => $typeName
    );
}
function tj_custom_post_type_args($typeName,$postType="post",$public=true,$queryable=true,$show_ui=true,$show_menu=true,$query_var=true,$has_archive = true, $hierarchical = false,$menu_position = null){
    return $args = array(
        'labels' => tj_cutom_post_type_label_args($typeName),
        'public' => $public,
        'publicly_queryable' => $queryable,
        'show_ui' => $show_ui, 
        'show_in_menu' => $show_menu, 
        'query_var' => $query_var,
        'rewrite' => array( 'slug' => strtolower($typeName)),
        'capability_type' => $postType,
        'has_archive' => $has_archive, 
        'hierarchical' => $hierarchical,
        'menu_position' => $menu_position,
        'supports' => array( 'title', 'thumbnail')
    );
}
/*************************************************------------------------------Article  
function custom_post_article() {
	$labels = array(
		'name'               => _x( 'Article', 'post type general name' ),
		'singular_name'      => _x( 'Article', 'post type singular name' ),
		'add_new'            => _x( 'Add New', 'book' ),
		'add_new_item'       => __( 'Add New article' ),
		'edit_item'          => __( 'Edit article' ),
		'new_item'           => __( 'New article' ),
		'all_items'          => __( 'All article' ),
		'view_item'          => __( 'View article' ),
		'search_items'       => __( 'Search article' ),
		'not_found'          => __( 'No article found' ),
		'not_found_in_trash' => __( 'No article found in the Trash' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'article'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail'),
		'has_archive'   => true,
	);
	register_post_type( 'article', $args );	
}
add_action( 'init', 'custom_post_article' );

 */
 /*************************************************------------------------------Product   */
function custom_post_guide() {
	$labels = array(
		'name'               => _x( 'Product Guide', 'post type general name' ),
		'singular_name'      => _x( 'Product Guide', 'post type singular name' ),
		'add_new'            => _x( 'Add New', 'book' ),
		'add_new_item'       => __( 'Add New Product Guide' ),
		'edit_item'          => __( 'Edit Product Guide' ),
		'new_item'           => __( 'New Product Guide' ),
		'all_items'          => __( 'All Product Guide' ),
		'view_item'          => __( 'View Product Guide' ),
		'search_items'       => __( 'Search Product Guide' ),
		'not_found'          => __( 'No Product Guide found' ),
		'not_found_in_trash' => __( 'No Product Guide found in the Trash' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Product Guide'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail'),
		'has_archive'   => true,
	);
	register_post_type( 'guide', $args );	
}
add_action( 'init', 'custom_post_guide' );

 
/*************************************************------------------------------VideoShow   */
function custom_post_vs() {
	$labels = array(
		'name'               => _x( 'Video Show', 'post type general name' ),
		'singular_name'      => _x( 'Video Show', 'post type singular name' ),
		'add_new'            => _x( 'Add New', 'book' ),
		'add_new_item'       => __( 'Add New vs' ),
		'edit_item'          => __( 'Edit vs' ),
		'new_item'           => __( 'New vs' ),
		'all_items'          => __( 'All vs' ),
		'view_item'          => __( 'View vs' ),
		'search_items'       => __( 'Search vs' ),
		'not_found'          => __( 'No vs found' ),
		'not_found_in_trash' => __( 'No vs found in the Trash' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'vs'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail'),
		'has_archive'   => true,
	);
	register_post_type( 'vs', $args );	
}
add_action( 'init', 'custom_post_vs' );


/*************************************************------------------------------help   */
function custom_post_help() {
	$labels = array(
		'name'               => _x( '相关页面', 'post type general name' ),
		'singular_name'      => _x( 'Help', 'post type singular name' ),
		'add_new'            => _x( '新建', 'book' ),
		'add_new_item'       => __( '新建 相关页面' ),
		'edit_item'          => __( '修改 相关页面' ),
		'new_item'           => __( '新建 相关页面' ),
		'all_items'          => __( '所有 相关页面' ),
		'view_item'          => __( '查看 相关页面' ),
		'search_items'       => __( '搜索 相关页面' ),
		'not_found'          => __( '无 相关页面 内容' ),
		'not_found_in_trash' => __( '无 相关页面 内容' ), 
		'parent_item_colon'  => '',
		'menu_name'          => '相关页面'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail'),
		'has_archive'   => true,
	);
	register_post_type( 'help', $args );	
}
add_action( 'init', 'custom_post_help' );
/*************************************************------------------------------news   */
function custom_post_news() {
	$labels = array(
		'name'               => _x( 'News', 'post type general name' ),
		'singular_name'      => _x( 'News', 'post type singular name' ),
		'add_new'            => _x( 'Add New', 'book' ),
		'add_new_item'       => __( 'Add New news' ),
		'edit_item'          => __( 'Edit news' ),
		'new_item'           => __( 'New news' ),
		'all_items'          => __( 'All news' ),
		'view_item'          => __( 'View news' ),
		'search_items'       => __( 'Search news' ),
		'not_found'          => __( 'No news found' ),
		'not_found_in_trash' => __( 'No news found in the Trash' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'News'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
		'has_archive'   => true,
	);
	register_post_type( 'news', $args );	
}
add_action( 'init', 'custom_post_news' );
//Custom Taxonomies (news Categories)
function taxonomies_news() {
	$labels = array(
		'name'              => _x( '新闻分类', 'taxonomy general name' ),
		'singular_name'     => _x( 'News Categories', 'taxonomy singular name' ),
		'search_items'      => __( '搜索新闻分类' ),
		'all_items'         => __( '新闻分类' ),
		'parent_item'       => __( '新闻分类' ),
		'parent_item_colon' => __( '新闻分类:' ),
		'edit_item'         => __( '新闻分类修改' ), 
		'update_item'       => __( '新闻分类更新' ),
		'add_new_item'      => __( '新增新闻分类' ),
		'new_item_name'     => __( '新新闻分类' ),
		'menu_name'         => __( '新闻分类' ),
	);
	$args = array(
		'labels' => $labels,
		'hierarchical' => true,
	);
	register_taxonomy( 'news_catalog', 'news', $args );
}
add_action( 'init', 'taxonomies_news', 0 );
/*************************************************------------------------------blog   
  function custom_post_blog() {
	$labels = array(
		'name'               => _x( 'Blog', 'post type general name' ),
		'singular_name'      => _x( 'Blog', 'post type singular name' ),
		'add_new'            => _x( '新建', 'book' ),
		'add_new_item'       => __( '新建 Blog' ),
		'edit_item'          => __( '修改 Blog' ),
		'new_item'           => __( '新建 Blog' ),
		'all_items'          => __( '所有 Blog' ),
		'view_item'          => __( '查看 Blog' ),
		'search_items'       => __( '搜索 Blog' ),
		'not_found'          => __( '无 Blog 内容' ),
		'not_found_in_trash' => __( '无 Blog 内容' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Blog'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail'),
		'has_archive'   => true,
	);
	register_post_type( 'blog', $args );	
}
add_action( 'init', 'custom_post_blog' );
function taxonomies_blog() {
	$labels = array(
		'name'              => _x( 'Blog分类', 'taxonomy general name' ),
		'singular_name'     => _x( 'Blog分类', 'taxonomy singular name' ),
		'search_items'      => __( '搜索Blog分类' ),
		'all_items'         => __( 'Blog分类' ),
		'parent_item'       => __( 'Blog分类' ),
		'parent_item_colon' => __( 'Blog分类:' ),
		'edit_item'         => __( 'Blog分类修改' ), 
		'update_item'       => __( 'Blog分类更新' ),
		'add_new_item'      => __( '新增Blog分类' ),
		'new_item_name'     => __( '新Blog分类' ),
		'menu_name'         => __( 'Blog分类' ),
	);
	$args = array(
		'labels' => $labels,
		'hierarchical' => true,
	);
	register_taxonomy( 'blog_catalog', 'blog', $args );
}
add_action( 'init', 'taxonomies_blog', 0 );
/*************************************************------------------------------video   
function custom_post_video() {
	$labels = array(
		'name'               => _x( 'Video', 'post type general name' ),
		'singular_name'      => _x( 'Video', 'post type singular name' ),
		'add_new'            => _x( 'Add New', 'book' ),
		'add_new_item'       => __( 'Add New video' ),
		'edit_item'          => __( 'Edit video' ),
		'new_item'           => __( 'New video' ),
		'all_items'          => __( 'All video' ),
		'view_item'          => __( 'View video' ),
		'search_items'       => __( 'Search video' ),
		'not_found'          => __( 'No video found' ),
		'not_found_in_trash' => __( 'No video found in the Trash' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Video'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
		'has_archive'   => true,
	);
	register_post_type( 'video', $args );	
}
add_action( 'init', 'custom_post_video' );
//Custom Taxonomies (video Categories)
function taxonomies_video() {
	$labels = array(
		'name'              => _x( 'Video分类', 'taxonomy general name' ),
		'singular_name'     => _x( 'Video Categories', 'taxonomy singular name' ),
		'search_items'      => __( '搜索Video分类' ),
		'all_items'         => __( 'Video分类' ),
		'parent_item'       => __( 'Video分类' ),
		'parent_item_colon' => __( 'Video分类:' ),
		'edit_item'         => __( 'Video分类修改' ), 
		'update_item'       => __( 'Video分类更新' ),
		'add_new_item'      => __( '新增Video分类' ),
		'new_item_name'     => __( '新Video分类' ),
		'menu_name'         => __( 'Video分类' ),
	);
	$args = array(
		'labels' => $labels,
		'hierarchical' => true,
	);
	register_taxonomy( 'video_catalog', 'video', $args );
}
add_action( 'init', 'taxonomies_video', 0 );
*/
/*************************************************------------------------------project   
function custom_post_project() {
	$labels = array(
		'name'               => _x( 'Project', 'post type general name' ),
		'singular_name'      => _x( 'Project', 'post type singular name' ),
		'add_new'            => _x( 'Add New', 'book' ),
		'add_new_item'       => __( 'Add New project' ),
		'edit_item'          => __( 'Edit project' ),
		'new_item'           => __( 'New project' ),
		'all_items'          => __( 'All project' ),
		'view_item'          => __( 'View project' ),
		'search_items'       => __( 'Search project' ),
		'not_found'          => __( 'No project found' ),
		'not_found_in_trash' => __( 'No project found in the Trash' ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Project'
	);
	$args = array(
		'labels'        => $labels,
		'description'   => 'Holds our product and product specific data',
		'public'        => true,
		'menu_position' => 10,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
		'has_archive'   => true,
	);
	register_post_type( 'project', $args );	
}
add_action( 'init', 'custom_post_project' );
//Custom Taxonomies (project Categories)
function taxonomies_project() {
	$labels = array(
		'name'              => _x( 'Project分类', 'taxonomy general name' ),
		'singular_name'     => _x( 'Project Categories', 'taxonomy singular name' ),
		'search_items'      => __( '搜索Project分类' ),
		'all_items'         => __( 'Project分类' ),
		'parent_item'       => __( 'Project分类' ),
		'parent_item_colon' => __( 'Project分类:' ),
		'edit_item'         => __( 'Project分类修改' ), 
		'update_item'       => __( 'Project分类更新' ),
		'add_new_item'      => __( '新增Project分类' ),
		'new_item_name'     => __( '新Project分类' ),
		'menu_name'         => __( 'Project分类' ),
	);
	$args = array(
		'labels' => $labels,
		'hierarchical' => true,
	);
	register_taxonomy( 'project_catalog', 'project', $args );
}
add_action( 'init', 'taxonomies_project', 0 );
/*************************************************
自定义字段结束
*************************************************/
//判断是否为机器人、爬虫
function checkrobot($useragent = ''){
	static $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
	static $kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
	$useragent = empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent;
	if(!strexists($useragent, 'http://') && preg_match("/($kw_browsers)/i", $useragent)) {
		return false;
	} elseif(preg_match("/($kw_spiders)/i", $useragent)) {
		return true;
	} else {
		return false;
	}
}
function strexists($haystack, $needle) {
	return !(strpos($haystack, $needle) === FALSE);
}
function email_address_login($username) {
$user = get_user_by_email($username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
function no_self_ping( &$links ) {
    $home = get_option( 'home' );
    foreach ( $links as $l => $link )
        if ( 0 === strpos( $link, $home ) ) unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
/*************************************************
菜单名称输出
*************************************************/
function get_menu_name_by_id($id){
    global $wpdb;
    $res = $wpdb->get_row("SELECT * FROM $wpdb->terms WHERE term_id = '{$id}'");
    if($res)  return $res->name;
    return false;
}
/**
只搜索文章的标题
 */
function __search_by_title_only( $search, &$wp_query )
{
	global $wpdb;
 
	if ( empty( $search ) )
        return $search; // skip processing - no search term in query
 
    $q = $wp_query->query_vars;    
    $n = ! empty( $q['exact'] ) ? '' : '%';
 
    $search =
    $searchand = '';
 
    foreach ( (array) $q['search_terms'] as $term ) {
    	$term = esc_sql( like_escape( $term ) );
    	$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
    	$searchand = ' AND ';
    }
 
    if ( ! empty( $search ) ) {
    	$search = " AND ({$search}) ";
    	if ( ! is_user_logged_in() )
    		$search .= " AND ($wpdb->posts.post_password = '') ";
    }
 
    return $search;
}
add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
function get_referrer_category() {
    global $posts;
    if ( ! $referrer_url = get_referrer_url( false ) )
        return false;
    foreach ( get_the_category( $posts[0]->ID ) as $cat ) {
        $cat_link = get_category_link( $cat->term_id );
        if ( false !== strpos( $referrer_url, $cat_link ) )
            return $cat;
    }
    foreach ( get_the_tags( $posts[0]->ID ) as $tag ) {
        $tag_link = get_tag_link( $tag->term_id );
        if ( false !== strpos( $referrer_url, $tag_link ) )
            return $tag;
    }
    foreach ( get_the_terms( $posts[0]->ID, 'color' ) as $term ) {
        $term_link = get_term_link( $term->term_id );
        if ( false !== strpos( $referrer_url, $term_link ) )
            return $term;
    }
    return false;
}
add_filter( 'post_thumbnail_html', 'remove_wps_width', 10 );
add_filter( 'image_send_to_editor', 'remove_wps_width', 10 );
  
function remove_wps_width( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}
add_action( 'init', 'tj_custom_post_type' );
function get_category_root_id($cat)   
{   
$this_category = get_category($cat); // 取得当前分类   
while($this_category->category_parent) // 若当前分类有上级分类时,循环   
{   
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬)   
}   
return $this_category->term_id; // 返回根分类的id号   
} 
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
  if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
    $translations = 'off';
  }
  return $translations;
}
remove_action('pre_post_update','wp_save_post_revision' );
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
	return is_array($var) ? array_intersect($var, array('nav-current','current-post-ancestor','current-menu-ancestor','current-menu-parent')) : '';
}
add_action('login_head', 'my_custom_login_logo');
function my_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
    </style>';
}
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action( 'wp_head', 'locale_stylesheet' );
remove_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 );
remove_action( 'wp_head', 'noindex', 1 );
remove_action( 'wp_head', 'wp_print_styles', 8 );
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'rel_canonical' );
remove_action( 'wp_footer', 'wp_print_footer_scripts' );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
remove_action( 'wp_head', 'index_rel_link' ); // Removes the index link   
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Removes the prev link   
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Removes the start link   
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Removes the relational links for the posts adjacent to the current post. 
add_action('widgets_init', 'my_remove_recent_comments_style');
function wpdx_change_role_name() {
    global $wp_roles;
 
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
    $wp_roles->roles['administrator']['name'] = '超级管理员';
    $wp_roles->role_names['administrator'] = '超级管理员';           
    $wp_roles->roles['editor']['name'] = '网站编辑';
    $wp_roles->role_names['editor'] = '网站编辑';                    
}
add_action('init', 'wpdx_change_role_name');
remove_role( 'author' );
remove_role( 'sc_chat_op' );
remove_role( 'pending' );
remove_role( 'subscriber' );
remove_role( 'contributor' );
remove_role( 'kefu' );
remove_role( 'yewu' );
function my_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
}
if ( function_exists('register_sidebar') ) {
	register_sidebar( array(
		'name' => 'inquiry',
		'id' => 'inquiry',
		) );
}
if ( function_exists('register_sidebar') ) {
	register_sidebar( array(
		'name' => 'newsletter',
		'id' => 'newsletter',
		) );
}
function cut_str($sourcestr,$cutlength)
{
	$returnstr='';
	$i=0;
	$n=0;
	$str_length=strlen($sourcestr);
	while (($n<$cutlength) and ($i<=$str_length))
	{
		$temp_str=substr($sourcestr,$i,1);
		$ascnum=Ord($temp_str);
		if ($ascnum>=224)
		{
			$returnstr=$returnstr.substr($sourcestr,$i,3);
			$i=$i+3;
			$n++;
		}
		elseif ($ascnum>=192)
		{
			$returnstr=$returnstr.substr($sourcestr,$i,2);
			$i=$i+2;
			$n++;
		}
		elseif ($ascnum>=65 && $ascnum<=90)
		{
			$returnstr=$returnstr.substr($sourcestr,$i,1);
			$i=$i+1;
			$n++;
		}
		else
		{
			$returnstr=$returnstr.substr($sourcestr,$i,1);
			$i=$i+1;
			$n=$n+0.5;
		}
	}
	if (mb_strlen($sourcestr)>$cutlength){
		$returnstr = $returnstr . "…";
	}
	return $returnstr;
}
function get_the_thumb($id) {
	$post=get_post($id);
	$first_img = '';
	$first_img = get_post_meta($post->ID, "zuluo_thumbnail", true);
	if ($first_img != '') return $first_img;
	if ( has_post_thumbnail($id) ) {
		$imgstr = explode('src="', get_the_post_thumbnail($id,'thumbnail'));
		$img = explode('"', $imgstr[1]);
		$first_img = $img[0];
		return $first_img;
	} 
	else {
		$args = array(
			'post_type' => 'attachment',
			'post_mime_type'	=> 'image',
			'numberposts'		=> -1,
			'post_status'		=> null,
			'post_parent'		=> $id,
			'orderby'			=> 'post_date',
			'order'				=> 'DESC'
		);
		$attachments = get_posts( $args );
		if ( $attachments ) {
			foreach ( $attachments as $attachment ) {
				$imgstr = explode('src="', wp_get_attachment_image( $attachment->ID, 'thumbnail' ));
				$img = explode('"', $imgstr[1]);
				$first_img = $img[0];
				return $first_img;
			}
		}
		else {
			$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); 
			if ( $matches[1] )
				$first_img = $matches[1][0];
			if ($first_img=='') {
				$first_img = get_template_directory_uri() . "/images/thumb/". rand(1,3) .".jpg";
			}
			return $first_img;
		}
	}	
}
function my_profile( $contactmethods ) {
	unset($contactmethods['aim']);   
	unset($contactmethods['yim']);
	unset($contactmethods['jabber']);
	return $contactmethods;
}
add_filter('user_contactmethods','my_profile');		
function zuluo_pagination($range = 11){
	global $paged, $wp_query;
	if ( !$max_page ) {
		$max_page = $wp_query->max_num_pages;
	}
	if($max_page > 1){
		if(!$paged){
			$paged = 1;
		}
		if($paged != 1){
			echo "<a href='" . get_pagenum_link(1) . "' title='First'>First</a>";
		}
		previous_posts_link('Previous');
		if($max_page > $range){
			if($paged < $range){
				for($i = 1; $i <= $range; $i++){
					echo "<a href='" . get_pagenum_link($i) ."'";
					if($i==$paged)
						echo " class='current'";
					echo ">$i</a>";
				}
			}
			elseif($paged >= ($max_page - ceil(($range/2)))){
				for($i = $max_page - $range + 1; $i <= $max_page; $i++){
					echo "<a href='" . get_pagenum_link($i) ."'";
					if($i==$paged)
						echo " class='current'";
					echo ">$i</a>";
				}
			}
			elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
				for($i = ($paged - ceil($range/2)) + 1; $i < ($paged + ceil(($range/2))); $i++){
					echo "<a href='" . get_pagenum_link($i) ."'";
					if($i==$paged)
						echo " class='current'";
					echo ">$i</a>";
				}
			}
		}
		else{
			for($i = 1; $i <= $max_page; $i++){
				echo "<a href='" . get_pagenum_link($i) ."'";
				if($i==$paged)
					echo " class='current'";
				echo ">$i</a>";
			}
		}
		next_posts_link('Next');
		if($paged != $max_page){
			echo "<a href='" . get_pagenum_link($max_page) . "' title='Last'>Last</a>";
		}
	}
}
function mypo_parse_query_useronly( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
        if ( !current_user_can( 'manage_options' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}
 
add_filter('parse_query', 'mypo_parse_query_useronly' );
  // ad_img调用方案
function get_the_field($field_name,$post_id=-1){
    if($post_id < 0){  //not id input
        global $eric_g_id;
        if($eric_g_id){
            $post_id = $eric_g_id;
        }else{
            global $wpdb;
            $res = $wpdb->get_row("SELECT ID FROM $wpdb->posts  WHERE post_status='publish' and post_type='ad_img' ORDER BY post_date DESC LIMIT 0,1");
            if(!$res) return false;
            $post_id = $res->ID;
            $eric_g_id = $post_id;
        }
    }
    the_field($field_name, $post_id);
}
function get_get_field($field_name,$post_id=-1){
    if($post_id < 0){  //not id input
        global $eric_g_id;
        if($eric_g_id){
            $post_id = $eric_g_id;
        }else{
            global $wpdb;
            $res = $wpdb->get_row("SELECT ID FROM $wpdb->posts  WHERE post_status='publish' and post_type='ad_img' ORDER BY post_date DESC LIMIT 0,1");
            if(!$res) return false;
            $post_id = $res->ID;
            $eric_g_id = $post_id;
        }
    }
    return get_field($field_name, $post_id);
}
function id_reset(){
     global $eric_g_id;
     $eric_g_id = null;
}
function keep_id_continuous(){
  global $wpdb;
  // 删掉自动草稿和修订版
  $wpdb->query("DELETE FROM `$wpdb->posts` WHERE `post_status` = 'auto-draft' OR `post_type` = 'revision'");
  // 自增值小于现有最大ID,MySQL会自动设置正确的自增值
  $wpdb->query("ALTER TABLE `$wpdb->posts` AUTO_INCREMENT = 1");  
}
add_filter( 'load-post-new.php', 'keep_id_continuous' );
add_filter( 'load-media-new.php', 'keep_id_continuous' );
add_filter( 'load-nav-menus.php', 'keep_id_continuous' );
function custom_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'custom_excerpt_more');
function custom_excerpt_length($length) {
return 70;
}
add_filter('excerpt_length', 'custom_excerpt_length');
class zuluo_Catpost_Widget extends WP_Widget {
	function zuluo_Catpost_Widget() {
		$widget_ops = array('description' => '分类文章列表', 'description' => '分类文章列表');
		$control_ops = array('width' => 200, 'height' => 300);
		parent::WP_Widget(false,$name='分类文章列表(zuluo)',$widget_ops,$control_ops); 
	}
	function form($instance) {
		$catposts = isset($instance['catposts']) ? esc_attr($instance['catposts']) : '1';
		$number = isset($instance['number']) ? absint($instance['number']) : 8;
?>
	<p><label for="<?php echo $this->get_field_id('catposts'); ?>">分类ID:</label><br>
		<input id="<?php echo $this->get_field_id('catposts'); ?>" name="<?php echo $this->get_field_name('catposts'); ?>" type="text" value="<?php echo $catposts; ?>" size="35" /></p>
	<p><label for="<?php echo $this->get_field_id('number'); ?>">文章列表数目:</label><br>
		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
<?php
    }
    function update($new_instance, $old_instance) { // 更新保存
	    return $new_instance;
    }
	function widget($args, $instance) { // 输出显示在页面上
		extract( $args );
		if ( empty( $instance['catposts'] ) || ! $catposts = esc_attr( $instance['catposts'] ) )
 			$catposts = '1';
		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
 			$number = 8;
		//按照列表输入分类标题和副标题链接
		$sidebar_cats1 = explode(',',$catposts);
		$i = 1;
		foreach( $sidebar_cats1 as $catid1 ) {
			$title = get_the_category_by_ID($catid1);
			echo '<li>';
			echo '<h2>'. $title. '<a class="more" href="'.get_category_link($catid1).'">'.'</a></h2>'; 
?>
			<ul>
		<?php
			$popular = new WP_Query( array(
				'cat' => $catid1,
				'showposts' => $number,
				'orderby' => 'date',
				'order' => 'ASC',
			) );	
			while ($popular->have_posts()) : $popular->the_post();
		?>
				<li><a href="<?php echo get_permalink(get_the_ID()); ?>"><?php echo cut_str(get_the_title(),14); ?></a></li>
		<?php	
			endwhile;
				// Reset Query
			wp_reset_query();
		?>
			</ul> 
<?php	echo '</li>'; ?>
<?php
		}
    }
}
register_widget('zuluo_Catpost_Widget');
function cmp_breadcrumbs() {
	$delimiter = '</li><li>'; // 分隔符
	$before = '<a href="#">'; // 在当前链接前插入
	$after = '</a>'; // 在当前链接后插入
	if ( !is_home() && !is_front_page() || is_paged() ) {
		echo ''.__( '' , 'cmp' );
		global $post;
		$homeLink = home_url();
		echo ' <a itemprop="breadcrumb" href="' . $homeLink . '">' . __( 'Home' , 'cmp' ) . '</a>' . $delimiter . ' ';
		if ( is_category() ) { // 分类 存档
			global $wp_query;
			$cat_obj = $wp_query->get_queried_object();
			$thisCat = $cat_obj->term_id;
			$thisCat = get_category($thisCat);
			$parentCat = get_category($thisCat->parent);
			if ($thisCat->parent != 0){
				$cat_code = get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ');
				echo $cat_code = str_replace ('<a','<a itemprop="breadcrumb"', $cat_code );
			}
			echo $before . '' . single_cat_title('', false) . '' . $after;
		} elseif ( is_day() ) { // 天 存档
			echo '<a itemprop="breadcrumb" href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
			echo '<a itemprop="breadcrumb"  href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
			echo $before . get_the_time('d') . $after;
		} elseif ( is_month() ) { // 月 存档
			echo '<a itemprop="breadcrumb" href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
			echo $before . get_the_time('F') . $after;
		} elseif ( is_year() ) { // 年 存档
			echo $before . get_the_time('Y') . $after;
		} elseif ( is_single() && !is_attachment() ) { // 文章
			if ( get_post_type() != 'post' ) { // 自定义文章类型
				$post_type = get_post_type_object(get_post_type());
				$slug = $post_type->rewrite;
				echo '<a itemprop="breadcrumb" href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
				echo $before . get_the_title() . $after;
			} else { // 文章 post
				$cat = get_the_category(); 
              	$flg = 0;
				foreach($cat as $kk=>$vv){
                	$rrrr = get_category_children($vv->term_id);
                  	if(!$rrrr){
                    	$cat_t = $cat[$kk];
                      	$flg=1;
                    }
                }
              	if($flg == 0){
                	$cat = $cat[0];
                }else{
                	$cat = $cat_t;
                }
				$cat_code = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
              	$cat_code =  substr($cat_code,0,strlen($cat_code)-5); 
				echo $cat_code = str_replace ('<a','<a itemprop="breadcrumb"', $cat_code );
			}
		} elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) {
			$post_type = get_post_type_object(get_post_type());
			echo $before . $post_type->labels->singular_name . $after;
		} elseif ( is_attachment() ) { // 附件
			$parent = get_post($post->post_parent);
			$cat = get_the_category($parent->ID); $cat = $cat[0];
			echo '<a itemprop="breadcrumb" href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
			echo $before . get_the_title() . $after;
		} elseif ( is_page() && !$post->post_parent ) { // 页面
			echo $before . get_the_title() . $after;
		} elseif ( is_page() && $post->post_parent ) { // 父级页面
			$parent_id  = $post->post_parent;
			$breadcrumbs = array();
			while ($parent_id) {
				$page = get_page($parent_id);
				$breadcrumbs[] = '<a itemprop="breadcrumb" href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
				$parent_id  = $page->post_parent;
			}
			$breadcrumbs = array_reverse($breadcrumbs);
			foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
			echo $before . get_the_title() . $after;
		} elseif ( is_search() ) { // 搜索结果
			echo $before ;
			printf( __( 'Search Results for: %s', 'cmp' ),  get_search_query() );
			echo  $after;
		} elseif ( is_tag() ) { //标签 存档
			echo $before ;
			printf( __( 'Tag Archives: %s', 'cmp' ), single_tag_title( '', false ) );
			echo  $after;
		} elseif ( is_author() ) { // 作者存档
			global $author;
			$userdata = get_userdata($author);
			echo $before ;
			printf( __( 'Author Archives: %s', 'cmp' ),  $userdata->display_name );
			echo  $after;
		} elseif ( is_404() ) { // 404 页面
			echo $before;
			_e( 'Not Found', 'cmp' );
			echo  $after;
		}
		
		echo '';
	}
}
function af_titledespacer($title) {
return trim($title);
}
add_filter('wp_title', 'af_titledespacer');
$keywords = substr($keywords,0,-2);
class RRHE {
	// Register the column - Registered
	public static function registerdate($columns) {
		$columns['registerdate'] = __('注册时间', 'registerdate');
		return $columns;
	}
 
	// Display the column content
	public static function registerdate_columns( $value, $column_name, $user_id ) {
		if ( 'registerdate' != $column_name )
			return $value;
		$user = get_userdata( $user_id );
		$registerdate = get_date_from_gmt($user->user_registered);
		return $registerdate;
	}
 
	public static function registerdate_column_sortable($columns) {
		$custom = array(
		  // meta column id => sortby value used in query
			'registerdate'    => 'registered',
			);
		return wp_parse_args($custom, $columns);
	}
 
	public static function registerdate_column_orderby( $vars ) {
		if ( isset( $vars['orderby'] ) && 'registerdate' == $vars['orderby'] ) {
			$vars = array_merge( $vars, array(
				'meta_key' => 'registerdate',
				'orderby' => 'meta_value'
				) );
		}
		return $vars;
	}
 
}
 
// Actions
add_filter( 'manage_users_columns', array('RRHE','registerdate'));
add_action( 'manage_users_custom_column',  array('RRHE','registerdate_columns'), 15, 3);
add_filter( 'manage_users_sortable_columns', array('RRHE','registerdate_column_sortable') );
add_filter( 'request', array('RRHE','registerdate_column_orderby') );
class zuluo_Catlist_Widget extends WP_Widget {
	function zuluo_Catlist_Widget() {
		$widget_ops = array('description' => '分类标题列表', 'description' => '分类标题列表');
		$control_ops = array('width' => 200, 'height' => 300);
		parent::WP_Widget(false,$name='分类标题列表(zuluo)',$widget_ops,$control_ops); 
	}
	function form($instance) {
		$catparent = isset($instance['catparent']) ? esc_attr($instance['catparent']) : '1';
?>
	<p><label for="<?php echo $this->get_field_id('catparent'); ?>">父分类ID:</label><br>
		<input id="<?php echo $this->get_field_id('catparent'); ?>" name="<?php echo $this->get_field_name('catparent'); ?>" type="text" value="<?php echo $catparent; ?>" size="35" /></p>
<?php
    }
    function update($new_instance, $old_instance) { // 更新保存
	    return $new_instance;
    }
	function widget($args, $instance) { // 输出显示在页面上
		extract( $args );
		if ( empty( $instance['catparent'] ) || ! $catparent = esc_attr( $instance['catparent'] ) )
 			$catparent = '1';
		//显示父分类标题和子分类列表
		$title = get_the_category_by_ID($catparent);
		$titlestr = '<li>';
		$titlestr .= '<h2>'. $title; 
		$titlestr .= '<a class="more" href="'.get_category_link($catparent).'">'.'</a>'; 
		$titlestr .= '</h2><ul>';
		echo $titlestr;
		//$variable = wp_list_categories( array( 
		wp_list_categories( array( 
			'child_of' => $catparent,
			'orderby'	=> 'slug',
			'order'		=> 'ASC',
			'title_li' => '',
			'hide_empty' =>	0,
			'depth' =>	4,
			'hierarchical' => true,
			'current_category' => 0,
			'show_option_none' =>''
			//'echo'	=> 0
		) );
		//echo preg_replace('/title=\"(.*?)\"/','',$variable);
		echo '</ul>';
		echo '</li>'; 
    }
}
register_widget('zuluo_Catlist_Widget');
class zuluo_Cattree_Widget extends WP_Widget {
	function zuluo_Cattree_Widget() {
		$widget_ops = array('description' => '分类目录树', 'description' => '分类目录树');
		$control_ops = array('width' => 200, 'height' => 300);
		parent::WP_Widget(false,$name='分类目录树(zuluo)',$widget_ops,$control_ops); 
	}
	function form($instance) {
		$catparent = isset($instance['catparent']) ? esc_attr($instance['catparent']) : '1';
?>
	<p><label for="<?php echo $this->get_field_id('catparent'); ?>">父分类ID:</label><br>
		<input id="<?php echo $this->get_field_id('catparent'); ?>" name="<?php echo $this->get_field_name('catparent'); ?>" type="text" value="<?php echo $catparent; ?>" size="35" /></p>
<?php
    }
    function update($new_instance, $old_instance) { // 更新保存
	    return $new_instance;
    }
	function widget($args, $instance) { // 输出显示在页面上
		extract( $args );
		if ( empty( $instance['catparent'] ) || ! $catparent = esc_attr( $instance['catparent'] ) )
 			$catparent = '1';
		//显示父分类标题和子分类列表
		$title = get_the_category_by_ID($catparent);
		$titlestr = '<li class="cattree">';
		$titlestr .= '<h2>'. $title;
		$titlestr .= '<a class="more" href="'.get_category_link($catparent).'">'.'</a>'; 
		$titlestr .= '</h2><ul>';
		echo $titlestr;
		//$variable = wp_list_categories( array( 
		wp_list_categories( array( 
			'child_of' => $catparent,
			'orderby'	=> 'slug',
			'order'		=> 'ASC',
			'title_li' => '',
			'hide_empty' =>	0,
			'depth' =>	4,
			'hierarchical' => true,
			'current_category' => 0,
			'show_option_none' =>''
			//'echo'	=> 0
		) );
		//echo preg_replace('/title=\"(.*?)\"/','',$variable);
		echo '</ul>';
		echo '</li>'; 
    }
}
register_widget('zuluo_Cattree_Widget');
add_filter( 'manage_media_columns', 'wpdaxue_media_column' );
function wpdaxue_media_column( $columns ) {
	$columns["media_url"] = "URL";
	return $columns;
}
add_action( 'manage_media_custom_column', 'wpdaxue_media_value', 10, 2 );
function wpdaxue_media_value( $column_name, $id ) {
	if ( $column_name == "media_url" ) echo '<input type="text" style="width:100%;" onclick="jQuery(this).select();" value="'. wp_get_attachment_url( $id ). '" />';
}
		function wt_get_category_count($input = '') {
    global $wpdb;
    if($input == '') {
        $category = get_the_category();
        return $category[0]->category_count;
    }
    elseif(is_numeric($input)) {
        $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
        return $wpdb->get_var($SQL);
    }
    else {
        $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
        return $wpdb->get_var($SQL);
    }
}
		function wt_get_category_count_g($input = '') {
    global $wpdb;
    if($input == '') {
        $category = get_the_category();
        return $category[2]->category_count;
    }
    elseif(is_numeric($input)) {
        $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
        return $wpdb->get_var($SQL);
    }
    else {
        $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
        return $wpdb->get_var($SQL);
    }
}
/**
 * 自动为文章标签添加该标签的链接
 */
$match_num_from = 1;  // 一个标签在文章中出现少于多少次不添加链接
$match_num_to = 2; // 一篇文章中同一个标签添加几次链接
add_filter('the_content','tag_link',1);
//按长度排序
function tag_sort($a, $b){
	if ( $a->name == $b->name ) return 0;
	return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
//为符合条件的标签添加链接
function tag_link($content){
	global $match_num_from,$match_num_to;
	$posttags = get_the_tags();
	if ($posttags) {
		usort($posttags, "tag_sort");
		foreach($posttags as $tag) {
			$link = get_tag_link($tag->term_id);
			$keyword = $tag->name;
			//链接的代码
			$cleankeyword = stripslashes($keyword);
			$url = "<a href=\"$link\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('View all posts in %s'))."\"";
			$url .= ' target="_blank"';
			$url .= ">".addcslashes($cleankeyword, '$')."</a>";
			$limit = rand($match_num_from,$match_num_to);
			//不链接的代码
			$content = preg_replace( '|(<a[^>]+>)(.*)('.$ex_word.')(.*)(</a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
			$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
			$cleankeyword = preg_quote($cleankeyword,'\'');
			$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
			$content = preg_replace($regEx,$url,$content,$limit);
			$content = str_replace( '%&&&&&%', stripslashes($ex_word), $content);
		}
	}
	return $content;
}
//-------------------------------------------------------------------------------------------分类/标签等存档页也能置顶文章
function curPageURL()
{
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on")
    {
        $pageURL .= "s";
    }
    $pageURL .= "://";
    $this_page = $_SERVER["REQUEST_URI"];   
    // 只取 ? 前面的内容
    if (strpos($this_page, "?") !== false)
        $this_page = reset(explode("?", $this_page));
 
    if ($_SERVER["SERVER_PORT"] != "80")
    {
        $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $this_page;
    }
    else
    {
        $pageURL .= $_SERVER["SERVER_NAME"] . $this_page;
    }
    return $pageURL;
}
add_filter('the_posts',  'putStickyOnTop' );
function putStickyOnTop( $posts ) {
  if(is_home() || !is_main_query() || !is_archive())
    return $posts;
 
  global $wp_query;
 
  $sticky_posts = get_option('sticky_posts');
 
  if ( $wp_query->query_vars['paged'] <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !get_query_var('ignore_sticky_posts') ) {        $stickies1 = get_posts( array( 'post__in' => $sticky_posts ) );
    foreach ( $stickies1 as $sticky_post1 ) {
      if($wp_query->is_category == 1 && !has_category($wp_query->query_vars['cat'], $sticky_post1->ID)) {
        $offset1 = array_search($sticky_post1->ID, $sticky_posts);
        unset( $sticky_posts[$offset1] );
      }
      if($wp_query->is_tag == 1 && has_tag($wp_query->query_vars['tag'], $sticky_post1->ID)) {
        $offset1 = array_search($sticky_post1->ID, $sticky_posts);
        unset( $sticky_posts[$offset1] );
      }
      if($wp_query->is_year == 1 && date_i18n('Y', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) {
        $offset1 = array_search($sticky_post1->ID, $sticky_posts);
        unset( $sticky_posts[$offset1] );
      }
      if($wp_query->is_month == 1 && date_i18n('Ym', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) {
        $offset1 = array_search($sticky_post1->ID, $sticky_posts);
        unset( $sticky_posts[$offset1] );
      }
      if($wp_query->is_day == 1 && date_i18n('Ymd', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) {
        $offset1 = array_search($sticky_post1->ID, $sticky_posts);
        unset( $sticky_posts[$offset1] );
      }
      if($wp_query->is_author == 1 && $sticky_post1->post_author != $wp_query->query_vars['author']) {
        $offset1 = array_search($sticky_post1->ID, $sticky_posts);
        unset( $sticky_posts[$offset1] );
      }
    }
 
    $num_posts = count($posts);
    $sticky_offset = 0;
    // Loop over posts and relocate stickies to the front.
    for ( $i = 0; $i < $num_posts; $i++ ) {
      if ( in_array($posts[$i]->ID, $sticky_posts) ) {
        $sticky_post = $posts[$i];
        // Remove sticky from current position
        array_splice($posts, $i, 1);
        // Move to front, after other stickies
        array_splice($posts, $sticky_offset, 0, array($sticky_post));
        // Increment the sticky offset. The next sticky will be placed at this offset.
        $sticky_offset++;
        // Remove post from sticky posts array
        $offset = array_search($sticky_post->ID, $sticky_posts);
        unset( $sticky_posts[$offset] );
      }
    }
 
    // If any posts have been excluded specifically, Ignore those that are sticky.
    if ( !empty($sticky_posts) && !empty($wp_query->query_vars['post__not_in'] ) )
      $sticky_posts = array_diff($sticky_posts, $wp_query->query_vars['post__not_in']);
 
    // Fetch sticky posts that weren't in the query results
    if ( !empty($sticky_posts) ) {
      $stickies = get_posts( array(
        'post__in' => $sticky_posts,
        'post_type' => $wp_query->query_vars['post_type'],
        'post_status' => 'publish',
        'nopaging' => true
      ) );
 
      foreach ( $stickies as $sticky_post ) {
        array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) );
        $sticky_offset++;
      }
    }
  }
 
  return $posts;
}
add_filter( 'flash_uploader', 'disable_flash_uploader', 7 ); 
function izt_pagenavi($range = 5){  
    global $paged, $wp_query;  
    if ( !$max_page ) {$max_page = $wp_query->max_num_pages;}  
    if($max_page > 1){
		echo '';
		if(!$paged){$paged = 1;}  
        if($paged != 1){echo "<a href='" . get_pagenum_link(1) . "' class='extend' title='The First Page'><<</a>";}  
        previous_posts_link(' < Previous ');  
        if($max_page > $range){  
            if($paged < $range){for($i = 1; $i <= ($range + 1); $i++){echo "<a href='" . get_pagenum_link($i) ."'";  
                if($i==$paged)echo " class='current'";echo ">$i</a>";}}  
            elseif($paged >= ($max_page - ceil(($range/2)))){  
                for($i = $max_page - $range; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";  
                    if($i==$paged)echo " class='current'";echo ">$i</a>";}}  
            elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){  
                for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){echo "<a href='" . get_pagenum_link  
  
($i) ."'";if($i==$paged) echo " class='current'";echo ">$i</a>";}}}  
        else{for($i = 1; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";  
            if($i==$paged)echo " class='current'";echo ">$i</a>";}}  
        next_posts_link(' Next > ');  
        if($paged != $max_page){echo "<a href='" . get_pagenum_link($max_page) . "' class='extend' title='The Last Page'>>></a> <span class='current2'>Page ".$paged." / ".$max_page."</span>";}}  
}  
if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
// for post and page
add_theme_support('post-thumbnails', array( 'post', 'page' ) );
function fb_AddThumbColumn($cols) {
$cols['thumbnail'] = __('Thumbnail');
return $cols;
}
function fb_AddThumbValue($column_name, $post_id) {
$width = (int) 50;
if ( 'thumbnail' == $column_name ) {
// thumbnail of WP 2.9
$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
// image from gallery
$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ($thumbnail_id)
$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
elseif ($attachments) {
foreach ( $attachments as $attachment_id => $attachment ) {
$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
}
}
if ( isset($thumb) && $thumb ) {
echo $thumb;
} else {
echo __('None');
}
}
}
// for posts
add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
// for pages
add_filter( 'manage_pages_columns', 'fb_AddThumbColumn' );
add_action( 'manage_pages_custom_column', 'fb_AddThumbValue', 10, 2 );
}
// Return the total amount of items in the shopping cart
function get_myeshop_cart_itemcount(){
	global $blog_id;
	$total_items_in_cart = 0;
	if(isset($_SESSION['eshopcart'.$blog_id])) {
		$item_array = $_SESSION['eshopcart'.$blog_id];
		
		foreach($item_array as $item) {
			$total_items_in_cart = $total_items_in_cart + $item['qty'];
		}
	}
	return $item_array;
}
function reset_password_message( $message, $key ) {
	if ( strpos($_POST['user_login'], '@') ) {
		$user_data = get_user_by('email', trim($_POST['user_login']));
	} else {
		$login = trim($_POST['user_login']);
		$user_data = get_user_by('login', $login);
	}
	$user_login = $user_data->user_login;
	$msg = __('密码重设:'). "\r\n\r\n";
	$msg .= network_site_url() . "\r\n\r\n";
	$msg .= sprintf(__('用户名: %s'), $user_login) . "\r\n\r\n";
	$msg .= __('若这不是您本人要求的,或不需要修改密码,请忽略本邮件,密码不变。') . "\r\n\r\n";
	$msg .= __('要重置您的密码,请打开下面的链接:'). "\r\n\r\n";
	$msg .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') ;
	return $msg;
}
add_filter('retrieve_password_message', reset_password_message, null, 2);
function display_my_cart_items() {
	$item = "";
	$cart_item_count = get_myeshop_cart_itemcount();
	if ($cart_item_count >0){
		$total = $sub_total=0;
		foreach($cart_item_count as $itm){			
			$item .='<div class="head-cartlist">
                  <dl>
                     <dt>'.$itm["pname"].'</dt>
                     <dd class="num">Qty: '.$itm["qty"].'</dd>
                     <dd class="price">'.get_currency_symbol().' '.get_currency_price($itm["price"]).'</dd>
                  </dl></div>
               ';
			   $total = $total+$itm["qty"];
			   $sub_total = $sub_total+$itm["price"];
			   $sub_total = get_currency_price($sub_total);
			}
			$item .='<div class="head-cartlist"><dl style="text-align: right;">Total:<span style="margin-right:20px;">'.$total.'</span>Sub-Total : '.get_currency_symbol().' '.$sub_total.'</dl>
               </div>';
		}else{
			$item ='<div class="head-cartlist">
                  <dl>
                     You have no items in your Shopping Cart!
                  </dl>
               </div>';
			};
	echo $item;
}
function display_my_cart_items_no() {
	$item = "";
	$cart_item_count = get_myeshop_cart_itemcount();
	if ($cart_item_count >0){
		$total = $sub_total=0;
		foreach($cart_item_count as $itm){			
			$item .='';
			   $total = $total+$itm["qty"];
			   $sub_total = $sub_total+$itm["price"];
			}
			$item .=$total;
		}else{
			$item ='0';
			
			};
	echo $item;
}
function display_my_cart_items_price() {
	$item = "";
	$cart_item_count = get_myeshop_cart_itemcount();
	if ($cart_item_count >0){
		$total = $sub_total=0;
		foreach($cart_item_count as $itm){			
			$item .='';
			   $total = $total+$itm["qty"];
			   $sub_total = $sub_total+$itm["price"];
			}
			$item .=$sub_total;
		}else{
			$item ='0.00';
			
			};
	echo $item;
}	
	function Reviews_num(){
		global $wpdb;
		$id = get_post()->ID;  
		//var_dump(the_ID());	
		echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments where comment_post_ID =".$id);
	
		}
		
function catch_that_image() { 
 global $post, $posts; 
 $first_img = ''; 
 ob_start(); 
 ob_end_clean(); 
 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); 
 $first_img = $matches [1] [0]; 
if(empty($first_img)){  
 $first_img = bloginfo('template_url'). '/images/default-thumb.jpg'; 
 } 
 return $first_img; 
 } 
//end
function make_get($arr){
	if(!is_array($arr)){
		return '';
	}
	$str = '?';
	$s = array();
	foreach($arr as $a=>$v){
		$s[] = $a.'='.$v;
	}
	$str .= implode('&',$s);
	return $str;
}
function attr($name,$value=''){
	
	if($value){
		update_option($name,$value);
	}else{
		return get_option($name);
	}
}
add_action( 'init', 'create_colors_nonhierarchical_taxonomy', 0 );
function create_colors_nonhierarchical_taxonomy() {
$str =  dopt('d_description'); 
$arr = explode(',',$str);
foreach($arr as $as){
  $labels = array(
    'name' => _x( $as, 'taxonomy general name' ),
    'singular_name' => _x( $as, 'taxonomy singular name' ),
    'search_items' =>  __( 'Search '.$as ),
    'popular_items' => __( 'Popular '.$as ),
    'all_items' => __( 'All '.$as ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit '.$as ),
    'update_item' => __( 'Update '.$as ),
    'add_new_item' => __( 'Add New '.$as ),
    'new_item_name' => __( 'New '.$as.' Name' ),
    'separate_items_with_commas' => __( 'Separate '.$as.' with commas' ),
    'add_or_remove_items' => __( 'Add or remove '.$as ),
    'choose_from_most_used' => __( 'Choose from the most used '.$as ),
    'menu_name' => __( $as ),
  ); 
  register_taxonomy($as,'post',array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => $as ),
  ));
}
}
function ashu_add_cat_field(){   
    echo '<div class="form-field">';   
    echo '<label for="xiaoxixi" >调用筛选</label>';   
    echo '<input type="text" size="" value="" id="xiaoxixi" name="xiaoxixi"/>';   
    echo '<p>输入筛选项目名称,逗号分隔</p>';   
    echo '</div>';   
}   
add_action('category_add_form_fields','ashu_add_cat_field', 10, 2);   
  
function ashu_edit_cat_field($tag){   
    echo '<table class="form-table"><tr class="form-field">
			<th scope="row" valign="top"><label for="xiaoxixi" >调用筛选</label></th>
			<td><input  type="text" value="';
	echo attr($tag->term_id.'xiaoxixi');
	echo '" id="xiaoxixi" name="xiaoxixi" size="40" />
			<p class="description">输入筛选项目名称,逗号分隔</p></td>
		</tr></table>';   
}   
add_action('category_edit_form_fields','ashu_edit_cat_field', 10, 2);    
add_action('created_category', 'ashu_taxonomy_metadata', 10, 1);   
add_action('edited_category','ashu_taxonomy_metadata', 10, 1);
function ashu_taxonomy_metadata($term_id){   
    if(isset($_POST['xiaoxixi'])){   
        if(!current_user_can('manage_categories')){   
            return $term_id ;   
        }   
           
        $data = $_POST['xiaoxixi'];   
           
       
            attr($term_id .'xiaoxixi', $data);   
    }   
}  
function dopt($e){
		return stripslashes(get_option($e));
	}
$dname = '过滤';
$themename = $dname.'设置';
$options = array(
    "d_description"
);
function mytheme_add_admin() {
    global $themename, $options;
    if ( $_GET['page'] == basename(__FILE__) ) {
        if ( 'save' == $_REQUEST['action'] ) {
            foreach ($options as $value) {
                update_option( $value, $_REQUEST[ $value ] ); 
            }
            header("Location: admin.php?page=functions.php&saved=true");
            die;
        }
    }
    add_theme_page($themename." Options", $themename."设置", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}
function mytheme_admin() {
    global $themename, $options;
    $i=0;
    if ( $_REQUEST['saved'] ) echo '<div class="updated settings-error"><p>'.$themename.'修改已保存</p></div>';
?>
<div class="wrap d_wrap entry">
 
<form method="post" class="d_formwrap">
    <table style="padding:20px 0 0 0;">
	<tr>
        <td style="color:red;">
<b>第一步</b>:输入筛选项目名称,逗号分隔;注:名称用全小写,空格用减号 - 代替;例如:price,color,size,sleeve-style
        </td>
    </tr>
    <tr>
        <td>
<input class="ipt-b" type="text" id="d_description" name="d_description" value="<?php echo dopt('d_description'); ?>" style="width:600px;float:left;margin:10px 10px 10px 0;">
<div style="margin:6px 10px;"class="d_desc">
<input class="button-primary" name="save" type="submit" value="保存筛选项目">
</div>
            <input type="hidden" name="action" value="save">
            <input type="hidden" name="page" value="functions.php">
        </td>
    </tr>
    <tr>
        <td>
<b>第二步</b>:保存后会显示每个筛选项目,点击下面的项目名称,添加每个筛选项目的具体参数:例如:点击Color,添加Red,Blue,Yellow.......
        </td>
    </tr>
    <tr>
        <td>
	<?php   
$str=dopt('d_description');
$keywords=array_filter(explode(",",$str));
foreach($keywords as $v){
echo "<li style='float:left;margin:10px 10px 10px 0px;text-transform:capitalize;'><a href='edit-tags.php?taxonomy=$v'>○ $v</a> </li>";
}?>
        </td>
    </tr>	
	
    <tr>
        <td>
<b>第三步</b>:在需要显示筛选的<a href="edit-tags.php?taxonomy=category">产品分类目录</a>下添加筛选项目名称;
        </td>
    </tr>	
	
	
    </table>
</form>
</div>
<script>
var aaa = []
jQuery('.d_wrap input, .d_wrap textarea').each(function(e){
    if( jQuery(this).attr('id') ) aaa.push( jQuery(this).attr('id') )
})
console.log( aaa )
</script>
<?php } ?>
<?php add_action('admin_menu', 'mytheme_add_admin');?>
<?php
	function get_currency(){
		$currency=$_COOKIE['currency'];
		return $currency;
	}
	function get_currency_symbol(){
		if (!isset($_COOKIE['currency'])) {        
			setcookie('currency', 'USD', time()+3600*24*30, COOKIEPATH, COOKIE_DOMAIN, false);
		 }		 
		 $currency=$_COOKIE['currency'];
		 if($currency=='EUR'){
			 $currency_symbol="€";
		 }else if($currency=='CAD'){
			 $currency_symbol="CAD$";
		 }else if($currency=='GBP'){
			 $currency_symbol="£";
		 }else if($currency=='AUD'){
			 $currency_symbol="AUD$";
		 }else if($currency=='HK'){
			 $currency_symbol="HK$";
		 }else if($currency=='JPY'){
			 $currency_symbol="円";
		 }else if($currency=='RUB'){
			 $currency_symbol="руб.";
		 }else if($currency=='CHF'){
			 $currency_symbol="CHF";
		 }else if($currency=='MXN'){
			 $currency_symbol="MXN";
		 }else if($currency=='NOK'){
			 $currency_symbol="Kr";
		 }else if($currency=='CZK'){
			 $currency_symbol="Kč";
		 }else if($currency=='BRL'){
			 $currency_symbol="R$";
		 }else if($currency=='ARS'){
			 $currency_symbol="$";
		 }else{
			 $currency_symbol="USD$";
		 }
		 return $currency_symbol;
	}
	function get_currency_name(){
		 $currency=$_GET['currency']?$_GET['currency']:$_COOKIE['currency'];
		 if($currency=='EUR'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=EUR'>EUR€</a>";
		 }else if($currency=='CAD'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=CAD'>CAD$</a>";
		 }else if($currency=='GBP'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=GBP'>GBP£</a>";
		 }else if($currency=='AUD'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=AUD'>AUD$</a>";
		 }else if($currency=='HK'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=HK'>HK$</a>";
		 }else if($currency=='JPY'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=JPY'>JPY円</a>";
		 }else if($currency=='RUB'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=RUB'>руб.</a>";
		 }else if($currency=='CHF'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=CHF'>CHF</a>";
		 }else if($currency=='CHF'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=MXN'>$MXN</a>";
		 }else if($currency=='NOK'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=NOK'>Kr</a>";
		 }else if($currency=='CZK'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=CZK'>Kč</a>";
		 }else if($currency=='BRL'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=BRL'>BRL$</a>";
		 }else if($currency=='ARS'){
			 $currency_name="Currency: <a rel='nofollow' href='?currency=ARS'>ARS$</a>";
		 }else{
			 $currency_name="Currency: <a rel='nofollow' href='?currency=USD'>USD$</a>";
		 }
		 return $currency_name;
	}
	function get_currency_price($price){
	     $currency_setting=get_option('currency_setting');	
		 $currency=$_COOKIE['currency'];
		 if($currency=='EUR'){
			 $currency_symbol_price=$price*$currency_setting['euro'];
		 }else if($currency=='CAD'){
			 $currency_symbol_price=$price*$currency_setting['canadian'];
		 }else if($currency=='GBP'){
			 $currency_symbol_price=$price*$currency_setting['british'];
		 }else if($currency=='AUD'){
			 $currency_symbol_price=$price*$currency_setting['australian'];
		 }else if($currency=='HK'){
			 $currency_symbol_price=$price*$currency_setting['HK'];
		 }else if($currency=='JPY'){
			 $currency_symbol_price=$price*$currency_setting['JPY'];
		 }else if($currency=='RUB'){
			 $currency_symbol_price=$price*$currency_setting['RUB'];
		 }else if($currency=='CHF'){
			 $currency_symbol_price=$price*$currency_setting['CHF'];
		 }else if($currency=='MXN'){
			 $currency_symbol_price=$price*$currency_setting['MXN'];
		 }else if($currency=='NOK'){
			 $currency_symbol_price=$price*$currency_setting['NOK'];
		 }else if($currency=='CZK'){
			 $currency_symbol_price=$price*$currency_setting['CZK'];
		 }else if($currency=='BRL'){
			 $currency_symbol_price=$price*$currency_setting['BRL'];
		 }else if($currency=='ARS'){
			 $currency_symbol_price=$price*$currency_setting['ARS'];
		 }else{
			 $currency_symbol_price=$price*1;
		 }
		 return round($currency_symbol_price,2);
	}
function custom_posts_per_page($query){ 
     if($query->query['blog_catalog']!=''||$query->query['post_type']=='blog'){
		 $query->set('posts_per_page',8);
	 }
     if($query->query['ps_catalog']!=''||$query->query['post_type']=='ps'){
		 $query->set('posts_per_page',36);
	 }
     if($query->query['vs_catalog']!=''||$query->query['post_type']=='vs'){
		 $query->set('posts_per_page',36);
	 }
}
// 排序
if (!function_exists('eshop_listorderColumn')) {
	function eshop_listorderColumn($cols) {
		$cols['listorder'] = __('排序');
		return $cols;
	} 
	function eshop_listorderValue($column_name, $post_id) {
		if ( 'listorder' == $column_name ) {
		    $listorder = get_post_meta($post_id, '_listorder', true);
		    if(!$listorder){
				update_post_meta($post_id, "_listorder", $post_id);
				$listorder=$post_id;
			}
		    echo '<input type="text" size="1"  style="width:50px" id="listorder_'.$post_id.'_val" name="listorder_post['.$post_id.'][listorder]" value="'.$listorder.'"><a class="listorder_edit" href="javascript:void(0);" id="listorder_'.$post_id.'" data-pid="'.$post_id.'"><img src="/wp-content/plugins/all-in-one-seo-pack/images/accept.png" border="0" alt="" title="修改"></a>';
		}
	} 
}
// for posts
add_filter( 'manage_posts_columns', 'eshop_listorderColumn' );
add_action( 'manage_posts_custom_column', 'eshop_listorderValue', 10, 2 );
function edit_listorder() {
    global $current_user;
    $post_id = $_POST['post_id'];
	$listorder = $_POST['listorder']?intval($_POST['listorder']):0;
    update_post_meta($post_id, "_listorder", $listorder);
    exit();
} 
add_action('wp_ajax_edit_listorder', "edit_listorder");
if ( !function_exists( 'listorder_admin_head' ) ) {
	function listorder_admin_head() {
?>
<script type="text/javascript">
$('.listorder_edit').click(function(){
	  var post_id = $(this).attr("data-pid");
	  var listorder = $('#listorder_'+post_id+'_val').val();
	  $.post("/wp-admin/admin-ajax.php", {action: 'edit_listorder', post_id: post_id, listorder:listorder },function(data){
		 alert("修改成功! ");
	   });
})
	 
</script>
<?php
	}
}
add_action( 'admin_footer', 'listorder_admin_head' );
function save_listorder( $post_id ) {
    $listorder = get_post_meta($post_id, '_listorder', true);
    if($listorder == "")
      update_post_meta($post_id, '_listorder', $post_id);
}
add_action('save_post', 'save_listorder');
//@eric 2015-12-18
//更新缩略图
function eric_updata_thumb($post_ID){
	$images = get_field('product_gallery');
	if( count($images) >0 ){
		$thum_url = $images[0]['sizes']['thumbnail'];
		set_post_thumbnail($post_ID,$images[0]['id']); 
	}
}
add_action( 'save_post', 'eric_updata_thumb', 10, 2 );
?>