[Resolved] Unable to Create Navigation for CPT Using PHP

Home Forums Support [Resolved] Unable to Create Navigation for CPT Using PHP

Home Forums Support Unable to Create Navigation for CPT Using PHP

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1929525
    Ken

    Hi,
    I found the following code in GP Docs:

    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta() {
        if ( is_singular( 'your-post-type' ) ) : ?>
            <footer class="entry-meta">
                <?php generate_entry_meta(); ?>
                <?php generate_content_nav( 'nav-below' ); ?>
            </footer><!-- .entry-meta -->
        <?php endif;
    }

    I then added my custom post types to get the following php and added it to my GP-Child-PHP at the bottom.

    add_action( 'generate_after_entry_content', 'tu_cpt_footer_meta' );
    function tu_cpt_footer_meta() {
        if ( is_singular( 'list_post','one_product','ten_product','five_product','how_to' ) ) : ?>
            <footer class="entry-meta">
                <?php generate_entry_meta(); ?>
                <?php generate_content_nav( 'nav-below' ); ?>
            </footer><!-- .entry-meta -->
        <?php endif;
    }

    Problem: it’s not working for 4 of the CPT, and I’m getting
    TEST
    TEST
    For the ‘list_post’
    Please see VDO and links below.
    Thank you for your time and help.

    If at first you don't succeed, skydiving is not for you.

    #1929530
    Ken

    Sorry, forgot to add, I’d be happy either way with
    1. previous <-> next
    OR
    2. Previous CPT Name <-> Next CPT Name

    If at first you don't succeed, skydiving is not for you.

    #1929600
    Elvin
    Staff
    Customer Support

    Hi Ken,

    Any particular reason why you must add the navigation using a hook?

    Consider using Block Element - Post navigation.

    With this, you can create your own template for post navigation for CPT using Block editor. You can set whatever text and styling to want to place on it.

    A wise man once said:
    "Have you cleared your cache?"

    #1929618
    Ken

    Elvin, ahh, didn’t think of Elements, it’s still pretty new to me.
    Anyhow, sorry it’s still not working
    > nothing for 4 of the 5 CPT
    > test test for the list post
    what I did:
    > Elements > Element Type: Post Navigation > hook name; after_do_template_part

    Display Rules;
    All Singular
    Post > All Posts
    List > All Lists (CPT)
    Special Find > All Special Finds (CPT)
    Collection > All Collections (CPT)
    Trending > All Trending (CPT)
    How to > All How to (CPT)

    Is there something else I need to do?

    If at first you don't succeed, skydiving is not for you.

    #1929632
    Ken

    Okay, I forgot to delete the earlier code i used in the php. after doing that I selected a template from the Element Post Navigation > Element > Template. Still no navigation links below the CPT, works great for all other regular WP Posts.

    If at first you don't succeed, skydiving is not for you.

    #1929635
    Elvin
    Staff
    Customer Support

    Elvin, ahh, didn’t think of Elements, it’s still pretty new to me.

    You’re missing out. It’s a good thing to learn.

    Here’s an example. https://share.getcloudapp.com/rRubmE7K

    You can completely skip that PHP snippet if you do this. 😀

    A wise man once said:
    "Have you cleared your cache?"

    #1929639
    Ken

    However it’s still not working. Can’t figure out what’s wrong.
    Sending a link to the “special_find” (one product cpt)

    If at first you don't succeed, skydiving is not for you.

    #1929828
    Elvin
    Staff
    Customer Support

    Are you using a child theme template for this CPT? (ex. content-special_find.php)

    The block element should work as is.

    see this example post – https://dev-generate-press.pantheonsite.io/?movies=veritatis-velit-quia-inventore

    It’s a CPT “movies”. On the bottom of the post, you’ll see a styled post navigation. This is done w/ Block ELement – Post navigation with the display rule and other settings shown here – https://share.getcloudapp.com/rRubmE7K

    No codes required. On a clean GeneratePress install (no child theme template for movies CPT)

    You can let us have backend access if you need help in checking things. You can use the private information text field for the details. 😀

    A wise man once said:
    "Have you cleared your cache?"

    #1929835
    Ken

    Hi Elvin,
    Yes I think so. I using GP Child theme and my coach helped me set up the CPT.
    Boy, I’d sure appreciate if you have the time to check it out.

    It’s a temporary, 7 days, link to my dashboard.

    If at first you don't succeed, skydiving is not for you.

    #1929842
    Ken

    Also, yes, I set the “display rules” for the regular post and all FIVE CPT. Only the regular posts show the Element is working, but the Element is not working with the 5-CPT that I selected under “display rules”

    am I forgetting something?

    If at first you don't succeed, skydiving is not for you.

    #1930801
    Ken

    Problem is solved!
    Solution: I’m changing all my Custom Post Types to regular WP Posts. Fortunately there’s not that many to change and redirect. \(*<>*)/

    I’m spending too much time fiddling with these CPT and taking your valuable time as well–not good.
    I’m deeply grateful for all the help you have given me and getting me started with using Elements. Wow!

    Not all is lost. My Coach provided folks who don’t have the CPT with HTML code that we could use with Gute Blocks that gives the same result as the custom post types.

    Again, thank you so much for your help over the past month. I hope I can sort out any future problems on my own and if not, only then come here for the “Best Theme Support on This Side of the Internet Galaxy!” ٩( ᐛ )و

    If at first you don't succeed, skydiving is not for you.

    #1930828
    Elvin
    Staff
    Customer Support

    Thanks for letting us know. Glad you got it sorted. 😀

    A wise man once said:
    "Have you cleared your cache?"

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