[Support request] Custom navigation on CPT

Home Forums Support [Support request] Custom navigation on CPT

Home Forums Support Custom navigation on CPT

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #823539
    Michele

    Hi guys! I’m working on a new project and I’d love to use the custom post navigation from Volume (site library).

    The GP element is doing its job on the single post template, but how can make It work on May custom post type as well?

    PS: already tried the display rules with no effects

    Thanks in Advance!

    #823548
    David
    Staff
    Customer Support

    Hi there,

    if you go to Appearance > Elements –> Edit the Custom Post navigation
    Does your post type show up in the Display rules? Currently it is set to display on the single Post.

    #823556
    Michele

    Ehi David,
    Yep, it shows up, but if I set in addiction my cpt that element is applied anyway only to normal posts.

    #823578
    Tom
    Lead Developer
    Lead Developer

    Any chance you can show us a screenshot of your Display Rules, and link us to one of your custom post types posts?

    #823590
    Michele

    Ehi Tom!
    Here you have the screenshot of my element’s settings:

    Element settings

    And this is a link to one of my custom post type > https://www.graffette.net/case-history/la-bionda/

    Thanks in advance!

    #823903
    Tom
    Lead Developer
    Lead Developer

    That post seems to be a post inside the case-history post type. What if you add that Case History cpt to your Display Rules?

    #824104
    Michele

    Nope Tom, I have just one custom post type on this website. It’s just a matter of labelling, as you can see:

    function cptui_register_my_cpts_case_history() {
    
    	/**
    	 * Post Type: Progetti.
    	 */
    
    	$labels = array(
    		"name" => __( "Progetti", "custom-post-type-ui" ),
    		"singular_name" => __( "Progetto", "custom-post-type-ui" ),...
    #824736
    Tom
    Lead Developer
    Lead Developer

    Do you have anything registered as case-history?

    #824746
    Michele

    Nope Tom, just the cpt I mentioned above and a custom taxonomy named categoria_progetti.

    Why you ask me this?

    #825088
    Tom
    Lead Developer
    Lead Developer

    The post you linked me to has this class added to the body element: https://www.screencast.com/t/wTSA9s9lV46

    WordPress only adds the single-xx class with the name of the custom post type. So as far as the code is showing, that post is a part of a custom post type named “Case History”.

    #825293
    Michele

    mmm… Yes, the cpt is named “case_history” but simply I changed the labels for being more italian friendly.

    Indeed, as you can see, I used another element to show something only on that specific cpt archive. This is the secundary navigation (in the element UI you can read ‘Progetti’:

    Secundary Navigation Element

    In this page you can see it in action.

    So I think the problem is not the cpt name, but something maybe in the element code not compatible?

    <div id="post-nav">
    	<?php global $post;
        $prevPost = get_previous_post(false);
            if($prevPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $prevPost->ID
                );
                $prevPost = get_posts($args);
                foreach ($prevPost as $post) {
                    setup_postdata($post);
        ?>
            <a class="post-previous" href="<?php the_permalink(); ?>">
    				<div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.1),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url("large"); ?>');">
                <div class="post-nav">Precedente</div>
                <h3 class="post-nav-title"><?php the_title(); ?></h3>
            </div></a>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
             
            $nextPost = get_next_post(false);
            if($nextPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $nextPost->ID
                );
                $nextPost = get_posts($args);
                foreach ($nextPost as $post) {
                    setup_postdata($post);
        ?>
            <a class="post-next" href="<?php the_permalink(); ?>">
            <div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.6),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');">
                <h3 class="post-nav-title"><?php the_title(); ?></h3>
                <div class="post-nav">Successivo</div>					
            </div></a>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
        ?>
    </div>
    #825778
    Tom
    Lead Developer
    Lead Developer

    Hmm, which hook are you adding it to?

    #825824
    Michele

    The secundary navigation is shown in the after_archive_title hook, while the custom post navigation is in before_footer.

    Then I’ve added some php to show the post meta, comments etc.. But I prefer to give you the code maybe in a private session, if it’s possible. Is it?

    #826084
    Tom
    Lead Developer
    Lead Developer

    I think I see the issue.

    get_previous_post() and get_next_post() don’t seem to work with custom post types by default.

    Did some searching and didn’t find anything concrete, unfortunately. One thing you could try is replacing:

    get_previous_post(false);

    With:

    get_previous_post(true);

    And

    get_next_post(false);

    With:

    get_next_post(true);

    Not sure if it will work, but it’s worth a shot.

    #826241
    Michele

    Ehi Tom, I tried to apply your tip but it didn’t work. 🙁

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