Last active
September 9, 2018 03:25
-
-
Save uruly/2c0c9099764079159347692a50eee93b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* News_Posts_Plugin Common Settings . | |
* | |
*/ | |
if ( !class_exists('News_Posts') ) { | |
exit; | |
} | |
$NewsPosts = new News_Posts; | |
class News_Posts { | |
// クラスがインスタンス化された時に呼ばれる | |
function __construct() { | |
add_action( 'init', array( $this, 'create_post_type' ) ); | |
} | |
function create_post_type() { | |
register_post_type( 'news', [ // 投稿タイプ名の定義 | |
'labels' => [ | |
'name' => 'ニュース', // 管理画面上で表示する投稿タイプ名 | |
'singular_name' => 'news', // カスタム投稿の識別名 | |
], | |
'public' => true, // 投稿タイプをpublicにするか | |
'has_archive' => true, // アーカイブ機能ON/OFF | |
'menu_position' => 5, // 管理画面上での配置場所 | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'posts_per_page' => 5, | |
'post_type' => 'news' | |
); | |
$the_query = new WP_Query( $args ); | |
if($the_query): | |
?> | |
<ul class="news-list"> | |
<?php | |
while ( $the_query->have_posts() ) : $the_query->the_post();?> | |
<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | |
<a href="<?php the_permalink();?>"> | |
<!-- date --> | |
<span class="news-date"><?php echo the_time('Y.n.j');?></span> | |
<?php the_title();?> | |
</a> | |
</li> | |
<?php endwhile;?> | |
</ul> | |
<?php else: ?> | |
<p class="content-excerpt">お知らせはありません。</p> | |
<?php endif;?> | |
<?php wp_reset_postdata(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php get_header(); ?> | |
<!-- News --> | |
<section class="top-content news" id="news"> | |
<div class="section-header"> | |
<h2>News</h2> | |
</div> | |
<?php get_template_part('content','front-news');?> | |
</section><!-- end .news --> | |
<?php get_footer(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: News Posts Plugin | |
Description: ニュース用の投稿を追加する | |
Version: 1.0 | |
Author: Reo | |
*/ | |
define( 'NSPP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | |
//ファイルの読み込み | |
require_once( NSPP_PLUGIN_DIR . '/class.news-posts-plugin.php' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment