Site icon Amelt.net

how to display a specific category listed in the static page of wordpress.

全角空白スペースが入っているのを調べるテキストエディタ

This post is also available in: 日本語 (Japanese)

When you display a specific category listed in the static page of wordpress, there are about two ways.

1.To display a specific category list using the short code
2.To display a specific category list using PHP code and plug-in

I think more of 「1.To display a specific category list using the short code」 is can be introduced easily.

1.To display a specific category list using the short code

There is a useful feature called " short code " with the wordpress.

Procedure is simple, with "A. PHP code to the following additional function.php", "B. Insert the short code to a static page article you want to display a specific category" to.

A. PHP code to the following additional function.php

Reference site:
http://wp.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/ at "5. Get posts from WordPress Database with a Shortcode"

/*** Short code for displaying a particular category to a static page ***/

function sc_liste($atts, $content = null) {
        extract(shortcode_atts(array(
                "num" => '5',
                "cat" => ''
        ), $atts));
        global $post;
        $myposts = get_posts('numberposts='.$num.'&order=DESC&orderby=post_date&category='.$cat);
        $retour='<ul>';
        foreach($myposts as $post) :
                setup_postdata($post);
             $retour.='<li><a href="'.get_permalink().'">'.the_title("","",false).'</a></li>';
        endforeach;
        $retour.='</ul> ';
        return $retour;
}
add_shortcode("list", "sc_liste");

B.Short example code to be inserted into the static page article

The part you want to display a specific category of static page, insert the following short code.
The following example is when "the number of articles displayed by the 5" "a specific category ID displayed by the 75" of.

[list num="5" cat="75"]

Describe as follows in the case "a specific category to display 36" and "the number of articles displayed by the 3".

[list num="3" cat="36"]

By the way, how to check the category ID of wordpress

Moved to the [category > category name] from the management screen.
If you mouse over, display, such as the image below will appear.

wordpressカテゴリID確認方法



It is a "category & tag_ID = 75" it's image. This number is the category ID.

If the category ID does not display using this method, then you click the editing of the category name (portion surrounded by a red circle in the image) , the same notation should appear in the address bar of your browser.

2.To display a specific category list using PHP code and plug-in

Displays a specific Category List by installing the plug-in [Exec-PHP] that can be used by PHP to a fixed page.

Is not recommended problem is likely to occur how to display a specific category list in PHP code.