WordPress.org

Forums

Ridizain
Add Custom Post Types to Featured Post Area (4 posts)

  1. Walton
    Member
    Posted 2 years ago #

    I've been trying to figure out how to add custom post types to the featured post slider or grid. I can't find the query_posts function in the template.

    I also tried the solution here:

    http://premium.wpmudev.org/blog/how-to-make-twenty-fourteen-or-any-other-wp-theme-super/

    It works well with 2014, but not with Ridizain.

  2. Brian Harris
    Member
    Theme Author

    Posted 2 years ago #

    Hello Walton,

    It works well with 2014, but not with Ridizain.

    How are you attempting to add the filter in to Ridizain?

    Zulf

  3. Walton
    Member
    Posted 2 years ago #

    I made a child theme and added this code to the functions.php file

    <?php
    //Add Custom Post Types
    function awesome_2014_get_featured_posts( $posts ){
    $fc_options = (array) get_option( 'featured-content' );
    if ( $fc_options ) {
    $tag_name = $fc_options['tag-name'];
    } else {
    $tag_name = 'best';
    }
    $layout = get_theme_mod( 'featured_content_layout' );
    $max_posts = get_theme_mod( 'num_posts_' . $layout, 2 );
    $args = array(
    'tag' => $tag_name,
    'posts_per_page' => $max_posts,
    'order_by' => 'post_date',
    'order' => 'DESC',
    'post_status' => 'publish',
    'post_type' => 'tc_lessonplan',
    );
    $new_post_array = get_posts( $args );
    if ( count($new_post_array) > 0 ) {
    return $new_post_array;
    } else {
    return $posts;
    }
    }
    add_filter( 'twentyfourteen_get_featured_posts', 'awesome_2014_get_featured_posts', 999, 1 );
    ?>

    Ah ha---I see it now. Changing the last line from twentyfourteen_get_featured_posts to ridizain_get_featured_posts works perfectly.

    I see that this function adds a lot of the stuff that you added to 2014 in terms of post limits. If I strip it down to:

    function awesome_2014_get_featured_posts( $posts )
    $args = array(
    'post_type' => 'tc_lessonplan',
    );
    $new_post_array = get_posts( $args );
    if ( count($new_post_array) > 0 ) {
    return $new_post_array;
    } else {
    return $posts;
    }
    }
    add_filter( 'twentyfourteen_get_featured_posts', 'awesome_2014_get_featured_posts', 999, 1 );

    does that do it? I am a fan on minimizing code.

    The theme is awesome by the way. I really want this to work so I can feature my lesson plans!

  4. Brian Harris
    Member
    Theme Author

    Posted 2 years ago #

    Cool - glad you spotted the change needed in the filter :)

    EDIT: I missed read what you meant on stripping the code down - for Ridizain, yes you only need to add the custom post type support part of the filter.

    As for Twenty Fourteen, other than support for custom post types all of the other elements are already included in the Fourteen Extended plugin.

    Looking for a way to support custom post types and pages via the plugin too but that will be sometime yet - need to find a good solution involving less code and minimal input bu end users.

    Let me know how the stripped down code work with Twenty Fourteen though - I might re-use it in the plugin :)

    Regards,
    Zulf

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic