[Resolved] Display content in single CPT

Home Forums Support [Resolved] Display content in single CPT

Home Forums Support Display content in single CPT

Viewing 15 posts - 16 through 30 (of 46 total)
  • Author
    Posts
  • #682378
    Tom
    Lead Developer
    Lead Developer

    This has been pretty stumped, it should be working. I’m on the road until tomorrow so I don’t have a localhost to test with, unfortunately.

    One more thing to try before I get back into the office tomorrow to figure out exactly why it’s not working:

    add_action( 'generate_after_content', function() {
        if ( is_singular( 'your-post-type-name' ) ) {
            previous_post_link();
            next_post_link();
        }
    } );

    Let me know if that displays anything at all.

    #682472
    Eva

    Again…. nothing.
    Don’t worry about the time, I am not in a hurry.
    I’d rather use WP Show Posts (I also have the PRO version) if I wouldn’t need a filterable portfolio with CPT’s…
    Thanks for you patience and support!

    #682707
    Tom
    Lead Developer
    Lead Developer

    No problem – I’ll dig into this ASAP and will let you know what I find out πŸ™‚

    #685127
    Eva

    Hi Tom, thank you! It would be great if the problem can be solved. Even better if I could use WP Show PostsPRO and have a filterable portfolio… That would be the best πŸ™‚
    I know it’s not a feature yet, but maybe it can be done another way?
    Thanks,
    Eva

    #685491
    Tom
    Lead Developer
    Lead Developer

    So I just built a custom post type and named it project.

    I then added this function:

    add_action( 'generate_after_content', function() {
        if ( is_singular( 'project' ) ) {
            previous_post_link();
            next_post_link();
        }
    } );

    And it’s showing the links for me. They need to be styled with CSS, but they’re there.

    #685813
    Eva

    Yessss! Great, it works!! You’re a genius πŸ™‚
    Now, to show categories and tags, I add?

    Thanks!!!

    #686400
    Tom
    Lead Developer
    Lead Developer

    Awesome πŸ™‚

    Are those taxonomies registered in your custom post type? Or do you have custom taxonomies?

    #686702
    Eva

    I use custom taxonomies: Projectsoorten and Trefwoorden

    Thanks!

    #687043
    Tom
    Lead Developer
    Lead Developer

    So you could try something like this:

    add_action( 'generate_after_content', function() {
        if ( is_singular( 'project' ) ) {
            previous_post_link();
            next_post_link();
    
            $projectsoorten = get_the_term_list( get_the_ID(), 'projectsoorten' );
            $trefwoorden = get_the_term_list( get_the_ID(), 'trefwoorden' );
    
            if ( $projectsoorten ) {
                echo $projectsoorten;
            }
    
            if ( $trefwoorden ) {
                echo $trefwoorden;
            }
        }
    } );

    Obviously, it would need to be styled with CSS.

    #687157
    Eva

    Unfortunately I got an error… I send you the code for the Projectsoort taxonomy, because I think what I send you was not correct (sorry, ones again πŸ™‚

    function your_prefix_register_taxonomy() {

    $args = array (
    ‘label’ => esc_html__( ‘Projectsoorten’, ‘text-domain’ ),
    ‘labels’ => array(
    ‘menu_name’ => esc_html__( ‘Projectsoorten’, ‘text-domain’ ),
    ‘all_items’ => esc_html__( ‘All Projectsoorten’, ‘text-domain’ ),
    ‘edit_item’ => esc_html__( ‘Edit Projectsoort’, ‘text-domain’ ),
    ‘view_item’ => esc_html__( ‘View Projectsoort’, ‘text-domain’ ),
    ‘update_item’ => esc_html__( ‘Update Projectsoort’, ‘text-domain’ ),
    ‘add_new_item’ => esc_html__( ‘Add new Projectsoort’, ‘text-domain’ ),
    ‘new_item_name’ => esc_html__( ‘New Projectsoort’, ‘text-domain’ ),
    ‘parent_item’ => esc_html__( ‘Parent Projectsoort’, ‘text-domain’ ),
    ‘parent_item_colon’ => esc_html__( ‘Parent Projectsoort:’, ‘text-domain’ ),
    ‘search_items’ => esc_html__( ‘Search Projectsoorten’, ‘text-domain’ ),
    ‘popular_items’ => esc_html__( ‘Popular Projectsoorten’, ‘text-domain’ ),
    ‘separate_items_with_commas’ => esc_html__( ‘Separate Projectsoorten with commas’, ‘text-domain’ ),
    ‘add_or_remove_items’ => esc_html__( ‘Add or remove Projectsoorten’, ‘text-domain’ ),
    ‘choose_from_most_used’ => esc_html__( ‘Choose most used Projectsoorten’, ‘text-domain’ ),
    ‘not_found’ => esc_html__( ‘No Projectsoorten found’, ‘text-domain’ ),
    ‘name’ => esc_html__( ‘Projectsoorten’, ‘text-domain’ ),
    ‘singular_name’ => esc_html__( ‘Projectsoort’, ‘text-domain’ ),
    ),
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_in_menu’ => true,
    ‘show_in_nav_menus’ => true,
    ‘show_tagcloud’ => true,
    ‘show_in_quick_edit’ => true,
    ‘show_admin_column’ => false,
    ‘show_in_rest’ => false,
    ‘hierarchical’ => false,
    ‘query_var’ => true,
    ‘sort’ => false,
    ‘rewrite_no_front’ => false,
    ‘rewrite_hierarchical’ => false,
    ‘rewrite’ => true,
    );

    register_taxonomy( ‘projectsoort’, array( ‘project’ ), $args );
    }
    add_action( ‘init’, ‘your_prefix_register_taxonomy’, 0 );

    #687290
    Tom
    Lead Developer
    Lead Developer

    What was the error?

    #688904
    Eva

    Sorry, this is the error:

    Catchable fatal error: Object of class WP_Error could not be converted to string in /home/alfabetp/test.alfabetprodukties.nl/wp-content/themes/generatepress_child/functions.php on line 22

    Hope this is of any use…
    Thanks again!!

    #689061
    Tom
    Lead Developer
    Lead Developer

    Are projectsoorten and trefwoorden the correct IDs of the taxonomies? I only guessed based on their names.

    #689283
    Eva

    I think I the ID’s are projectsoort and Trefwoord, because now I don’t get an error anymore. It all looks quite strange though, and even more when I click to open a similar project…
    But I am happy it’s almost resolved now!! Thank you for spending so much time!

    #689485
    Tom
    Lead Developer
    Lead Developer

    They likely need to be styled with CSS to look good. I’m not seeing any of the tags listed on your project pages though?

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