??xml version="1.0" encoding="utf-8" standalone="yes"?>jzzjzzjzz亚洲成熟少妇,日本在线视频一区,欧美日韩中文在线观看http://www.aygfsteel.com/cangshi004/category/50720.html日记?/description>zh-cnMon, 06 Jan 2014 14:35:53 GMTMon, 06 Jan 2014 14:35:53 GMT60WP后台表格代码CZhttp://www.aygfsteel.com/cangshi004/archive/2014/01/06/408551.htmlcangshicangshiMon, 06 Jan 2014 03:03:00 GMThttp://www.aygfsteel.com/cangshi004/archive/2014/01/06/408551.htmlhttp://www.aygfsteel.com/cangshi004/comments/408551.htmlhttp://www.aygfsteel.com/cangshi004/archive/2014/01/06/408551.html#Feedback0http://www.aygfsteel.com/cangshi004/comments/commentRss/408551.htmlhttp://www.aygfsteel.com/cangshi004/services/trackbacks/408551.html
  1. if(is_admin())   

  2. {   

  3.     new Cool_Wp_List_Table();   

  4. }   

  5.   

  6. /**  

  7.  * Cool_Wp_List_Table class will create the page to load the table  

  8.  */  

  9. class Cool_Wp_List_Table   

  10. {   

  11.     /**  

  12.      * Constructor will create the menu item  

  13.      */  

  14.     public function __construct()   

  15.     {   

  16.         add_action( 'admin_menu', array($this, 'add_menu_example_list_table_page' ));   

  17.     }   

  18.   

  19.     /**  

  20.      * Menu item will allow us to load the page to display the table  

  21.      */  

  22.     public function add_menu_example_list_table_page()   

  23.     {   

  24.         add_menu_page( 'CoowpCZ表格', 'CoowpCZ表格', 'manage_options', 'coolwp-list-table.php', array($this, 'list_table_page') );   

  25.     }   

  26.   

  27.     /**  

  28.      * Display the list table page  

  29.      *  

  30.      * @return Void  

  31.      */  

  32.     public function list_table_page()   

  33.     {   

  34.         $exampleListTable = new Example_List_Table();   

  35.         $exampleListTable->prepare_items();   

  36.         ?>   

  37.             <div class="wrap">   

  38.                 <div id="icon-users" class="icon32"></div>   

  39.                 <h2>CoowpCZ表格-面标题</h2>   

  40.                 <?php $exampleListTable->display(); ?>   

  41.             </div>   

  42.         <?php   

  43.     }   

  44. }   

  45.   

  46. // WP_List_Table is not loaded automatically so we need to load it in our application   

  47. if( ! class_exists( 'WP_List_Table' ) ) {   

  48.     require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );   

  49. }   

  50.   

  51. /**  

  52.  * Create a new table class that will extend the WP_List_Table  

  53.  */  

  54. class Example_List_Table extends WP_List_Table   

  55. {   

  56.     /**  

  57.      * Prepare the items for the table to process  

  58.      *  

  59.      * @return Void  

  60.      */  

  61.     public function prepare_items()   

  62.     {   

  63.         $columns = $this->get_columns();   

  64.         $hidden = $this->get_hidden_columns();   

  65.         $sortable = $this->get_sortable_columns();   

  66.   

  67.         $data = $this->table_data();   

  68.         usort( $data, array( &$this, 'sort_data' ) );   

  69.   

  70.         $perPage = 2;   

  71.         $currentPage = $this->get_pagenum();   

  72.         $totalItems = count($data);   

  73.   

  74.         $this->set_pagination_args( array(   

  75.             'total_items' => $totalItems,   

  76.             'per_page'    => $perPage  

  77.         ) );   

  78.   

  79.         $data = array_slice($data,(($currentPage-1)*$perPage),$perPage);   

  80.   

  81.         $this->_column_headers = array($columns, $hidden, $sortable);   

  82.         $this->items = $data;   

  83.     }   

  84.   

  85.     /**  

  86.      * Override the parent columns method. Defines the columns to use in your listing table  

  87.      *  

  88.      * @return Array  

  89.      */  

  90.     public function get_columns()   

  91.     {   

  92.         $columns = array(   

  93.             'id'          => __('ID'),   

  94.             'title'       => __('Title'),   

  95.             'description' => __('描述'),   

  96.             //__('Description'),怎么被Wordpress译?#8220;囑փ描述”?jin)?  

  97.             'date'        => __('Date'),   

  98.             'price'    => __('h'),//__('Price'),   

  99.             'rating'      => __('Rating')   

  100.         );   

  101.   

  102.         return $columns;   

  103.     }   

  104.   

  105.     /**  

  106.      * Define which columns are hidden  

  107.      *  

  108.      * @return Array  

  109.      */  

  110.     public function get_hidden_columns()   

  111.     {   

  112.         return array();   

  113.     }   

  114.   

  115.     /**  

  116.      * Define the sortable columns  

  117.      *  

  118.      * @return Array  

  119.      */  

  120.     public function get_sortable_columns()   

  121.     {   

  122.         return array('title' => array('title', false));   

  123.     }   

  124.   

  125.     /**  

  126.      * Get the table data  

  127.      *  

  128.      * @return Array  

  129.      */  

  130.     private function table_data()   

  131.     {   

  132.         $data = array();   

  133.   

  134.         $data[] = array(   

  135.                     'id'          => 1,   

  136.                     'title'       => '某IT讑֤U赁公司Q杨先生',   

  137.                     'description' => '上vQ需求描q?,   

  138.                     'date'        => '2013.01.01',   

  139.                     'price'       => '---',   

  140.                     'rating'      => '7.3'   

  141.                     );   

  142.   

  143.         $data[] = array(   

  144.                     'id'          => 2,   

  145.                     'title'       => '某婚摄团队:(x)李先?,   

  146.                     'description' => '台湾Q台?,   

  147.                     'date'        => '2013.12.15',   

  148.                     'price'       => '---',   

  149.                     'rating'      => '7.2'   

  150.                     );   

  151.   

  152.         $data[] = array(   

  153.                     'id'          => 3,   

  154.                     'title'       => '在校研究生:(x)梁小?,   

  155.                     'description' => '墨尔本大学:(x)艺术设计',   

  156.                     'date'        => '2013.12.03',   

  157.                     'price'       => '---',   

  158.                     'rating'      => '7.0'   

  159.                     );   

  160.   

  161.         $data[] = array(   

  162.                     'id'          => 4,   

  163.                     'title'       => '某私I公?,   

  164.                     'description' => '仅前端交互:(x)何小?,   

  165.                     'date'        => '2014.01.01',   

  166.                      'price'      => '---',   

  167.                     'rating'      => '7.0'   

  168.                     );   

  169.         return $data;   

  170.     }   

  171.   

  172.     /**  

  173.      * Define what data to show on each column of the table  

  174.      *  

  175.      * @param  Array $item        Data  

  176.      * @param  String $column_name - Current column name  

  177.      *  

  178.      * @return Mixed  

  179.      */  

  180.     public function column_default( $item, $column_name )   

  181.     {   

  182.         switch( $column_name ) {   

  183.             case 'id':   

  184.             case 'title':   

  185.             case 'description':   

  186.             case 'date':   

  187.             case 'price':   

  188.             case 'rating':   

  189.                 return $item[ $column_name ];   

  190.   

  191.             default:   

  192.                 return print_r( $item, true ) ;   

  193.         }   

  194.     }   

  195.   

  196.     /**  

  197.      * Allows you to sort the data by the variables set in the $_GET  

  198.      *  

  199.      * @return Mixed  

  200.      */  

  201.     private function sort_data( $a, $b )   

  202.     {   

  203.         // Set defaults   

  204.         $orderby = 'title';   

  205.         $order = 'asc';   

  206.   

  207.         // If orderby is set, use this as the sort column   

  208.         if(!emptyempty($_GET['orderby']))   

  209.         {   

  210.             $orderby = $_GET['orderby'];   

  211.         }   

  212.   

  213.         // If order is set use this as the order   

  214.         if(!emptyempty($_GET['order']))   

  215.         {   

  216.             $order = $_GET['order'];   

  217.         }   

  218.   

  219.         $result = strcmp( $a[$orderby], $b[$orderby] );   

  220.   

  221.         if($order === 'asc')   

  222.         {   

  223.             return $result;   

  224.         }   

  225.   

  226.         return -$result;   

  227.     }   

  228. }  

ENJOY IT!

cangshi 2014-01-06 11:03 发表评论
]]>
可以用在WordPress侧栏的一l图片广告轮播的代码http://www.aygfsteel.com/cangshi004/archive/2013/12/31/408236.htmlcangshicangshiTue, 31 Dec 2013 03:30:00 GMThttp://www.aygfsteel.com/cangshi004/archive/2013/12/31/408236.htmlhttp://www.aygfsteel.com/cangshi004/comments/408236.htmlhttp://www.aygfsteel.com/cangshi004/archive/2013/12/31/408236.html#Feedback0http://www.aygfsteel.com/cangshi004/comments/commentRss/408236.htmlhttp://www.aygfsteel.com/cangshi004/services/trackbacks/408236.html本文介绍一l适用于在Wordpress侧栏攄的图片广告轮播(jsQ代码:(x)可自动播放,同时响应访客的点?br />

1.样式?/p>

  1. /*SidebarTabsAd*/  
  2. #cwpad_box{width:100%;text-align:center}   
  3. #cwpad_box ul, #cwpad_box dd, #cwpad_box tt{   
  4.     margin:0px;   
  5.     padding:0px;   
  6.     float:left;   
  7.     list-style: none;   
  8. }   
  9. #cwpad_box{   
  10.     width:313px;/*250px+(n-1)*21px*/  
  11.     height:250px;   
  12.     border-left: 1px solid #740a20;   
  13. }   
  14. #cwpad_box dd{   
  15.     width:21px;   
  16.     height:250px;   
  17.     overflow:hidden;   
  18.     position:relative;   
  19. }   
  20. #cwpad_box dd.hove{   
  21.     width:250px;   
  22.     text-align:rightright;   
  23. }   
  24. #cwpad_box dd tt{   
  25.     width:20px;   
  26.     height:250px;   
  27.     top:0px;   
  28.     left:0px;   
  29.     color:#fff;   
  30.     cursor:pointer;   
  31.     text-align:center;   
  32.     padding:20px 0 0 0;   
  33.     background:#b9000d;   
  34.     position:absolute;   
  35.     border-right:1px solid #740a20;   
  36. }   
  37. #cwpad_box dd tt.hove{   
  38.     background:#620317;   
  39. }  

在上面的样式表中Q假设放|的是四?50px*250px的图片广告,所?50+Q?-1Q?21=313px?/p>

2.javascript代码

  1. <script type="text/javascript">   
  2. function myAddEvent(obj, sEvent, fn){   
  3.     return obj.attachEvent ? obj.attachEvent('on' + sEvent, fn) : obj.addEventListener(sEvent, fn, false);   
  4. }   
  5. function Class(oParent, sClass){   
  6.     var aElem = oParent.getElementsByTagName('*');   
  7.     var aClass = [];   
  8.     var i = 0;   
  9.     for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]);   
  10.     return aClass;   
  11. };   
  12. function css(obj, attr, value){   
  13.     if(arguments.length == 2){   
  14.         var style = obj.style,   
  15.             currentStyle = obj.currentStyle;   
  16.         if(typeof attr === 'string')return currentStyle ? currentStyle[attr] : getComputedStyle(obj, false)[attr];   
  17.         for(var propName in attr)propName == 'opacity' ? (style.filter = "alpha(opacity=" + attr[propName] + ")", style.opacity = attr[propName] / 100) : style[propName] = attr[propName];    
  18.     }else if(arguments.length == 3){   
  19.         switch(attr){   
  20.             case "width":   
  21.             case "height":   
  22.             case "paddingTop":   
  23.             case "paddingRight":   
  24.             case "paddingBottom":   
  25.             case "paddingLeft":   
  26.             case "top":   
  27.             case "right":   
  28.             case "bottom":   
  29.             case "left":   
  30.             case "marginTop":   
  31.             case "marginRigth":   
  32.             case "marginBottom":   
  33.             case "marginLeft":   
  34.                 obj.style[attr] = value + "px";   
  35.                 break;   
  36.             case "opacity":   
  37.                 obj.style.filter = "alpha(opacity=" + value + ")";   
  38.                 obj.style.opacity = value / 100;   
  39.                 break;   
  40.             default:   
  41.                 obj.style[attr] = value   
  42.         }   
  43.     }   
  44. };   
  45. function extend(destination, source){   
  46.     for (var propName in source) destination[propName] = source[propName];   
  47.     return destination   
  48. };   
  49. function doMove(obj, json, fnEnd){   
  50.     clearInterval(obj.timer);   
  51.     obj.iSpeed = 0;   
  52.     fnEnd = extend({   
  53.         type: "buffer",   
  54.         callback: function() {}   
  55.     }, fnEnd);   
  56.     obj.timer = setInterval(function(){   
  57.         var iCur = 0,   
  58.             iStop = true;   
  59.         for(var propName in json){   
  60.             iCur = parseFloat(css(obj, propName));   
  61.             propName == 'opacity' && (iCur = Math.round(iCur * 100));   
  62.             switch(fnEnd.type){   
  63.                 case 'buffer':   
  64.                     obj.iSpeed = (json[propName] - iCur) / 5;   
  65.                     obj.iSpeed = obj.iSpeed > 0 ? Math.ceil(obj.iSpeed) : Math.floor(obj.iSpeed);   
  66.                     json[propName] == iCur || (iStop = false, css(obj, propName, iCur + obj.iSpeed));   
  67.                     break;   
  68.                 case 'elasticity':   
  69.                     obj.iSpeed += (json[propName] - iCur) / 5;   
  70.                     obj.iSpeed *= 0.75;   
  71.                     Math.abs(json[propName] - iCur) <= 1 &&  Math.abs(obj.iSpeed) <= 1 ? css(obj, propName, json[propName]) : css(obj, propName, json[propName]) || (iStop = false, css(obj, propName, iCur + obj.iSpeed));   
  72.                     break;   
  73.                 case 'accelerate':   
  74.                     obj.iSpeed = obj.iSpeed + 5;   
  75.                     iCur >= json[propName] ? css(obj, propName, json[propName]) : css(obj, propName, json[propName]) || (iStop = false, css(obj, propName, iCur + obj.iSpeed));   
  76.                 break;   
  77.             }   
  78.         }   
  79.         if(iStop){   
  80.             clearInterval(obj.timer);   
  81.             obj.timer = null;   
  82.             obj.iSpeed = 0;   
  83.             fnEnd.callback();   
  84.         }   
  85.     },30);   
  86. };   
  87.   
  88. window.onload = function(){   
  89.     var oBox = document.getElementById('cwpad_box')   
  90.     var aSpan = document.getElementsByTagName('tt');   
  91.     var aLi = document.getElementsByTagName('dd');   
  92.     var playtime = null;   
  93.     var iNow = 0;   
  94.     for(i=0;i<aSpan.length;i++){   
  95.         aSpan[i].index = i;   
  96.         aSpan[i].onclick = function(){   
  97.             for(var len=aLi.length,i=0;i<len;i++)doMove(aLi[i], {width:21});   
  98.             for(var len=aSpan.length,i=0;i<len;i++)aSpan[i].className = '';   
  99.             this.className = 'hove';   
  100.             doMove(this.parentNode, {width:250});   
  101.             iNow = this.index;   
  102.         };   
  103.     }   
  104.     playtime = setInterval(tab,3500);   
  105.     oBox.onmouseover = function(){   
  106.         clearInterval(playtime);   
  107.     }   
  108.     oBox.onmouseout = function(){   
  109.         playtime = setInterval(tab,3500);   
  110.     }   
  111.     function tab(){   
  112.         iNow == aLi.length-1 ? iNow = 0 : iNow++;   
  113.         aSpan[iNow].onclick();   
  114.     }   
  115. };   
  116.  </script>    

 

3.CZ的HTML代码

  1. <div id="cwpad_box">  
  2.     <ul>  
  3.         <dd  class="hove">  
  4.         <tt class="hove">|站设计?qing)培?lt;/tt>  
  5.         <a ></a>  
  6.         </dd>  
  7.     </ul>  
  8. </div>  

使用的是索凌|络前面介绍q的"假图"生成|站fakeimg.pl生成?假图"?/p>

q组代码的一个显著缺Ҏ(gu)Q不适合Ud讑֤昄?/p>



cangshi 2013-12-31 11:30 发表评论
]]>
WordPress查询文章作者的文章数及(qing)WordPress用户角色/权限http://www.aygfsteel.com/cangshi004/archive/2013/12/05/407245.htmlcangshicangshiThu, 05 Dec 2013 02:49:00 GMThttp://www.aygfsteel.com/cangshi004/archive/2013/12/05/407245.htmlhttp://www.aygfsteel.com/cangshi004/comments/407245.htmlhttp://www.aygfsteel.com/cangshi004/archive/2013/12/05/407245.html#Feedback0http://www.aygfsteel.com/cangshi004/comments/commentRss/407245.htmlhttp://www.aygfsteel.com/cangshi004/services/trackbacks/407245.html本文详细介绍?jin)如何查询Wordpress某一文章作者的文章以及(qing)其权限,附带介绍?jin)Wordpress的用h限系l,指出?jin)网上到处复制的某些文章存在的问题?/div>

一、查询Wordpress某篇文章作者的全部文章或部分最新文?/h2>

1.获取当前文章作者的ID

  1. get_post($id)->post_author  

q才是获取Wordpress当前文章作者ID的正方式,|上到处׃的那名?#8220;WordPress 通过文章I(yng)D获取文章标题、内容等信息”的文章里的说法是错误的,虽然是错误的Q但是却被广泛的Ctrl+C然后Ctrl+VQ以讹传讹,不可思议啊?/p>

另外get_post($id)->可以获取与文章有关的许多信息Q{q如下:(x)

  1. post_authorQ?整数Q文章作者的~号    
  2. post_dataQ?字符Q文章发表的日期和时_(d)YYYY-MM-DD HH-MM-SS)    
  3. post_data_gmtQ(字符Q文章发表的格林治标准旉QGMTQ?nbsp;QYYYY-MM-DD HH-MM-SS)    
  4. post_contentQ(字符Q文章内?nbsp;   
  5. post_titleQ(字符Q文章标?nbsp;   
  6. post_categoryQ(整数Q文章类别的~号。注意:(x)该值在WordPress 2.1之后的版本Mؓ(f)0。定义文章的cd时可使用 get_the_category()函数?nbsp;   
  7. post_excerptQ(字符Q文章摘?nbsp;   
  8. post_statusQ?字符Q文章状态(publish|pending|draft|private|static|object|attachment|inherit|futureQ?nbsp;   
  9. comment_statusQ(字符Q评论状态(open|closed|registered_onlyQ?nbsp;   
  10. ping_statusQ(字符Qpingback/trackback状态(open|closedQ?nbsp;   
  11. post_passwordQ?字符Q文章密?nbsp;   
  12. post_nameQ?字符Q文章的URL嵌套    
  13. to_pingQ?字符Q要引用的URL链接    
  14. pingedQ(字符Q引用过的链?nbsp;   
  15. post_modifiedQ?字符Q文章最后修Ҏ(gu)_(d)YYYY-MM-DD HH-MM-SS)    
  16. post_modified_gmtQ?字符Q文章最后修改GMT旉QYYYY-MM-DD HH-MM-SS)    
  17. post_parentQ?整数Q父U文章编P供附件等Q?nbsp;   
  18. guidQ(字符Q文章的一个链接。注意:(x)不能GUID作ؓ(f)怹链接Q虽然在2.5之前的版本中它的被当作怹链接Q,也不能将它作为文章的可用链接。GUID是一U独有的标识W,只是目前恰y成ؓ(f)文章的一个链接?nbsp;   
  19. post_typeQ(字符Q(日志 | 面 | 附gQ?nbsp;   
  20. post_mime_typeQ?字符QMimecdQ供附g{)(j)    
  21. comment_countQ(整数Q评论L  

 

2.Wordpress查询文章作者的全部文章/部分文章的主要函数及(qing)输出

  1. <?php   
  2. global $wpdb;   
  3. //$current_user->ID的话Q查询的是当前d的用P所以是不对?   
  4. $author_id = get_post($id)->post_author;   
  5. $sql =  "SELECT * FROM $wpdb->posts WHERE post_status IN ('publish','static') AND post_author = '$author_id' AND post_type ='post'LIMIT 5" ; //查询作者文章数?  
  6. $posts= $wpdb->get_results($sql);   
  7.     foreach ($posts as $post) {   
  8.   
  9. echo'<li><a href="';the_permalink();echo '" rel="twipsy" title="';the_title();echo '">'. mb_strimwidth(get_the_title(), 0, 20,"...").'</a></li>';   
  10. }   
  11. ?>  

只在无序列表ul里输Z个列表,格式是截断的标题加上链接Q查询了(jin)仅仅5,多了(jin)的话Q没什么用Q这里仅仅是试?/p>

二、Wordpress用户角色与权?/h2>

WordPress用户角色或者Wordpress用户权限说是从Wordpress2.0开始,逐渐的完善v来的Q默认分以下几种的:(x)

  1. Super Admin񔽎理?针对Wordpress多站点环境,一般h很少接触Q所以很有人提?qing)?  
  2. Administrator理?nbsp;-拥有特定的某一个站?/strong>的所有管理权限;   
  3. Editor~辑 -发表文章、编辑文章、ƈ能编辑其他h的文章等{;   
  4. Author作?能够发布和编辑自q文章Q?  
  5. Contributor贡献者或者叫投稿?nbsp;-能够撰写和编辑自q文章、但不能发布Q?  
  6. Subscriber订阅?nbsp;-能够查看评论/d评论/查看文章Q等{?nbsp; 

 

当新用户在你的Wordpress站点上注册了(jin)的时候(假设已经开启注册)(j)Q他的默认角色可以在Wordpress后台-->讄-->常规面讄?/p>

下面的用戯色以?qing)对应的权限能力{对照表翻译自Wordpress官方|站Q所在页面:(x)

http://codex.wordpress.org/Roles_and_Capabilities#Capabilities

 

角色񔽎理?/th>理员(单个站点Q?/th>~辑作?/th>贡献者(投稿者)(j)订阅?/th>
manage_network?/td>




manage_sites?/td>




manage_network_users?/td>




manage_network_plugins?/td>




manage_network_themes?/td>




manage_network_options?/td>




unfiltered_html?/td>




角色񔽎理?/th>理员(单个站点Q?/th>~辑作?/th>贡献者(投稿者)(j)订阅?/th>
activate_plugins?/td>?/td>



create_users?/td>仅单个站?/td>



delete_plugins?/td>?/td>



delete_themes?/td>仅单个站?/td>



delete_users?/td>?/td>



edit_files?/td>?/td>



edit_plugins?/td>仅单个站?/td>



edit_theme_options?/td>?/td>



edit_themes?/td>仅单个站?/td>



edit_users?/td>仅单个站?/td>



export?/td>?/td>



import?/td>?/td>



角色񔽎理?/th>理员(单个站点Q?/th>~辑作?/th>贡献者(投稿者)(j)订阅?/th>
install_plugins?/td>仅单个站?/td>



install_themes?/td>仅单个站?/td>



list_users?/td>?/td>



manage_options?/td>?/td>



promote_users?/td>?/td>



remove_users?/td>?/td>



switch_themes?/td>?/td>



update_core?/td>仅单个站?/td>



update_plugins?/td>仅单个站?/td>



update_themes?/td>仅单个站?/td>



edit_dashboard?/td>?/td>



角色񔽎理?/th>理员(单个站点Q?/th>~辑作?/th>贡献者(投稿者)(j)订阅?/th>
moderate_comments?/td>?/td>?/td>


manage_categories?/td>?/td>?/td>


manage_links?/td>?/td>?/td>


edit_others_posts?/td>?/td>?/td>


edit_pages?/td>?/td>?/td>


edit_others_pages?/td>?/td>?/td>


edit_published_pages?/td>?/td>?/td>


publish_pages?/td>?/td>?/td>


delete_pages?/td>?/td>?/td>


delete_others_pages?/td>?/td>?/td>


delete_published_pages?/td>?/td>?/td>


delete_others_posts?/td>?/td>?/td>


delete_private_posts?/td>?/td>?/td>


edit_private_posts?/td>?/td>?/td>


阅读_private_posts?/td>?/td>?/td>


delete_private_pages?/td>?/td>?/td>


edit_private_pages?/td>?/td>?/td>


阅读_private_pages?/td>?/td>?/td>


角色񔽎理?/th>理员(单个站点Q?/th>~辑作?/th>贡献者(投稿者)(j)订阅?/th>
edit_published_posts?/td>?/td>?/td>?/td>

upload_files?/td>?/td>?/td>?/td>

create_product?/td>?/td>?/td>?/td>

publish_posts?/td>?/td>?/td>?/td>

delete_published_posts?/td>?/td>?/td>?/td>

edit_posts?/td>?/td>?/td>?/td>?/td>
delete_posts?/td>?/td>?/td>?/td>?/td>
阅读?/td>?/td>?/td>?/td>?/td>?/td>
角色񔽎理?/th>理员(单个站点Q?/th>~辑作?/th>贡献者(投稿者)(j)订阅?/th>

 

1.查询Wordpress文章作者的角色

在本文的开_(d)我们已经知道如何获取Wordpress某一文章的作者ID?jin),现在来获取其角Ԍ?x)

  1. $user_id=get_post($id)->post_author;   
  2. if(user_can($user_id,'install_plugins')){echo'理?;}   
  3. elseif(user_can($user_id,'edit_others_posts')){echo'理~辑';}elseif(user_can($user_id,'publish_posts')){echo'作?;}elseif(user_can($user_id,'delete_posts')){echo'贡献?;}elseif(user_can($user_id,'read')){echo'订阅?;}   

理员和~辑都能publish_postsQ但是这里的判断有先后顺序,所以不用担?j)这个问题,q个判断是不错的Q?/p>

WordPress某篇文章的作者是否有某权限的推荐函数Q?/p>

  1. if ( author_can( $post, $capability ) ) {      
  2. // 如果文章 $post 的作者拥?nbsp;$capability 时执行的动作      
  3. }    

q个相对单一些,可以直接d断,所以我再某个项目中最l用了(jin)q个函数。参C?post可以是文章自w,也可以是文章I(yng)DQ用v来很方便Q?/p>

  1. if(author_can($post->ID,'install_plugins'))   
  2. {echo'<span class="label label-warning role">理?lt;/span>';}elseif(author_can($post->ID,'edit_others_posts')){echo'理~辑';}elseif(author_can($post->ID,'publish_posts')){echo'作?;}elseif(author_can($post->ID,'delete_posts')){echo'投稿?;}elseif(author_can($post->ID,'read')){echo'订阅?;}  

2.Wordpress当前d者的权限/权限{

q个函数是经常被使用的,使用的是权限{QW(xu)ordpress官方已经声明Q从Wordpress3.0Q已l废弃了(jin)对这个权限等U制度的支持Q所以,|上到处乱飞的复制文章,谨慎对待吧!

  1. <?php if(current_user_can('level_10')){ echo '理?;}elseif(current_user_can('level_7')){ echo '理~辑';}elseif(current_user_can('level_4')){ echo '作?;}elseif(current_user_can('level_4')){ echo '贡献?;}elseif(current_user_can('level_0')){ echo '订阅?;}   
  2.     ?>  

 



cangshi 2013-12-05 10:49 发表评论
]]>
转蝲一今天正好遇到的动态{化ؓ(f)?rn)态问题方?/title><link>http://www.aygfsteel.com/cangshi004/archive/2013/09/27/404534.html</link><dc:creator>cangshi</dc:creator><author>cangshi</author><pubDate>Fri, 27 Sep 2013 03:14:00 GMT</pubDate><guid>http://www.aygfsteel.com/cangshi004/archive/2013/09/27/404534.html</guid><wfw:comment>http://www.aygfsteel.com/cangshi004/comments/404534.html</wfw:comment><comments>http://www.aygfsteel.com/cangshi004/archive/2013/09/27/404534.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/cangshi004/comments/commentRss/404534.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/cangshi004/services/trackbacks/404534.html</trackback:ping><description><![CDATA[其实之前早就存在q样一个问题,只是没有旉去考虑是否?x)?jing)响到整个|站l构的内部优化。忙里偷闲之中我无意扑ֈ?jin)解x案在|上扑ֈ的,E序是PHP的,在这里{载分享一下,也希望在以后能够利用方便一炏V?br /><div><p>首先讄.htaccess文gQ将动态调用的参数转换为静(rn)态的HTML的URL地址Q例如将在post目录下的文gQ{发到根目录的wp- post.php文g中,加入的语句类|(x)RewriteRule ^post/([a-z0-9\-]+\.html)$ wp-post.php?$1$2</p> <p>然后修改wp-post.php文gQ在文g的开头加入以下PHP代码Q?/p> <p>以下为引用的内容Q?/p> <p>ob_start();</p> <p>$qstring = isset($_SERVER["QUERY_STRING"]) ? $_SERVER["QUERY_STRING"] : "";</p> <p>define("HTML_FILE", $_SERVER['DOCUMENT_ROOT']."/post/".$qstring);</p> <p>if (file_exists(HTML_FILE))</p> <p>{</p> <p>$lcft = filemtime(HTML_FILE);</p> <p>if (($lcft + 3600) > time()) //判断上次生成HTML文g是否过1时Q若没有才直接输出文件内?/p> <p>{</p> <p>echo(file_get_contents(HTML_FILE));</p> <p>exit(0);</p> <p>}</p> <p>}</p> <p>之后是现有的PHP的代码,然后在当前代码的最后面加上如下的PHP代码Q?/p> <p>以下为引用的内容Q?/p> <p>define("HTMLMETA","");</p> <p>$buffer = ob_get_flush();</p> <p>$fp = fopen(HTML_FILE, "w");</p> <p>if ($fp)</p> <p>{</p> <p>fwrite($fp, $buffer.HTMLMETA);</p> <p>fclose($fp);</p> <p>}</p> <p>好了(jin)Q然后查看你的静(rn)态HTML面Q如果页面尾部出C(jin)注释行,说明已经成功的创Z(jin)?rn)态HTML文g?/p> <p>q个Ҏ(gu)的一个应用就是我先前写的那个“WordPressq度博客l计插g”Q这个统计插件由于查询十多次数据库,很多问的时候会(x)有很大性能问题Q用我介绍的这U动态生成HTML技术后Q一天就查询一ơ,生成一ơ统计排行,完美解决?jin)查询数据库的性能问题?/p></div><img src ="http://www.aygfsteel.com/cangshi004/aggbug/404534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/cangshi004/" target="_blank">cangshi</a> 2013-09-27 11:14 <a href="http://www.aygfsteel.com/cangshi004/archive/2013/09/27/404534.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">鱦</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ն</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ֺ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̨ʡ</a>| <a href="http://" target="_blank">ٸ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯ̨</a>| <a href="http://" target="_blank">첼</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯ</a>| <a href="http://" target="_blank">կ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ѳ</a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˳</a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank">ͭ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ĵ</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank">²</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͭɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>