こんにちは。
WPのカスタム投稿で困っておりご教授お願いしたい次第です。
フォーラムや検索をかけても思ったような(自分の理解がないだけだと思いますが)記事が、
見つかりませんでした。
現在WPでカスタム投稿タイプを設置しており、一覧表示は出来ております。
お知らせ(ニュースやイベント情報)を掲載しているのですが、
テンプレートはarchive-info.phpを使用しております。
contents部分は新しい記事が上にきて、
投稿する度にひとつずつ増えていく内容になってます。
/custom_post.php (inc/custom_post.php)の記載/
カスタム投稿タイプの設定 info
---------------------------------------------------- */
add_action('init', 'info_custom_init');
function info_custom_init()
{
$labels = array(
'name' => _x('お知らせ', 'post type general name')
);
$args = array(
'labels' => $labels,
'public' => true,
'menu_icon' => 'dashicons-info',
'show_ui' => true,
'capability_type' => 'post',
'has_archive' => true,
'query_var' => false,
'rewrite' => true,
'menu_position' => 5,
'supports' => array('title','editor'),
);
register_post_type('info',$args);
/** * csv importerを使用する際は hierarchical => false にする */ register_taxonomy( 'info_cat', 'info', array( 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => 'お知らせカテゴリ', 'singular_label' => 'お知らせカテゴリ', 'public' => true, 'show_ui' => true, 'rewrite' => array('slug' => 'info' ,'hierarchical' => true), 'menu-order' => true ) );
}
/archive-info.phpのcontents部分/
<?php while ( have_posts() ) : the_post();?> <a href="<?php echo get_post_type_archive_link($post->postname); ?>"> <div class="entry info_block"> <?php $info_cat = wp_get_post_terms($post->ID,'info_cat');?> <span class="info_date"><?php the_time('Y.m.d'); ?></span> <?php if (isset($info_cat[0])): ?> <span class="label <?php echo $info_cat[0]->slug ?> info2"><?php echo $info_cat[0]->name ?></span> <?php endif ?> <br> <span class="info_title"><?php the_title(); ?></span> <div class="info_content"><?php the_content(); ?></div> </div></a> <hr class="info_hr"> <?php endwhile; ?> </div>/function.phpの中身/
<?php /** * 関数 */ include_once (TEMPLATEPATH . '/inc/custom_post.php'); //カスタム投稿タイプ専用 include_once (TEMPLATEPATH . '/inc/shortcode.php'); //ショートコード専用 /** * wp_head() で出力しないように */ remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); remove_action('wp_head', 'rel_canonical'); remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'feed_links_extra', 3); remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles', 10 ); function remove_recent_comments_style() { global $wp_widget_factory; remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')); } add_action('widgets_init', 'remove_recent_comments_style'); /** * the_content出力時に自動で<p><br />を付けないように */ function noautop( $content ) { remove_filter( 'the_content', 'wpautop' ); return $content; } add_filter( 'the_content', 'noautop', 1 ); /** * リッチエディタで全角スペースを残す */ add_filter('tiny_mce_before_init', 'my_tiny_mce_before_init_filter'); function my_tiny_mce_before_init_filter( $init_array ) { $init_array['remove_linebreaks'] = false; return $init_array; } /** * thumbnailを有効化 */ if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); } /** * 日本語などマルチバイトの場合は、{投稿タイプ}-141222に強制的に変更 */ function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) { if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) { $slug = utf8_uri_encode( $post_type ) . '-' . date('ymd'); } return $slug; } add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 ); そこで、個々の投稿も単独で表示させたいと思ったのですが、 パーマリンク設定を/%postname%/に設定(英数字で出力されます)し、 個々から飛ぶリンク先を<?php the_permalink(''); ?>に設定したのですが、404.phpが表示されてしまいます。
何卒よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。