• НАЧАЛО
  • Услуги

AIT WEB DESIGN - изработка на сайт и СЕО оптимизация

  • НАЧАЛО
  • Услуги
  • No products in cart.
  • Начало
  • Wordpress
  • Създаване на „Custom post types“ в WordPress
15.04.2026

Създаване на „Custom post types“ в WordPress

Създаване на „Custom post types“ в WordPress

by afilipov / неделя, 19 юни 2016 / Published in Wordpress

Влезте в папката на вашата тема и отворете файла 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();?>
  • Tweet

What you can read next

Как да променим SKU label-а във Woocommerce към Product Code
Как сами да си създадем Widget в WordPress
Полезни модули за WordPress

Търсене

Категории

  • CSS
  • SEO Оптимизация
  • WooCommerce
  • Wordpress
  • WordPress Модули
  • Код оптимизация
  • Трикове

Архиви

  • февруари 2026
  • юли 2020
  • юли 2018
  • февруари 2018
  • август 2017
  • март 2017
  • ноември 2016
  • октомври 2016
  • септември 2016
  • август 2016
  • юли 2016
  • юни 2016
  • май 2016
  • март 2016
  • юли 2012

УСЛУГИ

ВРЪЗКА С НАС

(+359) 888 898 797
Email: office@ait-webdesign.com

AIT WEB DESIGN
6300 Хасково, Ул. Хан Аспарух 9-11. България

Отвори в Google Maps

ПОСЛЕДНО ЗАВЪРШЕНИ ПРОЕКТИ

Етикети

  • НАЧАЛО
  • Услуги

Всички права запазени AIT WEB DESIGN 2026

НАГОРЕ