Site logo

Archived topic

Custom navigation on CPT

20 replies · Started by Michele on February 27, 2019

Viewing posts 1–15 of 21

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!

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.

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

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

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?

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" ),...

Do you have anything registered as case-history?

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

Why you ask me this?

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".

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>

Hmm, which hook are you adding it to?

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?

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.

Ehi Tom, I tried to apply your tip but it didn't work. :(

This archived topic is closed to new replies.