Setting up a custom type for a portfolio – lesson 25

To create a portfolio page, we will need a new data type, if you still don't know what it is, I will tell you a little. Initially, after installation, WordPress has several arbitrary types (Entries, Pages, Media file), we will try to create a new data type portfolio and add categories, same as in standard records. In general, I want to say that if there is an opportunity to do something using the CMS API, it is better to use this opportunity.

In our theme in a folder functions add file custom-type.php in it we will store new file types and taxonomies. For the new file to work, it is necessary to file functions.php paste the connection of the created file as shown in the picture below.

insert custom type file wordpress

After creating and connecting the file, create the data type. To create a data type, you need to use the function register_post_type(), You can read more about it on the official website., in wordpress code. I will talk about my code, which we will use.

By the way, for developing a data type, you can use a good data type generator, but this does not mean that this generator will work forever and you do not need to know how the function works register_post_type().

I think I will write about the data type generator, maybe I'll make my own, and now I'll tell you how everything works on the example of my code.

I won't tell much, I will begin to paint you in order all the attributes passed to the function.

Function attributes register_post_type()

name – generic name for an arbitrary data type, usually written in the plural. Used to display the name in the admin panel.

name custom post type wordpress cms

singular_name – data type name in single number.

menu_name – the name of the new type in the menu, in our case it is portfolio.

menu name portfolio post type wordpress

parent_item_colon – label to display the parent entry, write in single.

all_items – label for all entries. By default for all records of this type ‘Parent work:’.

view_item – text to view record of this type ‘View work’.

view wordpress custom post type portfolio

add_new_item – caption on the button to add a new entry.

add_new – add new post button next to title.

wordpres add new button post

edit_item – title for edited post.

edit wordpress title post

search_items – change the inscription to what we need.

wordpress search post types button

not_found – default caption, if there are no records of this type.

wordpress not found post custom type

not_found_in_trash – an inscription in an empty basket “No entries found”.

wordpress not found tresh page

slug – a label in a link of this type, important to think about, how to call it.

wordpress portfolio slug custom post type

with_front – allows you to display a stronger link. If the value is true, then the linked post will be displayed like this /news/, if false, the link will look like this /blog/news/. I think it's right to set the default to true for now.

pages – true by default, by default pagination is allowed for individual posts. If this parameter is set to false, then you won't be able to use the short tag (<!–nextpage–>) to insert pagination inside a post.

feeds – by specifying this parameter in (true), we can determine if this type of data will be displayed in the rss feed.

label – plural data type label.

description – short description for data type.

supports – inclusion of additional functionality, the same functionality can be enabled after the data type has been created using the add_post_type_support function(). Consider everything that can be enabled using this function..

title – post title.

wordpress custom type enable title

• editor (content) – renders an input field for page content.

wordpress content area enable• author – selecting an author from a list of available users.

wordpress custom post type author• thumbnail (featured image) – post thumbnail support.

wordpress fatured image enable in custom post type

• excerpt – short recording area activation. Who is not aware, if we enter this area, then when displaying the archive of records, this text will be displayed. Very useful for SEO.

wordpress custom post type excerpt - wordpress courses custom-fields – enable metabox with custom fields, we will talk about them.
comments – viewing the list of comments on the article left by others and the ability to leave it yourself in the admin panel.

wordpress comment metabox admin panel

page-attributes – displays page attributes, e.g. the order of the records. Rarely used, I saw the use only once in one template, there it was really necessary.

wordpress custom post atribut

post-formats – adds page formats, if necessary, I will tell about them in the future.

hierarchical – enable and disable custom hierarchy. Until we need this item.

public – determines the visibility of the custom post type in the admin panel and in the client side.

menu_position – denotes a position of a custom type in the admin panel.

wordpress post type menu position

show_ui – hides the new type in the admin panel, as in the menu, same in admin bar. You can work with the type, but only by means of code.

show_in_menu – hides the new type only in the custom menu.

display type in wordpress menu

show_in_admin_bar – specify to display or not display an arbitrary type in the menu.

wordpress show in admin bar

In step 2 no submenu for new data type.

menu_icon – shows the path to the icon for the menu

wordpress menu icon - wordpress courses

can_export – the ability to export data of an arbitrary data type.

has_archive – output data in list as archive (also how records are displayed).

exclude_from_search – exclude this data type from search.

publicly_queryable – the ability to make requests from the user part.

query_var – sets the key to this type, used for queries.

rewrite – setting links to a new type.

capability_type – we take permission settings from another data type.

Lesson is a bit long, so I decided to break it down into several lessons. Follow the WordPress course, new lessons coming soon.


Buy WordPress hosting
WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal