最好的方法是注册a custom post type 然后在项目页面模板中循环该类型。
CPT来自GenerateWP.
if ( ! function_exists(\'projects\') ) {
// Register Custom Post Type
function projects() {
$labels = array(
\'name\' => _x( \'Projects\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Project\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Projects\', \'text_domain\' ),
\'name_admin_bar\' => __( \'Projects\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Project:\', \'text_domain\' ),
\'all_items\' => __( \'All Projects\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Project\', \'text_domain\' ),
\'add_new\' => __( \'Add New\', \'text_domain\' ),
\'new_item\' => __( \'New Project\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Project\', \'text_domain\' ),
\'update_item\' => __( \'Update Project\', \'text_domain\' ),
\'view_item\' => __( \'View Project\', \'text_domain\' ),
\'search_items\' => __( \'Search Projects\', \'text_domain\' ),
\'not_found\' => __( \'Not found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'text_domain\' ),
\'items_list\' => __( \'Projects list\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Projects list navigation\', \'text_domain\' ),
\'filter_items_list\' => __( \'Filter project list\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'project\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
$args = array(
\'label\' => __( \'Project\', \'text_domain\' ),
\'description\' => __( \'A Single Project\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'custom-fields\', ),
\'taxonomies\' => array( \'category\', \'post_tag\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-media-document\',
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'capability_type\' => \'page\',
);
register_post_type( \'projects\', $args );
}
add_action( \'init\', \'projects\', 0 );
}
在您的
Projects Template
运行您的
custom loop.
<?php
/*
* Template Name: Projects Page Template
* Description: Page template to display projects custom post types
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// WP_Query arguments
$args = array (
\'post_type\' => \'projects\',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
// PROJECT
$query->the_post(); ?>
<h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
<?php the_field(\'description\'); ?>
<hr><?php
}
} else { ?>
<p>There are no posts or pages here</p>
<?php }
// Restore original Post Data
wp_reset_postdata();
// The Content
echo apply_filters( \'the_content\', get_the_content() );
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
您可以创建页面
/projects
并将模板设置为
Projects Template
这将列出您的所有项目
/project/project-title
.
但如果你想在帖子中添加额外的字段并将其标记为项目,那么这更像是一个循环问题。