get_cat_ID

Sponsored Link

カテゴリー名からカテゴリIDを取得します。

Sponsored Link

Retrieve the ID of a category from its name.

get_cat_IDのファンクションタグ使用方法

<?php get_cat_ID( $cat_name ) ?>

get_cat_IDのパラメーター

$cat_name

(string) (optional) デフォルトは”一般”であり、任意のカテゴリ名にすることができます。
デフォルト:”一般

(string) (optional) Default is ‘General’ and can be any category name.
Default: ‘General’

戻り値

(整数の場合は0、文字列の場合はID)
基本は0ですが、もし失敗する場合はカテゴリーIDで成功するかもしれない。

(integer if 0, string if ID)
0, if failure and ID of category on success.

基本例

これはループ内でこの関数を使う方法でとても基本的な例です。

This is a very basic example of how to use this function in The_Loop.

<?php
     $category_id = get_cat_ID('Category Name');
     $q = 'cat=' . $category_id;
     query_posts($q);
     if (have_posts()) : while (have_posts()) : the_post();

     the_content();

     endwhile; endif;
?>

注意

変更ログ

Since: 1.0.0

ソースファイル

get_cat_ID()は、wp-includes/category.php内に位置しています。

get_cat_ID() is located in wp-includes/category.php.

Sponsored Link