2010-08-10 74 views
0

我正在编写一本杂志的wordpress主题。该网站的一个方面是,该网页是静态的,并且在主页的一个区域中包含杂志的当前版本。我需要帮助,找出替换主页上最近期问题的最实用的方法。应该使用Wordpress 3.0自定义帖子类型吗?

基本上,每个月,主页上的图像以及标题和一小段文字都会改变。我的主页是静态页面(来自模板)。我希望客户能够更改wordpress后端的图片/文字。也就是说,最好的方法是写一个自定义的帖子类型?

这与博客(帖子部分)无关。这可能是一个非常简单的方法。有任何想法吗?

回答

1

是的!自定义帖子类型是解决方案。答案就在这里完全概括:link text

基本上,我已将此添加到我的functions.php文件:

ADD_ACTION( '初始化', '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; ?> 

它完美!

相关问题