{"id":199,"date":"2018-01-24T21:09:48","date_gmt":"2018-01-24T12:09:48","guid":{"rendered":"http:\/\/genicca.wp.xdomain.jp\/?p=199"},"modified":"2025-02-13T11:51:18","modified_gmt":"2025-02-13T02:51:18","slug":"wp%e3%82%a6%e3%82%a3%e3%82%b8%e3%82%a7%e3%83%83%e3%83%88%e4%b8%8a%e3%81%ae%e6%9c%80%e6%96%b0%e3%81%ae%e6%8a%95%e7%a8%bf%e4%b8%80%e8%a6%a7%e3%81%a7%e7%89%b9%e5%ae%9a%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4","status":"publish","type":"post","link":"https:\/\/genicca.cloudfree.jp\/?p=199","title":{"rendered":"WP\u30a6\u30a3\u30b8\u30a7\u30c3\u30c8\u4e0a\u306e\u6700\u65b0\u306e\u6295\u7a3f\u4e00\u89a7\u3067\u7279\u5b9a\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u3092\u9664\u5916"},"content":{"rendered":"<p>\u3053\u308cfunction.php\u306b\u5165\u308c\u3068\u3051\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\r\n\r\nclass WP_Widget_Recent_Posts_Exclude extends WP_Widget {\r\n\r\nfunction __construct() {\r\n$widget_ops = array('classname' =&gt; 'widget_recent_entries', 'description' =&gt; __( \"The most recent posts on your site\") );\r\nparent::__construct('recent-posts', __('Recent Posts with Exclude'), $widget_ops);\r\n$this-&gt;alt_option_name = 'widget_recent_entries';\r\n\r\nadd_action( 'save_post', array(&amp;$this, 'flush_widget_cache') );\r\nadd_action( 'deleted_post', array(&amp;$this, 'flush_widget_cache') );\r\nadd_action( 'switch_theme', array(&amp;$this, 'flush_widget_cache') );\r\n}\r\n\r\nfunction widget($args, $instance) {\r\n$cache = wp_cache_get('widget_recent_posts', 'widget');\r\n\r\nif ( !is_array($cache) )\r\n$cache = array();\r\n\r\nif ( ! isset( $args['widget_id'] ) )\r\n$args['widget_id'] = $this-&gt;id;\r\n\r\nif ( isset( $cache[ $args['widget_id'] ] ) ) {\r\necho $cache[ $args['widget_id'] ];\r\nreturn;\r\n}\r\n\r\nob_start();\r\nextract($args);\r\n\r\n$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this-&gt;id_base);\r\nif ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )\r\n$number = 10;\r\n$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];\r\n\r\n$r = new WP_Query(array('posts_per_page' =&gt; $number, 'no_found_rows' =&gt; true, 'post_status' =&gt; 'publish', 'ignore_sticky_posts' =&gt; true, 'category__not_in' =&gt; explode(',', $exclude) ));\r\nif ($r-&gt;have_posts()) :\r\n?&gt;\r\n&lt;?php \/\/echo print_r(explode(',', $exclude)); ?&gt;\r\n&lt;?php echo $before_widget; ?&gt;\r\n&lt;?php if ( $title ) echo $before_title . $title . $after_title; ?&gt;\r\n&lt;ul&gt;\r\n&lt;?php while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt;\r\n&lt;li&gt;&lt;a href=\"&lt;?php the_permalink() ?&gt;\" title=\"&lt;?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?&gt;\"&gt;&lt;?php if ( get_the_title() ) the_title(); else the_ID(); ?&gt;&lt;\/a&gt;&lt;\/li&gt;\r\n&lt;?php endwhile; ?&gt;\r\n&lt;\/ul&gt;\r\n&lt;?php echo $after_widget; ?&gt;\r\n&lt;?php\r\n\/\/ Reset the global $the_post as this query will have stomped on it\r\nwp_reset_postdata();\r\n\r\nendif;\r\n\r\n$cache[$args['widget_id']] = ob_get_flush();\r\nwp_cache_set('widget_recent_posts', $cache, 'widget');\r\n}\r\n\r\nfunction update( $new_instance, $old_instance ) {\r\n$instance = $old_instance;\r\n$instance['title'] = strip_tags($new_instance['title']);\r\n$instance['number'] = (int) $new_instance['number'];\r\n$instance['exclude'] = strip_tags( $new_instance['exclude'] );\r\n$this-&gt;flush_widget_cache();\r\n\r\n$alloptions = wp_cache_get( 'alloptions', 'options' );\r\nif ( isset($alloptions['widget_recent_entries']) )\r\ndelete_option('widget_recent_entries');\r\n\r\nreturn $instance;\r\n}\r\n\r\nfunction flush_widget_cache() {\r\nwp_cache_delete('widget_recent_posts', 'widget');\r\n}\r\n\r\nfunction form( $instance ) {\r\n$title = isset($instance['title']) ? esc_attr($instance['title']) : '';\r\n$number = isset($instance['number']) ? absint($instance['number']) : 5;\r\n$exclude = esc_attr( $instance['exclude'] );\r\n?&gt;\r\n&lt;p&gt;&lt;label for=\"&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;\"&gt;&lt;?php _e('Title:'); ?&gt;&lt;\/label&gt;\r\n&lt;input class=\"widefat\" id=\"&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;\" name=\"&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;\" type=\"text\" value=\"&lt;?php echo $title; ?&gt;\" \/&gt;&lt;\/p&gt;\r\n\r\n&lt;p&gt;&lt;label for=\"&lt;?php echo $this-&gt;get_field_id('number'); ?&gt;\"&gt;&lt;?php _e('Number of posts to show:'); ?&gt;&lt;\/label&gt;\r\n&lt;input id=\"&lt;?php echo $this-&gt;get_field_id('number'); ?&gt;\" name=\"&lt;?php echo $this-&gt;get_field_name('number'); ?&gt;\" type=\"text\" value=\"&lt;?php echo $number; ?&gt;\" size=\"3\" \/&gt;&lt;\/p&gt;\r\n\r\n&lt;p&gt;\r\n&lt;label for=\"&lt;?php echo $this-&gt;get_field_id('exclude'); ?&gt;\"&gt;&lt;?php _e( 'Exclude Category(s):' ); ?&gt;&lt;\/label&gt; &lt;input type=\"text\" value=\"&lt;?php echo $exclude; ?&gt;\" name=\"&lt;?php echo $this-&gt;get_field_name('exclude'); ?&gt;\" id=\"&lt;?php echo $this-&gt;get_field_id('exclude'); ?&gt;\" class=\"widefat\" \/&gt;\r\n&lt;br \/&gt;\r\n&lt;small&gt;&lt;?php _e( 'Category IDs, separated by commas.' ); ?&gt;&lt;\/small&gt;\r\n&lt;\/p&gt;\r\n&lt;?php\r\n}\r\n}\r\n\r\nfunction WP_Widget_Recent_Posts_Exclude_init() {\r\nunregister_widget('WP_Widget_Recent_Posts');\r\nregister_widget('WP_Widget_Recent_Posts_Exclude');\r\n}\r\n\r\nadd_action('widgets_init', 'WP_Widget_Recent_Posts_Exclude_init');\r\n\r\n?&gt;<\/code><\/pre>\n<\/div>\n<p>\u524d\u304b\u3089\u6c17\u306b\u306a\u3063\u3066\u305f\u3093\u3060\u3051\u3069\u3001WP\u30c6\u30fc\u30de\u306e\u4e2d\u3067function.php\u3068function<strong>s<\/strong>.php\u304c\u3042\u308b\u306e\u306f\u4f55\u6545\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u308cfunction.php\u306b\u5165\u308c\u3068\u3051\u3002 &lt;?php class WP_Widget_Recent_Posts_Exclude extends WP_Widget { function __construct()  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-php","category-wp"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=199"}],"version-history":[{"count":4,"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/199\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/genicca.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}