ワードプレス
【2020-10-15更新】投稿タイプ追加
functions.php
function create_post_type_news() {
$Supports = [
'title',
'editor',
'thumbnail',
];
register_post_type( 'recruit',
array(
'label' => '採用情報登録',
'labels' => array(
'all_items' => '採用情報一覧'
),
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'supports' => $Supports
)
);
}
add_action( 'init', 'create_post_type_news' );
一覧
<ul class="clearfix anime1">
<?php
$args = array(
'posts_per_page' => 20, // 表示する投稿数
'post_type' => array('recruit-post'), // 取得する投稿タイプのスラッグ
'orderby' => 'date', //日付で並び替え
'order' => 'DESC' // 降順 or 昇順
);
$my_posts = get_posts($args);
?>
<?php foreach ($my_posts as $post) : setup_postdata($post); ?>
<li>
<a href="<?php echo get_permalink($post->ID); ?>">
<time><?php echo get_the_date("Y年m月d日", $post->ID ); ?></time> //ショートコードの場合は、$post->ID必須
<p><?php echo get_the_title($post->ID); ?></p>
</a>
</li>
<?php endforeach; ?>
</ul>
サムネイル
<?php if ( get_the_post_thumbnail($post->ID)): ?>
<?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri() ?>/img/page/blank.jpg" alt="<?php the_title(); ?>" />
<?php endif ; ?>
———-
出力は、single-スラッグ.php
———-
条件分岐
<?php if(is_singular('recruit')) : ?>
<h2>採用情報一覧</h2>
