Влезте в папката на вашата тема и отворете файла functions.php.
Извикайте файла city.php.
require_once ('functions/city.php');
city.php
add_action( 'init', 'city_register'); function city_register() { $labels = array( 'name' => _x('Cities', 'post type general name'), 'singular_name' => _x('City', 'post type singular name'), 'add_new' => _x('Add New', 'City'), 'add_new_item' => __('Add New City'), 'edit_item' => __('Edit City'), 'new_item' => __('New City'), 'all_items' => __('All Cities'), 'view_item' => __('View Cities'), 'search_items' => __('Search Cities'), 'not_found' => __('No cities found'), 'not_found_in_trash' => __('No cities found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Cities' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'), 'menu_icon' => 'dashicons-flag' ); register_post_type('city', $args); }
След като вече сте създали новия тип постове, може да го извикате в предната част на сайта по следният начин:
template-city.php
<?php $args = array( 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order'=>'ASC', 'post_type' => 'city'); query_posts($args); $lastposts = get_posts( $args ); ?> <?php foreach ( $lastposts as $post ) : $post_orig = $post; setup_postdata( $post ); ?> <div class="city"> <h3><?php the_title(); ?></h3> <div class="thumb"> <?php the_post_thumbnail(array(500, 500)); ?> </div> <?php the_content(); ?> </div> <?php endforeach; ?> <?php wp_reset_postdata();?> <?php wp_reset_query();?>