Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1179618

    blueprint
    Participant

    Hello support team,

    I created a custom post type but couldn’t figure out how to make new posts of this type show up as recent post on my blog index page.

    Can you tell me how to do that?

    Thank you!

    #1179894

    Christopher
    Moderator
    #1180077

    blueprint
    Participant

    Thanks for the link. I have read this before, but I could not follow the instruction.
    As I uderstand it, I have to create a new indx.php and archive.php file for my custom post type in the x-child directory by dublicating the existing index.php file from x-theme directory and rename it with my post type like so: index-{video.php}; archive-{video}.php.

    “It’s safe to duplicate index.php and it’s template parts for your customization” but my index.php file in wp-content>themes>index.php and wp-content>themes>x>index.php are as good as empty, so I did not see any “template parts” to copy. This is what’s in there:

    <?php
    
    // =============================================================================
    // INDEX.PHP
    // -----------------------------------------------------------------------------
    // Handles output of pages and posts if a more specific template file isn't
    // present. Must be present for theme to function properly.
    //
    // Content is output based on which Stack has been selected in the Customizer.
    // To view and/or edit the markup of your Stack's index, first go to "views"
    // inside the "framework" subdirectory. Once inside, find your Stack's folder
    // and look for a file called "wp-index.php," where you'll be able to find the
    // appropriate output.
    // =============================================================================
    
    ?>
    
    <?php x_get_view( x_get_stack(), 'wp', 'index' ); ?>

    I also do not understand where to copy “all the content you can find in the different files that our portfolio consists of” from.

    I would be very greatful if you could give me a little clearer instruction.

    Thank you!!

    #1180094

    Thai
    Moderator

    Hi There,

    Please add the following code under functions.php file locates in your child theme:

    function x_custom_blog($query) {
    	if( !is_admin() && $query->is_main_query() ) {
    		if( $query->is_home() ) {
    			$query->set('post_type', array( 'post', 'your-post-type' ) );
    		}
    	}
    }
    add_action('pre_get_posts','x_custom_blog');

    Replace the your-post-type with your post type slug.

    Hope it helps 🙂

    #1180139

    blueprint
    Participant

    Thank you, but there is no change visible.
    I haven’t created the new index.php and archive.php as mentioned above. Just added the code you have given me into the funktions.php. This is what the funktions.php file in x-child theme looks like:

    <?php

    
    // =============================================================================
    // FUNCTIONS.PHP
    // -----------------------------------------------------------------------------
    // Overwrite or add your own custom functions to X in this file.
    // =============================================================================
    
    // =============================================================================
    // TABLE OF CONTENTS
    // -----------------------------------------------------------------------------
    //   01. Enqueue Parent Stylesheet
    //   02. Additional Functions
    // =============================================================================
    
    // Enqueue Parent Stylesheet
    // =============================================================================
    
    add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );
    
    // Additional Functions
    // =============================================================================
    function x_custom_blog($query) {
    	if( !is_admin() && $query->is_main_query() ) {
    		if( $query->is_home() ) {
    			$query->set('post_type', array( 'post', ‚video‘ ) );
    		}
    	}
    }
    add_action('pre_get_posts','x_custom_blog');

    Let me know what to do next.
    Thank you!!

    #1180140

    blueprint
    Participant
    This reply has been marked as private.
    #1180163

    Thai
    Moderator
    This reply has been marked as private.
    #1180307

    blueprint
    Participant

    Thanks again! I included the video post type in the essential grid settings and corrected the code in the functions.php. But still no luck – the video post still doesn’t appear…

    #1180309

    blueprint
    Participant

    I do see the custum post on the X-Blog Index page (see link from erlier conversation). But it has a different layout than the other posts and shows no featured image. Anyway I do not want to use that index page, but maybe this can help you see why it does not show up on my Essential Grid index page…

    Thanxx!!

    #1180311

    blueprint
    Participant

    That’s the recent post from custom post type “video” on the x blog index page…

    #1180515

    Rad
    Moderator

    Hi there,

    You post types should also have featured image. In your Grid source, you only selected one category but didn’t select catgeory assigned to your video post type.

    Try selecting the Vortrag too .

    Thanks!

    #1181289

    blueprint
    Participant
    This reply has been marked as private.
    #1181556

    Rad
    Moderator

    Hi there,

    Editing EG settings will only affect your preferred EG at http://dev.2016.christianseidel.de/pinnwand. It’s not related to your blog index anymore. What I’m saying is, you have to set featured image since it’s also required under media sources setting of your EG. And category relation should be OR and not AND. I went ahead and changed it.

    About the issue you’re getting from custom post type, you may contact the plugin author. I’m not really sure how their plugin works.

    For the meantime, please delete your custom post type and add the new one. Maybe it’s the reason it’s not properly appearing and the setting is corrupted. Is supposed to be blank when editing (eg. no editor and no other controls)?

    Thanks!

    #1181862

    blueprint
    Participant

    Thanks, I think it is fixed now! Deleting the custom post type and creating a new one helped!

    Now the post is showing on my blog index page as well as the one from X.

    Only thing left to fix is:
    1. The post doesn’t show up in “recent post” on the sidbar or “recent post”-widget. Do you have an idea how to make that work?

    2. The layout of custum posts is different from the ones created with regular post type. The changes I made to the layout via apearance > customizer > css do not apply to the custom post. Can you tell me how to make them all look the same?

    Thanks for your patience!!

    #1182515

    Lely
    Moderator

    Hi There,

    1.) By default, custom post types is not available on Recent Post element. To include it, please check this thread:https://community.theme.co/forums/topic/recent-posts-widget-to-show-custom-post-types/

    2.)Please update the following custom CSS:

    .single-post.x-post-meta-disabled .post .entry-featured {
        margin-top: 0;
    }
    
    .single .hentry .entry-wrap {
        padding-top: 0;
    }
    
    /*Posttitel*/
    .entry-title {
    text-align: left;
    }
    
    .single-post .entry-header {
        padding-top: 2em;
        margin: 0 auto;
      	margin-bottom: -3em;
        padding-left: 10%;
        padding-right: 10%;
    }
    
    .single-post .entry-header .entry-title {
        width: 89% !important;
        padding: 0;
        max-width: 1200px;
    }
    
    @media(max-width: 770px){
      .single-post .entry-header {
        padding-left: 0;
        padding-right: 0;
        margin-bottom: -2em;
        font-size: 130%;
      }
    }

    To this:

    .single-post.x-post-meta-disabled .post .entry-featured,
    .single-video_beitrag.x-post-meta-disabled .post .entry-featured  {
        margin-top: 0;
    }
    
    .single .hentry .entry-wrap {
        padding-top: 0;
    }
    
    /*Posttitel*/
    .entry-title {
    text-align: left;
    }
    
    .single-post .entry-header,
    .single-video_beitrag .entry-header{
        padding-top: 2em;
        margin: 0 auto;
      	margin-bottom: -3em;
        padding-left: 10%;
        padding-right: 10%;
    }
    
    .single-post .entry-header .entry-title,
    .single-video_beitrag  .entry-header .entry-title{
        width: 89% !important;
        padding: 0;
        max-width: 1200px;
    }
    
    @media(max-width: 770px){
      .single-post .entry-header,
      .single-video_beitrag .entry-header {
        padding-left: 0;
        padding-right: 0;
        margin-bottom: -2em;
        font-size: 130%;
      }
    }

    Hope this helps.