WordPress.org

Support

Support » Themes and Templates » Add Custom Post Types to Featured Post Area

Add Custom Post Types to Featured Post Area

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Brian Harris

    @zgani

    Hello Walton,

    It works well with 2014, but not with Ridizain.

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

    Zulf

    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!

    Theme Author Brian Harris

    @zgani

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add Custom Post Types to Featured Post Area’ is closed to new replies.