另一个完成类似任务的好方法是利用WordPressCustom Post Types.
您可以在WordPress后端设置3种不同类型的功能,以便于使用。
首先,设置自定义帖子类型要做到这一点,请打开主题的功能。php文件,并包括以下内容:
<?php
function custom_register_post_types() {
$labels = array(
\'name\' => _x(\'People\', \'post type general name\'),
\'singular_name\' => _x(\'Person\', \'post type singular name\'),
\'add_new\' => __(\'Add New\'),
\'add_new_item\' => __(\'Add New Person\'),
\'edit_item\' => __(\'Edit Person\'),
\'new_item\' => __(\'New Person\'),
\'view_item\' => __(\'View Person\'),
\'search_items\' => __(\'Search People\'),
\'not_found\' => __(\'No People found\'),
\'not_found_in_trash\' => __(\'No People found in Trash\'),
\'menu_name\' => \'People\'
);
$rewrite = array(
\'slug\' => \'people\'
);
$supports = array(\'title\',\'editor\');
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_menu\' => true,
\'query_var\' => \'people\',
\'rewrite\' => $rewrite,
\'has_archive\' => true,
\'hierarchical\' => false,
\'supports\' => $supports
);
register_post_type(\'people\',$args);
$labels = array(
\'name\' => _x(\'Places\', \'post type general name\'),
\'singular_name\' => _x(\'Place\', \'post type singular name\'),
\'add_new\' => __(\'Add New\'),
\'add_new_item\' => __(\'Add New Place\'),
\'edit_item\' => __(\'Edit Place\'),
\'new_item\' => __(\'New Place\'),
\'view_item\' => __(\'View Place\'),
\'search_items\' => __(\'Search Places\'),
\'not_found\' => __(\'No Places found\'),
\'not_found_in_trash\' => __(\'No Places found in Trash\'),
\'menu_name\' => \'Places\'
);
$rewrite = array(
\'slug\' => \'places\'
);
$supports = array(\'title\',\'editor\');
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_menu\' => true,
\'query_var\' => \'places\',
\'rewrite\' => $rewrite,
\'has_archive\' => true,
\'hierarchical\' => false,
\'supports\' => $supports
);
register_post_type(\'places\',$args);
$labels = array(
\'name\' => _x(\'Things\', \'post type general name\'),
\'singular_name\' => _x(\'Thing\', \'post type singular name\'),
\'add_new\' => __(\'Add New\'),
\'add_new_item\' => __(\'Add New Thing\'),
\'edit_item\' => __(\'Edit Thing\'),
\'new_item\' => __(\'New Thing\'),
\'view_item\' => __(\'View Thing\'),
\'search_items\' => __(\'Search Things\'),
\'not_found\' => __(\'No Things found\'),
\'not_found_in_trash\' => __(\'No Things found in Trash\'),
\'menu_name\' => \'Things\'
);
$rewrite = array(
\'slug\' => \'things\'
);
$supports = array(\'title\',\'editor\');
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_menu\' => true,
\'query_var\' => \'things\',
\'rewrite\' => $rewrite,
\'has_archive\' => true,
\'hierarchical\' => false,
\'supports\' => $supports
);
register_post_type(\'things\',$args);
}
add_action(\'init\', \'custom_register_post_types\', 0);
?>
我已经写了一篇关于这段代码细节的参考文献
here.您也可以在
codex.
这将要做的是在WordPress的主左侧导航中设置3个新菜单,为这些类型的每种类型在界面中提供自己的空间。在这种情况下,人、地方和事物。(从逻辑上进行自定义以满足您的需要)现在,这些设置只显示标题栏和编辑器窗格。
在你的主页上查询要使用的帖子类型,我喜欢设置新的查询对象,以保持所有内容都很好和独立。此外,您还可以在其他循环中调用对象,这有时很方便。将这些(或定制的适合您需要的东西)混合到您的模板中,以将它们带到所需的页面中。
<?php
$args = array( \'post_type\' => \'people\', \'numberposts\' => \'1\' );
$people = new WP_Query($args);
if ( $people->have_posts() ) :
while ( $people->have_posts() ) :
$people->the_post();
global $more;
$more = 0;
?>
<div id="people-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-entry">
<div class="post-title">
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="post-content">
<?php edit_post_link( \'Edit\', \'<h5 class="edit-link">\', \'</h5>\' ); ?>
<?php the_content(); ?>
</div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
<?php
$args = array( \'post_type\' => \'places\', \'numberposts\' => \'1\' );
$places = new WP_Query($args);
if ( $places->have_posts() ) :
while ( $places->have_posts() ) :
$places->the_post();
global $more;
$more = 0;
?>
<div id="places-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-entry">
<div class="post-title">
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="post-content">
<?php edit_post_link( \'Edit\', \'<h5 class="edit-link">\', \'</h5>\' ); ?>
<?php the_content(); ?>
</div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
<?php
$args = array( \'post_type\' => \'things\', \'numberposts\' => \'1\' );
$things = new WP_Query($args);
if ( $things->have_posts() ) :
while ( $things->have_posts() ) :
$things->the_post();
global $more;
$more = 0;
?>
<div id="things-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-entry">
<div class="post-title">
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="post-content">
<?php edit_post_link( \'Edit\', \'<h5 class="edit-link">\', \'</h5>\' ); ?>
<?php the_content(); ?>
</div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
这些只是一些快速而肮脏的示例,说明了如何设置查询和循环。这些将只设置并显示每个自定义帖子类型中的最新帖子或热门帖子。
有关WP\\U查询类的更多说明,请参见here. 其他一切都是HTML和CSS。
享受