ãã¾ãæ³å®ã§ããªãã±ã¼ã¹ã®ããã«æãããããããã¾ããããæå¤ã«ããã®ãããWordPressã«è¨äºãï¼ä»¶ãç¡ãå ´åãã§ãã
ããã¯ããã®ãµã¤ãå
¨ä½ã«è¨äºãã¾ã£ããç¡ãã¨ããã±ã¼ã¹ã§ã¯ããã¾ããã
ä¾ãã°ãã«ãã´ãªã¼ãè¤æ°ä½ã£ããã©ãã¾ã è¨äºãï¼ä»¶ãæ¸ãã¦ããªãã«ãã´ãªã¼ããããã¨ããå ´åã¯ããã®å
¸åã§ãããµã¤ãéå¶ãå§ããã°ããã§ã¯ããã¨æãã¾ãã
ã¾ããç§ãç´è¿ã§ä½ã£ããµã¤ãã§è¨ãã¨ã
WordPressã§é年度ã®åãæ¥ä»ãåãé±ã®è¨äºã表示ããæ¹æ³
ã«æ¸ãã¾ããéãã
人ç©åéã®ãµã¤ãã§ã人ç©ã®èªçæ¥ãè¨äºå
¬éæ¥ä»ã«ãããã®ã§ãããããã®æ¥ã«èªçæ¥ã®äººãããªãï¼ï¼éå»ã®ãã®æ¥ã®å
¬éè¨äºãç¡ãï¼ãã¨ããå ´åãããã¾ããã
ãã®ä»ã«ããããã§ãå¿ç¨ãèããããã¨æãã¾ããããããã«ãã¾ãã¦ããç¹å®ã®æ¡ä»¶ä¸ã«ãããWordPressè¨äºãï¼ä»¶ãç¡ããã¨ããå ´åã¯ããã¨æãã¾ãã
ãã®ãããªæã«ã空æ¬ã«ãã¦ãããã¨ãã§ãã¾ãããå³æ°ãªãã®ã§ããè¨äºãããã¾ããããããããè¨äºãæ¸ãã¾ãï¼ããªã©ã¨è¡¨ç¤ºããããã¨ããéã«ãï¼ä»¶ã§ãè¨äºãæ¸ãã¾ã§ã¯è©²å½ç®æã丸ã£ã¨åé¤ãããã¨ããããããéè¦ãããã®ã§ã¯ãªããã¨æãã¾ãã
ãããã®è¦æã«åãWordPressã®ãã³ãã¬ã¼ãã¿ã°ã¨ãã¦ã
get_posts
ã¨ããé¢æ°ãããã¾ãã
ãã³ãã¬ã¼ãã¿ã°/get posts – WordPress Codex æ¥æ¬èªç
ãã®é¢æ°ã使ãã¨ãè¨äºãï¼ä»¶ãç¡ãå ´åã«ãç¹å®ã®æåã表示ããããã¨ãå¯è½ã¨ãªãã¾ãã
ä¾ãã°ã以ä¸ã®ãããªã½ã¼ã¹ã³ã¼ããWordPressãã¼ãã®è©²å½ç®æã«æ¸ãã¾ãããã
WordPressã«è¨äºãï¼ä»¶ãç¡ãå ´åã«æåã表示ãããæ¹æ³
$kijiganai = get_posts( 'category=4' ); if (! $kijiganai){ echo "ââã«ãã´ãªã¼ã®è¨äºã¯ã¾ã ï¼ä»¶ãããã¾ããã"; }
以ä¸ã®ä¾ã¯ãã«ãã´ãªã¼IDãï¼ã®ã«ãã´ãªã¼ã«ãè¨äºãã¼ã件ã®å ´åããââã«ãã´ãªã¼ã®è¨äºã¯ã¾ã ï¼ä»¶ãããã¾ããããã¨æ¸ãä¾ã§ãã
è¡ãªã£ã¦ãããã¨ã¯åç´ã§ã
get_postsé¢æ°ã§ãè¨äºã®æç¡ãã$kijiganaiã¨ããå¤æ°ã«å
¥ãã¦ãã¾ãã
ããã¦ãè¨äºãç¡ãå ´åã«ãifæã®å¦å®æã!ãã§ãæ¡ä»¶ã«è©²å½ãã¦ããªãå ´åã«ãechoã§æ¸ããã¦ããæç« ã表示ããã¦ãã¾ãã
ããã¯ãå¿ç¨ãããã°ãéã«ãè¨äºãæãå ´åã«ç¹å®ã®æåãåºããã¨ãåºæ¥ãã§ãããããã®å ´åã¯ã
if (! $kijiganai)
ã¨ããã!ããåã£ã¦ã
if ($kijiganai)
ã¨ããã°è§£æ±ºãã¾ãã
get_postsã®ãã©ã¡ã¼ã¿ã¼ã¯ããã³ãã¬ã¼ãã¿ã°/get posts – WordPress Codex æ¥æ¬èªçã«è¼ã£ã¦ãã¾ãã
ãã©ã¡ã¼ã¿ã¼
$numberposts
ï¼æ´æ°ï¼ ï¼ãªãã·ã§ã³ï¼ åå¾ããæ稿ã®æ°ã0 ã«ããã¨to use the max number of posts per page ã®æ大å¤ã-1 ã«ããã¨å¶éç¡ã
åæå¤ï¼ 5
$offset
ï¼æ´æ°ï¼ ï¼ãªãã·ã§ã³ï¼ å é ããä½ä»¶ã®æ稿ãé¤å¤ãããã
åæå¤ï¼ 0
$category
ï¼æ´æ°ï¼ ï¼ãªãã·ã§ã³ï¼ æå®ããã«ãã´ãªID ã®æ稿ã®ã¿ãè¿ãã(-3ã®ããã«)ã«ãã´ãªID ããã¤ãã¹ã«ããã¨ããã®ã«ãã´ãªID以å¤ã®æ稿ãè¿ããè¤æ°ã®ã«ãã´ãªãæå®ããå ´åã¯ãã«ãã´ãªIDãã«ã³ãã§åºåã(é åã§ã®æå®ã¯ä¸å¯)ã
åæå¤ï¼ ãªã
$category_name
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ æå®ããã«ãã´ãªã¼åã¾ãã¯ã«ãã´ãªã¼ã¹ã©ãã°ã®æ稿ã®ã¿ãè¿ãã
åæå¤ï¼ ãªã
$tag
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ æå®ããã¿ã°ã¹ã©ãã°ã®æ稿ã®ã¿ãè¿ããè¤æ°ã®ã¿ã°ã¹ã©ãã°ãæå®ããå ´åã¯ãã«ã³ãã§åºåãã¨ãããããã®ã¿ã°ã«ãããããæ稿ããã¹ã¦è¿ããã¿ã°ã¹ã©ãã°ã空ç½ã§åºåã£ã¦æå®ããã¨ããã¹ã¦ã®ã¿ã°ã«ãããããæ稿ãè¿ãã
åæå¤ï¼ ãªã
$orderby
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ 以ä¸ã«ç¤ºãæ§ã ãªå¤(空ç½ã§åºåã)ã§ä¸¦ã¹æ¿ããã
‘author’ – èè IDã
‘category’ – ã«ãã´ãªIDã
‘content’ – ã³ã³ãã³ãã
‘date’ – ä½ææ¥ã
‘ID’ – æ稿IDã
‘menu_order’ – ã¡ãã¥ã¼ããã¼ã¸ã¨ã¢ã¿ããã¡ã³ãã§ã®ã¿æå¹ã
‘mime_type’ – MIME typeãã¢ã¿ããã¡ã³ãã§ã®ã¿æå¹ã
‘modified’ – æçµæ´æ°æ¥
‘name’ – stubã
‘parent’ – 親IDã
‘password’ – ãã¹ã¯ã¼ãã
‘rand’ – ã©ã³ãã ã
‘status’ – ã¹ãã¼ã¿ã¹ã
‘title’ – ã¿ã¤ãã«ã
‘type’ – æ稿ã¿ã¤ãã
注:
ID 㨠rand 㯠Version 2.5ããå©ç¨å¯è½ã
åæå¤ï¼ date
$order
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ $orderby ã§ã®ã½ã¼ãæ¹å¼ãæå¹ãªå¤:
‘ASC’ – æé (ä½ããé«)ã
‘DESC’ – éé (é«ããä½)ã
åæå¤ï¼ DESC
$include
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ 表示ãããæ稿ã®IDãã«ã³ãã¾ãã¯ç©ºç½ã§åºåãã次ã®ä¾ã§ã¯ã6 ã¤ã®æ稿ã表示ããã
‘45,63,78,94,128,140’
注: ãã®ãã©ã¡ã¼ã¿ã使ç¨ãã㨠posts_per_page, offset, category, exclude, meta_key, meta_value, ããã³ post_parent ãã©ã¡ã¼ã¿ãä¸æ¸ããã¾ãã
åæå¤ï¼ ãªã
$exclude
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ 表示ããããªãæ稿ã®IDãã«ã³ãã¾ãã¯ç©ºç½ã§åºåãã( $include ãã©ã¡ã¼ã¿ãåç §)
åæå¤ï¼ ãªã
$meta_key and $meta_value
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ ã¡ã¿ãã£ã¼ã«ã(ã«ã¹ã¿ã ãã£ã¼ã«ã)ã®ãã¼ã¨å¤ãæã¤æ稿ã®ã¿è¡¨ç¤ºããã両æ¹ã®ãã©ã¡ã¼ã¿æå®ãå¿ è¦(ä¸æ¹ã ãã§ã¯åä½ããªã)ã
åæå¤ï¼ ãªã
$post_type
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ 表示ããæ稿ã®ã¿ã¤ããå©ç¨å¯è½ãªãªãã·ã§ã³:
post – ããã©ã«ã
page
attachment
any – å ¨ã¦
åæå¤ï¼ post
$post_status
ï¼æååï¼ ï¼ãªãã·ã§ã³ï¼ æå®ããã¹ãã¼ã¿ã¹ã®æ稿ã表示ãããè¤æ°ã®ã¹ãã¼ã¿ã¹ãæå®ããå ´åã¯ã«ã³ãã§åºåããå©ç¨å¯è½ãªãªãã·ã§ã³:
publish – ããã©ã«ã
private
draft
future
inherit – $post_type ãã¢ã¿ããã¡ã³ãã®ã¨ãã®ããã©ã«ã
(blank) – ãã¹ã¦ã®ã¹ãã¼ã¿ã¹(WordPress version 2.8 以éã§ã¯ã’any’ ã使ç¨ãããå¤æ´ãããææã¯ä¸æã)
åæå¤ï¼ publish
$post_parent
ï¼æ´æ°ï¼ ï¼ãªãã·ã§ã³ï¼ ãã®IDã®æ稿ã®åã®ã¿ã表示ããã
åæå¤ï¼ ãªã
$nopaging
ï¼çå½å¤ï¼ ï¼ãªãã·ã§ã³ï¼ ãã¼ã¸ã³ã°ãæå¹ï¼ç¡å¹ã«ããããã¼ã¸ã³ã°ãç¡å¹ã«ãã㨠$numberposts ãªãã·ã§ã³ãç¡è¦ãããã
åæå¤ï¼ ãªã
以ä¸ã¨ãªãã¾ãã
get_postsé¢æ°ã¯è²ã
ãªå¿ç¨ã®ããé¢æ°ã§ãã®ã§ãç¥ã£ã¦ããã¨ä¾¿å©ãªå ´é¢ãããã¨æãã¾ãã
ãã¾ãã¾ããããã±ã¼ã¹ããã£ãã®ã§ãã¡ã¢ãå ¼ãã¦ããã°è¨äºã«æ¸ãã¾ãããget_postsé¢æ°ã®ä½¿ãæ¹ã®ï¼ã¤ã§ãã – WordPressã«è¨äºãï¼ä»¶ãç¡ãå ´åã«æåã表示ãããæ¹æ³ http://t.co/DjJiDfr6
å¤æ°ã®ä½¿ãæ¹å ¥éã«ããããªè¨äº
WordPressã«è¨äºãï¼ä»¶ãç¡ãå ´åã«æåã表示ãããæ¹æ³ http://t.co/d6BSchHj @khoshinoãããã
WordPressã«è¨äºãï¼ä»¶ãç¡ãå ´åã«æåã表示ãããæ¹æ³ http://t.co/tYyGHBNT @khoshinoãããã
@goodsun_taichi ééã£ãï¼ããã¯ï¼http://t.co/gwWzzLvM
get_posts使ç¨æã«è¨äºã1件ããªãæ
get_postsã§ä»¶æ°ã¼ãã®ã¨ãï¼ã¡ã¢ã¡ã¢