WordPressãã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦ä½¿ãã
WordPressã使ã£ã¦ã¢ããªã±ã¼ã·ã§ã³ãéçºãããããã¾ã§WordPressã¯ä½¿ã£ããã¨ããªãã£ãããç°¡åã«æ©è½ã追å ã§ããã
ããã°çãªã¢ããªã±ã¼ã·ã§ã³ãå¹çããéçºã§ããç°å¢ã«ãªã£ã¦ããã¨æãã
ãã¥ã¼: ãã¼ããã«ã¹ã¿ãã¤ãºãã
- ./wp-conent/themes/defaultãã£ã¬ã¯ããªãè¤è£½ãã¦ãªãªã¸ãã«ã®ãã¼ããä½ãã
- ããã·ã¥ãã¼ãï¼å¤è¦³ï¼ãã¼ã ã§ä½æãããã¼ããé¸æã
- index.php(ããããã¼ã¸)ãsingle.php(è¨äºåä½è¡¨ç¤º)ã«PHPã®ã³ã¼ãã足ãã
- é常ã®ããã°ã¨ãã¦æ©è½ããã¤ã¤ãç¹å®ã®è¨äºã«ã ãæ©è½ã追å ã§ããã
- ä¾: if (ã¿ã°Aãè¨å®ããã¦ããã) { æ¬æã®åå¾ã«å¥ãã¡ã¤ã«ãã¤ã³ã¯ã«ã¼ã }
- ä¾: if (æ稿ã¹ã©ãã°ãæ£è¦è¡¨ç¾ã«ããã) { ç¹å®ã¦ã¼ã¶ã®ã³ã¡ã³ããå¦çã»åºå }
- ä¾: if (ç¹å®ã®ã¦ã¼ã¶ãã³ã¡ã³ã) { DBãããã¼ã¿ãåå¾ãã¦åºå }
ã¢ãã«: ãªãã¸ã§ã¯ãã¨ãªãã¸ã§ã¯ãã®ãã¼
ãªãã¸ã§ã¯ãã¨ãã¼æååã
- è¨äº â¦â¦ æ稿ã¹ã©ãã°(ASCIIãè¨äºæ稿ç»é¢ã§è¨å®ã§ãããURLã«ä½¿ç¨ã)
- ã¿ã° â¦â¦ ã¿ã°ã¹ã©ãã°(ASCIIãã¿ã°ç®¡çç»é¢ã§è¨å®ã§ãããURLã«ä½¿ç¨ã)
- ã¦ã¼ã¶ â¦â¦ loginãã¼ã
ãããã®ãã¼ã使ã£ã¦ãè¨äºã»ã¿ã°ã»ã¦ã¼ã¶ã»ã³ã¡ã³ãéã«ããã©ã¦ã¶ããç·¨éå¯è½ãªãªã¬ã¼ã·ã§ã³ãä½ãåºããã
- ä¾: æ稿ã¹ã©ãã°=status_koseki / ã¦ã¼ã¶å=koseki
- ä¾: ã¿ã°ã¹ã©ãã°=permission_foo, permission_bar / ã¦ã¼ã¶å=foo, bar
- ä¾: ã¿ã°ã¹ã©ãã°=include_items / å¤é¨ãã¡ã¤ã«=$HOME/data/items.csv
ä»åã¯ä½¿ããªãã£ããã©ä½¿ããããªæ©è½ã
- è¨äºã«ã«ã¹ã¿ã ãã£ã¼ã«ãã足ããã
- ã«ãã´ãªã¯ããªã¼æ§é ã
- å ¬éäºç´ã
- è¨äºã®ãªãã¸ã§ã³ç®¡çã
ã³ã³ããã¼ã©: ãªã¯ã¨ã¹ããåãã¦ãã¼ãã«æ¸¡ãã¾ã§
index.php wp-blog-header.php â¦â¦ è¨å®ãã¼ã â wp() WPãªãã¸ã§ã¯ãä½æ â ãã¼ã wp-load.php â¦â¦ è¨å®ãç¡ãã£ããã¨ã©ã¼ wp-config.php â¦â¦ ã¦ã¼ã¶è¨å® wp-settings.php â¦â¦ ç°å¢æ§ç¯ $wp = &new WP(); query.php â¦â¦ ã¯ã¨ãªAPI : wp-include/template-loader.php â¦â¦ ãã¼ãå¦çã«ç§»è¡
ä¸çä¸ç°¡åãªWordPressã¯ã©ã¤ã¢ã³ã
大éã«è¨äºãæ稿ããå¿ è¦ããã£ãããå¤é¨APIã§ã¯æ稿ã¹ã©ãã°ã®è¨å®ãã§ããªãã£ããã¾ããXMLã¤ã³ãã¼ãã»ã¨ã¯ã¹ãã¼ãæ©è½ã§ã¯ãä¸åº¦åãè¾¼ãã è¨äºãä¸æ¸ãã§ããªãã£ãã
ããããªãã®ã§Mechanizeã使ãã¯ã©ã¤ã¢ã³ããä½ã£ãã
ãã¶ãä»ã®ã©ããªAPIã使ãããç°¡åã
url = "http://wordpress.local/" user = "admin" pass = "admin" client = WpClient.new(url).login(user,pass) # æ°è¦è¨äºä½æ entry = client.get entry.title = "title" entry.content = "body" entry.post_name = "abcde" entry.save # æ¢åã®è¨äºãç·¨é entry = client.get("http://è¨äºURL") entry.date = Time.now entry.tags = "ã¿ã°1,ã¿ã°2" entry.ping_status = false entry.comment_status = false entry.save
ãã ãHTMLã«ä¾åãããããã·ã¥ãã¼ãã®HTMLãå¤ããã¨åããªããªãããã¨ãæä½éå¿ è¦ã ã£ãæ©è½ããå®è£ ãã¦ãªããåé¤ã¨ãã§ãã¾ãããã²ã©ãã使ããªãã
ãã©ã°ã¤ã³
ãã©ã°ã¤ã³ãä½ã£ããç°¡åãªãã©ã°ã¤ã³ãªãç°¡åãé£ãããã©ã°ã¤ã³ã¯ä½ã£ã¦ãªãããããããªãã
以ä¸ã¯å®éã«ä½¿ã£ããã©ã°ã¤ã³ãã³ã¡ã³ãæ¬ã«jQueryã®star-ratingã§æãã¤ããUIã追å ãåºåæã«â ãç»åã§ç½®æããã
<?php /* Plugin Name: Star Comment Plugin URI: http://bluemark.co.jp/ Description: ã³ã¡ã³ãã®â ãç»åã«ç½®ãæãã¾ãã Author: KOSEKI Kengo Version: 1.0 */ function filter_starcomment($content) { return preg_replace('/â /u', '<img src="/common/js/star-rating/star_on.gif" />', $content); } add_filter('comment_text','filter_starcomment'); ?>
wp-content/pluginsã«å ¥ãã¦ãããã·ã¥ãã¼ãï¼ãã©ã°ã¤ã³ ã§ãã©ã°ã¤ã³ãæå¹ã«ããã
API
æ¥æ¬èªçã®APIããã¥ã¡ã³ãã¯å¤ãã£ããããã¿ããã
å¤æ°$postã¯the_xxxã¨ããé¢æ°ç¾¤ã§ãä»ã¿ã¼ã²ããã«ãã¦ããæ稿ãã¨ãã¦æ±ãããã$_ã¿ãããªãã®ããã³ãã¬ã¼ããã«ã¼ãã§æ±ããããããã«ããä¸æå¤æ°ã§$postã¨æ¸ããªãããã«æ°ãã¤ããã
以ä¸ã使ã£ãé¢æ°ã¨ãã¤ã使ãã§ãããé¢æ°ã®æç²ã
è¨äº
å ¨postãåå¾ã
$allposts = get_posts('numberposts=-1');
æ稿ã¹ã©ãã°ããpostãåå¾ã
$tmp = get_posts("name=postname1234");
echo $tmp[0]->post_name;
get_postsã®å¼æ°ã«ä½ãæ¸ããã®ãã詳ãã説æãè¦ã¤ãããªããã½ã¼ã¹ãè¦ãæ¹ãæ©ãããquery.phpã«æ¸ãã¦ããã
ã³ã¡ã³ã
è¨äºIDããã³ã¡ã³ãåå¾ã
$comments = get_comments("post_id=".$p->ID);
ã³ã¡ã³ãã®ãã£ã¼ã«ã
- http://codex.wordpress.org/Function_Reference/get_comment
- comment_content ã§å 容ã
- user_id ã§ã¦ã¼ã¶IDãåããã
ã¿ã°
è¨äºIDããã¿ã°åå¾ã
$tags = wp_get_post_tags($p->ID);
ã¦ã¼ã¶
ãã°ã¤ã³ã¦ã¼ã¶
$u = wp_get_current_user();
ãã°ã¤ã³ãã¦ããã
is_user_logged_in()
ã¦ã¼ã¶ã®åå¾ã
$u = get_userdata($comment->user_id);
- http://codex.wordpress.org/Function_Reference/get_userdata
- ID
- user_login
- display_name
- user_email
- user_url