PostPack WordPress post archive with description

I have a common design template. I'm not quite sure what is the best way to accomplish in WordPress. The layout is a list of mail teasers (name, cropped body, image) on the overview page. Let say example.com is a boat safety company, and example.com/classes has a list of its class type entries using archive.php or archive- $ posttype.php

So far, this is the dead simple and default behavior of WordPress. But, I want to get some background information about this type of information in general on this overview page. Also, suppose I have 10 custom message types hypothetically, and each of them will follow this template with a listing and a general introductory paragraph on the archive page.

What I don't want to do is a page for each of these types, and a user request is executed for each of them in the page template. If there was a way to associate the description and even the best custom fields with the type of message itself (and not on messages of this type, except for the type itself), this would be an ideal scenario. Ideally, I would like all of this to be included in my archive.php template.

Does anyone know a good way to take this off?

This may or may not be useful, but I will create message types in the code, but using additional custom fields for my own fields.

+5
source share
2 answers

read when creating message types there is an option for the archive to exist, set it to none, it will not create standard URLs for viewing the list, etc. You can modify archive.php to include all message types.

I think you are confused by the way WordPress custom post types exist on your server. Basically, they exist only in php code, so every time the wp system boots up, your custom code starts to create a custom message type ... basically you set message type rules at this point - like this

  • Custom message type name
  • Arguments for the post type (google post type)
  • Custom taxonomy
  • Meta boxes for the admin screen (recommended instead of using custom fields ...)

Wordpress, if he sees that posttype is public, and has_archive will allow any url requests for post-type with the appropriate template ... for example, the message type is "mypost". In this case, by typing www.example.com/mypost, you will return the archive view from your topic (archive.php or archive-mypost.php). This file is in your topic, and you can change it to include an archive of all types of messages (replace get_posts with wp_query for full control over messages)

On these archive pages, you will see a function called get_posts / wp_query, and then the standard loop structure for looping through each element. These functions query the wp_posts table in the database to return rows with the post_type query (querying the function to search for) (see DB and the post_type column in wp_posts). There is also a secondary table for storing unlimited additional fields (I don’t literally take me there, but in theory and memory limitations pushed aside, there is no limit set by WP on additional fields) in the post_meta table, which uses post id (a unique identifier for the string in wp_posts ) You can display this information using get_post_meta () (google it)

So where do you assume the theme is installed? (best to create a children's theme here)

  • create your custom message types in function file with has_archive value false in an array of arguments
  • Add meta-field function for custom fields that you want in your function file (google this, very easy to do)
  • Modify archive.php file to start a new query for all message types (google wp_query, you can request an array of message types)
  • Any other data, such as descriptions, default behavior, can be set using php in your functions file and connected to the action you want to change (for example, save a message, etc.).
+1
source

register_post_type() has a description of arg , which by default contains an empty string. You can use this and get a description, for example:

 $obj = get_post_type_object( 'my_post_type' ); echo $obj->description; 
0
source

Source: https://habr.com/ru/post/1206845/


All Articles