[Support request] [GP Beta] generate_do_template_part does not call the content

Home Forums Support [GP Beta] generate_do_template_part does not call the content

  • This topic has 4 replies, 3 voices, and was last updated 4 months ago by Tom.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1449649
    Laurent

    Hi,

    I’m testing GP 3.0 Beta which is great so far. However I have a problem that I can’t figure out.

    I’ve a CPT ‘formation’.

    In single-formation.php, if I have the line

    get_template_part( 'content', 'formation' );

    it displays the content as in 2.7

    If I replace the line with :

    generate_do_template_part( 'content', 'formation' );

    It shows nothing.

    What Am I doing wrong ?

    Thanks

    #1449670
    Laurent

    Looking into the function code, it seems it does not handle CPTs ? There’s only one parameter.

    Should I keep using get_template_part() for CPTs ?

    #1449711
    David
    Staff
    Customer Support

    Hi there,

    Tom provides an example here:

    https://generatepress.com/forums/topic/question-about-gp-3-0-and-generate_do_template_part/#post-1429909

    The CPT would of course need to be built upon the GP template for the function to exist.

    #1449721
    Laurent

    I saw that but didn’t understand, now I think I do.

    I can either :

    – keep using get_template_part within child theme templates as default wordpress behavior

    or

    – use generate_do_template_part, remove the child theme templates and use a add_action( ‘generate_before_do_template_part’, function…) which would check the post_type and displays information accordingly

    Using the later opens up possibilities of calling those from Elements and other places in the code. Did I get this right ?

    Thanks

    #1450158
    Tom
    Lead Developer
    Lead Developer

    Exactly! There’s nothing wrong with keeping the core get_template_part() if you’re already using a child theme.

    generate_do_template_part() simply allows for a way to remove the default get_template_part() and add your own loop item without the need for a child theme template 🙂

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