php 投稿にアーカイブ(投稿一覧)を持たせるように

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 投稿にアーカイブ(投稿一覧)を持たせるように相关的知识,希望对你有一定的参考价值。


/*
 * 投稿にアーカイブ(投稿一覧)を持たせるようにします。
 * ※ 記載後にパーマリンク設定で「変更を保存」してください。
 */
 ↓こっちのがいいかも
 add_filter( 'register_post_type_args', function( $args, $post_type ) {
    global $wp_rewrite;
    if ( 'post' === $post_type ) {
        $archive_slug = 'column/news';
        // Setting 'has_archive' ensures get_post_type_archive_template() returns an archive.php template.
        $args['has_archive'] = $archive_slug;
        // We have to register rewrite rules, because WordPress won't do it for us unless $args['rewrite'] is true.
        $archive_slug = $wp_rewrite->root . $archive_slug;
        add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
        $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
        add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
        add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
        add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
    }
    return $args;
}, 10, 2 );



↓こっちも使える
function post_has_archive( $args, $post_type ) {
	if ( 'post' == $post_type ) {
		$args['rewrite'] = true;
		$args['has_archive'] = 'column/news'; // ページ名
	}
	return $args;
}
add_filter( 'register_post_type_args', 'post_has_archive', 10, 2 );

以上是关于php 投稿にアーカイブ(投稿一覧)を持たせるように的主要内容,如果未能解决你的问题,请参考以下文章

php 投稿にアーカイブ(投稿一覧)を持たせる

php カスタム投稿の子カテゴリ记事一覧表示(アクセスしているカテゴリーアーカイブを自动判别)

php アーカイブタイトルの「アーカイブ:」を削除

text 书いた英语アーカイブ

php 投稿一覧に「サムネイル」「ID」「スラッグ」」文字数」の4项目を追加

php 投稿一覧に「サムネイル」「ID」「スラッグ」」文字数」の4项目を追加