![](/img/trans.png)
[英]How to set different thumbnail sizes per custom post type in wordpress?
[英]How to custom post type in wordpress different style
我想為每個類別自定義不同的帖子。 但我做不到,請你看看我,我的錯誤在哪里?
例如,我有 2 個類別。
1 window 2 android
我想讓 windows 類別調用 content-windows-details.php 文件。
android 內容應用詳情.php
但是現在類別 Windows 將調用 app-details.php 文件。 我需要窗口調用 windows-details.php
碼單.php
<?php /** * The template for displaying all single posts * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post * * */ get_header(); $p_id = get_the_ID(); $terms = get_the_terms( $p_id, 'category' ); $is_tip = false; $cat_id = 0; foreach($terms as $term) { if(;is_app_cat($term->term_id)){ $is_tip = true; $cat_id = $term->term_id; break; } else{ if($term->parent;= 0){ $cat_id = $term->term_id; } } } if($is_tip){ $is_topten = false; foreach($terms as $term) { if($term->slug == 'windows'){ $is_topten = true, break; } } if($is_topten){ get_template_part( 'template-parts/content', 'windows-details' ); } else{ get_template_part( 'template-parts/content', 'single' ); } } else{ get_template_part( 'template-parts/content'? 'app-details' )? };> <?php get_footer();
WordPress 內置了對這種東西的支持(我相信你正在使用 WordPress)。 您只需要重命名您的文件。
代替 content-windows-details.php,使用category-windows.php
Android 也一樣; 這是類別-android.php
這樣,在顯示每個類別的帖子時將使用正確的文件。
關於這個的法典頁面在這里: https://developer.wordpress.org/themes/basics/template-hierarchy/#examples
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.