[Resolved] I have created a custom post type, how do I load its content

Home Forums Support [Resolved] I have created a custom post type, how do I load its content

Home Forums Support I have created a custom post type, how do I load its content

  • This topic has 12 replies, 2 voices, and was last updated 1 year ago by David.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #2570789
    lionet

    I have created a custom post type, how do I load its content, I have made a template into a plug-in, which is convenient for maintenance, how do I do it?

    #2570807
    lionet


    But, If you do not create a specific template, then WP would use the themes single.php.
    Then you can use a Block element Content Template to design the CPT, by setting the Display Rules Location to the Custom Post Type Name.
    This methods means you don’t require a custom template unless there are code specific things you need to change.”

    https://generatepress.com/forums/search/How+to+display+custom+types/

    I saw this answer in this post. This is what I want. I just want to display the default GP theme template, but I don’t know how to set it up. If I need to add code, I hope it will be added to the custom plugin. If not, add it code, that’s even better. Because you don’t want to break your custom code by updating.

    #2570816
    lionet

    By the way, I need to add products and pages, and I want to manage products separately, so I just registered the new post type, if there is another way that is better, please let me know.

    #2570923
    David
    Staff
    Customer Support

    Hi there,

    you can try using the Block Element – Content Template.

    https://docs.generatepress.com/article/block-element-content-template/

    1, go to Appearance > Elements –> Add New —> Block Element.
    2. set the Element Type to Content Template
    3. In the editor add a Post Content block.
    4. Set the Display Rules -> Location to your single post type.
    5. Publish this.

    Then check if it shows your posts.
    If it does you can edit the block element and design it and add other dynamic data as you need.

    #2572022
    lionet

    I’m a little dizzy looking at it, the documentation is too simple, I know that you can use element block positioning to make different templates, which works great.

    However, I’m still figuring it out, like if I want to create a new menu and post type for others to use, how do I set this field only?

    I looked at the settings and it seems that only terms and custom fields can be used.
    Don’t see custom post types.

    #2572027
    lionet

    I have to say the design is really cool. But the usage docs are terrible. I’m not smart enough to know all of its features just by looking at a little description. Hahaha

    #2572059
    David
    Staff
    Customer Support

    The Block Element is only means to displaying the content ie. you are making a template to display your data.
    What it cannot do is create the fields you may need on your custom post type.

    Did you follow the steps i provided above? And did you see any thing on your custom post types ?

    #2572307
    lionet

    Opening the link before I set it shows 404

    I do this step:
    【4. Set the Display Rules -> Location to your single post type.】

    But the page will now 301 to the homepage.

    I don’t know where I went wrong, hahaha.

    #2572326
    lionet

    I tried the steps on a test site, all ok. Now we can know that it is not a gp problem.

    #2572338
    lionet

    I know the problem, I set the data, and then 404, but rank math gave it 301 (I have confirmed that the 301 function is turned off, but it still automatically 301, which makes me don’t know why this happens, after After checking, only this plugin has this function, I uninstalled it. Now everything is fine.)

    My problem solved, GPP is awesome, it does what I want, I’ve removed the 3 plugins I had to install before, it’s great.

    I don’t know where these configuration options can be used, can you tell me.

    Tag name
    Select the tag names to apply to the content template.

    Apply to
    Set the condition which the content template is applied to.

    #2572425
    David
    Staff
    Customer Support

    Glad to hear that 🙂

    Tag Name: this changes the HTML wrapper of your template it defaults as <article> and in most cases you can leave it as is.

    Apply to: for most cases and particulary a single post you can leave that on the default All posts.

    For more complex scenarios on say an archive page, you can create a template that only applies to the first post or posts with a specific term, allowing you to mix content templates. See here for an example:

    https://www.youtube.com/watch?v=8byA37OTBRg

    #2572677
    lionet

    Thank you so much. This solved my problem.

    #2572879
    David
    Staff
    Customer Support

    You’re welcome!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.