[英]SHould I Use a Wordpress 3.0 Custom Post Type?
我正在為雜志編寫wordpress主題。 該網站的一方面是首頁是靜態的,並且在首頁的某個區域顯示了本期的雜志。 我需要幫助,以找出最實用的方法來替換主頁上最新一期的內容。
基本上,每個月,圖像,標題以及一小段文字都會在首頁上發生變化。 我的主頁是一個靜態頁面(來自模板)。 我希望客戶端能夠從wordpress的后端更改圖片/文本。 也就是說,最好的方法是編寫自定義帖子類型?
這與博客無關(帖子部分)。 解決這個問題的方法可能非常簡單。 有任何想法嗎?
是! 解決方案是自定義帖子類型。 答案在此處完整列出: 鏈接文本
基本上,我將此添加到我的functions.php文件中:
add_action('init','create_my_post_types');
function create_my_post_types() {
register_post_type( 'current_issue',
array(
'labels' => array(
'name' => __( 'Current Issues' ),
'singular_name' => __( 'Current Issue' )
),
'public' => true,
'exclude_from_search' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
)
);
}
然后將其添加到我的homepage.php文件中:
<?php $loop = new WP_Query( array( 'post_type' => 'current_issue', 'posts_per_page' => 1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_post_thumbnail( 'current-issue' ); ?>
<?php the_title( '<h2><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
<div class="readmore" style="margin-top:4px">
<a href="#">Read More</a>
</div>
<?php the_content(); ?>
<?php endwhile; ?>
效果很好!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.