Using Custom Post Types instead of Standard Posts

Home Forums Modern Using Custom Post Types instead of Standard Posts

Viewing 10 posts - 1 through 10 (of 15 total)
  • Author
    Posts
  • #21580

    Sharkster4000
    Participant

    Using Custom Post Types instead of Standard Posts

    Resolved

    Hey there! Have you noticed this support service is provided FREE of charge?
    If you like the speed and accuracy of resolutions, please consider supporting me with a small donation. Thank you

    Consider a donation →

    Hi Oliver,

    I would like to do a (hopefully simple) theme modification and would love to get your help with it. I realize that you offer this theme for free and that modifications are out of scope for “free support” which is why I have no problem paying a fee for your assistance.

    We’re using a custom post type “timeline items” on our site (generated via the plugin “cool timeline pro” (https://cooltimeline.com/)). We would like to use these timeline items the same way, the theme displays standard posts. In detail:

    The NS Featured Posts plugin allows us to select the source for the posts to be featured in the slider. Fortunately, this includes the option to choose our timeline items. However, the posts shown on the homepage under the slider remain the “standard posts”. How can I change these to display timeline items instead?

    I also would love to see the timeline items show the categories and tags just like standard posts do.

    So, the question is: How can I let the theme treat a custom post type (timeline items) just like standard posts?

    Regarding commercial assistance for a free theme, please let me know an email-address, where we can negotiate a price for your help. Thank you so much in advance!

    Best regards,
    Martin

    #21582

    Oliver Juhas
    Keymaster

    Hi Martin,

    Please understand that I do not provide any freelance work as I am fully occupied with my own projects.

    However, if I understand correctly, you would like to populate the homepage slideshow with your “timeline items” post type. Well, there should be no issue doing so out of the box using NS Featured Posts plugin. I’ve just tried it with Jetpack Testimonials, for example, and all featured testimonials are displayed correctly in slideshow for me. All I did was I enabled the Testimonials post type in NS Featured Posts plugin settings.

    Please understand though that slideshow displays posts/custom post types based on publish date, so the newest posts/custom post types are displayed first. Maybe none of your “timeline items” post type posts is published more recently than other posts in your slideshow?

    You can also simply disable NS Featured Posts for WordPress standard posts and just display the “timeline items” in slideshow. That should also work just fine.

    If this doesn’t work, please check with your Cool Timeline Pro plugin support for help. Maybe they didn’t made the post type public?

    As for enabling categories and tags for the “timeline items” post type, adding this code in your child theme‘s functions.php file should help:

    function child_theme_post_type_taxonomy() {
    	register_taxonomy_for_object_type( 'post_tag', 'post-type-id-here' );
    	register_taxonomy_for_object_type( 'category', 'post-type-id-here' );
    }
    add_filter( 'init', 'child_theme_post_type_taxonomy' );

    Replace the post-type-id-here with your “timeline items” post type id. Check with your Cool Timeline Pro plugin support for help.

    As you can see, these questions are related to your Cool Timeline Pro plugin usage rather than theme. However, the above tips should work/help. Please consult with Cool Timeline Pro plugin support if more help required with their post type.

    Best regards,

    Oliver Juhas
    WebMan Design

    #21583

    Oliver Juhas
    Keymaster

    BTW, looking at the code of the free Cool Timeline plugin, seems like you should replace the post-type-id-here with cool_timeline.
    And I can also see the post type is public, so there should be really no issue in displaying it in homepage slideshow.

    Best regards,

    Oliver Juhas
    WebMan Design

    #21584

    Sharkster4000
    Participant

    Hi Oliver,

    thanks again for the super fast and comprehensive reply. Unfortunately, I added…

    function child_theme_post_type_taxonomy() {
    register_taxonomy_for_object_type( ‘post_tag’, ‘cool_timeline’ );
    register_taxonomy_for_object_type( ‘category’, ‘cool_timeline’ );
    }
    add_filter( ‘init’, ‘child_theme_post_type_taxonomy’ );

    …in functions.php of my ‘modern-child’ but the categories still aren’t shown anyway with the timeline items. I will ask the author of the timeline plugin how the post-type is called and try again.

    About using timeline items instead of posts, I didn’t mean in the slider (I got that one figured out), but in the display of posts below the slider:

    However, the posts shown on the homepage <b>under the slider</b> remain the “standard posts”. How can I change these to display timeline items instead?

    I understand that I can deactivate the post under the page content entirely, but I would only do that as a last resort. I prefer to have the last three added timeline items displayed there. Is that possible?

    About the order of displayed items in the slider: Yea, I know that they are ordered in a “last-added”-order. That’s okay.

    #21592

    Oliver Juhas
    Keymaster

    Hi Sharkster4000,

    Now I understand. You would like to display the “timeline items” post type in a blog section on homepage.

    You can actually force the theme to display any post type in there. Use this PHP code in your child theme‘s functions.php file:

    function child_theme_loop_query( $args, $context ) {
    	if ( 'loop-front-blog.php' === $context ) {
    		$args['post_type'] = 'cool_timeline';
    	}
    	return $args;
    }
    add_filter( 'wmhook_modern_loop_query', 'child_theme_loop_query', 10, 2 );

    To modify the title of the section, please copy the template-parts/component/title-front-blog.php file into your child theme, keeping the folder structure, and edit it there.
    Similar would apply for the button and its template-parts/component/link-front-blog.php file.

    Best regards,

    Oliver Juhas
    WebMan Design

    #21596

    Sharkster4000
    Participant

    Hi Oliver, thanks for your reply. I’ve changed the functions.php accordingly, but neither this change nor the one where I’m trying to limit the amount of featured posts in the “NS featured posts slider” has any effect on my theme. Also the change where I try to add the display of categories to the timeline items. :(

    I’m still pretty new to editing WordPress stuff, but I believe that I do everyhing as instructed. But maybe there’s something I do fundamentally wrong? This is how my child theme’s function.php looks:

    <?php
    /**
     * Post meta, bottom
     *
     * We are using generic, global hook names in this file, but passing
     * a file name as a hook context/scope parameter you can check for.
     *
     * @package    Modern
     * @copyright  WebMan Design, Oliver Juhas
     *
     * @since    2.0.0
     * @version  2.0.0
     */
    // Requirements check
    	if (
    		post_password_required()
    		|| ! in_array(
    			get_post_type( get_the_ID() ),
    			(array) apply_filters( 'wmhook_modern_entry_meta_post_type', array( 'post' ), basename( __FILE__ ) )
    		)
    	) {
    		return;
    	}
    ?>
    
    function child_theme_post_type_taxonomy() {
    	register_taxonomy_for_object_type( 'post_tag', 'cool_timeline' );
    	register_taxonomy_for_object_type( 'category', 'cool_timeline' );
    }
    add_filter( 'init', 'child_theme_post_type_taxonomy' );
    
    function child_theme_loop_query( $args, $context ) {
    	if ( 'loop-front-blog.php' === $context ) {
    		$args['post_type'] = 'cool_timeline';
    	}
    	return $args;
    }
    add_filter( 'wmhook_modern_loop_query', 'child_theme_loop_query', 10, 2 );
    
    function child_theme_ns_featured_posts_get_posts_args( $args ) {
    	$args['numberposts'] = 3;
    	return $args;
    }
    add_filter( 'wmhook_modern_ns_featured_posts_get_posts_args', 'child_theme_ns_featured_posts_get_posts_args' );
    
    <footer class="entry-meta entry-meta-bottom"><?php
    	if ( is_single( get_the_ID() ) ) {
    		get_template_part( 'template-parts/meta/entry-meta-element', 'tags' );
    	} else {
    		get_template_part( 'template-parts/meta/entry-meta-element', 'date' );
    		get_template_part( 'template-parts/meta/entry-meta-element', 'comments' );
    		get_template_part( 'template-parts/meta/entry-meta-element', 'author' );
    		get_template_part( 'template-parts/meta/entry-meta-element', 'category' );
    	}
    ?></footer>

    Did I put the changes in the way they are meant to be or is there something obviously wrong that I don’t get…

    Best regards,
    Martin

    #21601

    Oliver Juhas
    Keymaster

    Hi Martin,

    Your functions.php file is wrong. There is additional code from a different file of the theme that breaks it up. But you should actually get some errors on your website if this is really in your child theme‘s functions.php file…

    Here is the content of functions.php file that I have proposed:

    <?php
    
    function child_theme_post_type_taxonomy() {
    	register_taxonomy_for_object_type( 'post_tag', 'cool_timeline' );
    	register_taxonomy_for_object_type( 'category', 'cool_timeline' );
    }
    add_filter( 'init', 'child_theme_post_type_taxonomy' );
    
    function child_theme_loop_query( $args, $context ) {
    	if ( 'loop-front-blog.php' === $context ) {
    		$args['post_type'] = 'cool_timeline';
    	}
    	return $args;
    }
    add_filter( 'wmhook_modern_loop_query', 'child_theme_loop_query', 10, 2 );
    
    function child_theme_ns_featured_posts_get_posts_args( $args ) {
    	$args['numberposts'] = 3;
    	return $args;
    }
    add_filter( 'wmhook_modern_ns_featured_posts_get_posts_args', 'child_theme_ns_featured_posts_get_posts_args' );

    No other code should be in the file.

    I strongly suggest checking these resources please:

    If you want to modify the post meta, please follow my instructions provided to you previously. Please note I haven’t mentioned you should put the code into your child theme‘s functions.php file: copy the post (entry) meta file into your child theme according to my instructions and edit it there.

    Best regards,

    Oliver Juhas
    WebMan Design

    #21602

    Oliver Juhas
    Keymaster

    Also, please understand that I have no capacity to check users’ own code modifications. Users are responsible for any code modifications they apply, including introducing errors. Please read terms of service of this support forum.

    If you are not familiar with PHP coding, please hire a WordPress developer that can help you with custom theme modifications. Thank you for understanding.

    If you consider advice and the code I’ve provided helpful, please consider a donation. Thank you.

    Best regards,

    Oliver Juhas
    WebMan Design

    #21606

    Sharkster4000
    Participant

    Hi Oliver,

    thank you so much for your help. I just donated with the subject “Sharkster4000 says Thank You!”.

    I got it to work as intended. Actually, I’m experienced with WordPress and CSS etc., but a total n00b with everything PHP related. I don’t even get the syntax lol… So, again… thanks a ton for your professional help and your time!

    Best regards,
    Martin

    • This reply was modified 3 days, 19 hours ago by  Oliver Juhas. Reason: Making the post public as there is no sensitive information shared
    #21610

    Oliver Juhas
    Keymaster

    Hey Martin,

    Thank you very much for your donation! :)

    Glad to see the solution worked just fine for you.

    Tip: In case you will tweak a PHP code in the future, please enable debugging in WordPress so it displays errors/warnings if they occur. That way you will be able to trace the issue with the code much faster.

    Best regards,

    Oliver Juhas
    WebMan Design

Viewing 10 posts - 1 through 10 (of 15 total)

You must be logged in to reply to this topic.