Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #988052
    Mobility
    Participant

    Hello! I’m using Cornerstone and have added to my child theme to allow excepts on the recent posts shortcode. Here’s my functions.php:

    <?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
    // =============================================================================
    add_action('x_after_view_global__brand', 'ph_besides_logo');
    function ph_besides_logo() { 
    $logo_nav_layout = x_get_logo_navigation_layout();
    if ( $logo_nav_layout == 'stacked' ) {
    echo '<h2 class="logo_with_text">Changing the World Through Mobility Solutions</h2>
    <h6 class="logo_with_text">September 28-29, 2016 | Detroit, Michigan USA</h6>';
    } 
    }
    // Excerpt Custom Length
    // =============================================================================
    function x_excerpt_length( $length ) {
    return 200;
    }  
    add_filter( 'excerpt_length', 'x_excerpt_length' );
    // Add read more to the excerpts
    // =============================================================================
    add_filter( 'ups_sidebar', 'x_force_sidebar', 9999 );
    function x_force_sidebar ( $default_sidebar ) {
    $sidebars = get_option( 'ups_sidebars' );
    foreach ( $sidebars as $id => $sidebar ) {
    if (  is_singular('post') ) {
    if ( array_key_exists( 'index-blog', $sidebar ) && $sidebar['index-blog'] == 'on' ) {
    return $id;
    }
    }
    }
    return $default_sidebar;
    }
    // =============================================================================
    // Add read more to the excerpts
    // =============================================================================
    function add_excerpt_readmore(){ ?>
    <p class="read-more"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"></br><span class="featured-view">Read More</span></a></p>
    <?php }
    add_action('x_before_the_excerpt_end', 'add_excerpt_readmore' );
    // =============================================================================
    // Add text on blog
    // =============================================================================
    function custom_landmark() { 
    if(is_home()): ?>
    <div class="custom-landmark">
    <div class="x-container max width"><h3 style="margin: 0.2em 0 0.2em; color: #035487;">Mobility Resources</h3>
    <h5 style="font-weight: 300; min-height: 100px !important;">The world is changing incredibly fast. Fresh ideas and mobility solutions are emerging every day to move people, goods and services seamlessly around the globe. From new start-ups to strategic growth solutions, today’s leaders are advancing promising innovations for the future. Learn more about what’s next, fascinating research and compelling best practices, below.</h5>
    </div></div>
    <?php endif; 
    }
    add_action('x_before_view_ethos__landmark-header','custom_landmark', 30);
    // =============================================================================
    // Remove date from post meta in index
    // =============================================================================
    function x_ethos_featured_index() {
    $entry_id                    = get_the_ID();
    $index_featured_layout       = get_post_meta( $entry_id, '_x_ethos_index_featured_post_layout', true );
    $index_featured_size         = get_post_meta( $entry_id, '_x_ethos_index_featured_post_size', true );
    $index_featured_layout_class = ( $index_featured_layout == 'on' ) ? ' featured' : '';
    $index_featured_size_class   = ( $index_featured_layout == 'on' ) ? ' ' . strtolower( $index_featured_size ) : '';
    $is_index_featured_layout    = $index_featured_layout == 'on' && ! is_single();
    ?>
    <a href="<?php the_permalink(); ?>" class="entry-thumb<?php echo $index_featured_layout_class; echo $index_featured_size_class; ?>" style="<?php echo x_ethos_entry_cover_background_image_style(); ?>">
    <?php if ( $is_index_featured_layout ) : ?>
    <span class="featured-meta"><?php echo x_ethos_post_categories(); ?> </span>
    <h2 class="h-featured"><span><?php x_the_alternate_title(); ?></span></h2>
    <span class="featured-view"><?php _e( 'View Post', '__x__' ); ?></span>
    <?php else : ?>
    <span class="view"><?php _e( 'View Post', '__x__' ); ?></span>
    <?php endif; ?>
    </a>
    <?php
    }
    // =============================================================================
    // Custom Excerpt Length - Call: echo excerpt($length);
    // =============================================================================
    function excerpt($limit) {
    $excerpt = explode(' ', get_the_excerpt(), $limit);
    if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt).'.';
    } else {
    $excerpt = implode(" ",$excerpt);
    } 
    // $excerpt = preg_replace('<code>\[[^\]]*\]</code>','',$excerpt);
    return $excerpt;
    }
    // =============================================================================
    // Add Excerpt to Recent Posts -> [x_recent_posts]
    // =============================================================================
    function x_shortcode_recent_posts_excerpt( $atts ) {
    extract( shortcode_atts( array(
    'id'          => '',
    'class'       => '',
    'style'       => '',
    'type'        => 'post',
    'count'       => '',
    'category'    => '',
    'offset'      => '',
    'orientation' => '',
    'no_image'    => '',
    'fade'        => ''
    ), $atts, 'x_recent_posts' ) );
    $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
    $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';
    $id            = ( $id          != ''          ) ? 'id="' . esc_attr( $id ) . '"' : '';
    $class         = ( $class       != ''          ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
    $style         = ( $style       != ''          ) ? 'style="' . $style . '"' : '';
    $count         = ( $count       != ''          ) ? $count : 3;
    $category      = ( $category    != ''          ) ? $category : '';
    $category_type = ( $type        == 'post'      ) ? 'category_name' : 'portfolio-category';
    $offset        = ( $offset      != ''          ) ? $offset : 0;
    $orientation   = ( $orientation != ''          ) ? ' ' . $orientation : ' horizontal';
    $no_image      = ( $no_image    == 'true'      ) ? $no_image : '';
    $fade          = ( $fade        == 'true'      ) ? $fade : 'false';
    $js_params = array(
    'fade' => ( $fade == 'true' )
    );
    $data = cs_generate_data_attributes( 'recent_posts', $js_params );
    $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";
    $q = new WP_Query( array(
    'orderby'             => 'date',
    'post_type'           => "{$type}",
    'posts_per_page'      => "{$count}",
    'offset'              => "{$offset}",
    "{$category_type}"    => "{$category}",
    'ignore_sticky_posts' => true
    ) );
    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
    if ( $no_image == 'true' ) {
    $image_output       = '';
    $image_output_class = 'no-image';
    } else {
    $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' );
    $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
    $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
    $image_output_class = 'with-image';
    }
    $excerpt = wp_trim_words( strip_tags( get_the_excerpt() ), 200, '<a href="'.get_permalink().'">read more</a>' );
    $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', csl18n() ), the_title_attribute( 'echo=0' ) ) ) . '">'
    . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
    . '<div class="entry-wrap">'
    . $image_output
    . '<div class="x-recent-posts-content">'
    . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
    . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
    . do_shortcode('[x_gap size="10px"]')
    . '<span class="x-recent-posts-excerpt">' .  strip_tags(excerpt(25))  . '</span>'
    . '</div>'
    . '</div>'
    . '</article>'
    . '</a>';
    endwhile; endif; wp_reset_postdata();
    $output .= '</div>';
    return $output;
    }
    add_action('wp_head', 'update_x_recent_posts_to_v2');
    function update_x_recent_posts_to_v2() {
    remove_shortcode( 'x_recent_posts' );
    add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_excerpt' );
    }
    // =============================================================================
    // Remove Author from entry meta in Ethos
    // =============================================================================
    if ( ! function_exists( 'x_ethos_entry_meta' ) ) :
    function x_ethos_entry_meta() {
    $author = sprintf( ' by %s</span>',
    get_the_author()
    );
    $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
    esc_attr( get_the_date( 'c' ) ),
    esc_html( get_the_date() )
    );
    if ( get_post_type() == 'x-portfolio' ) {
    if ( has_term( '', 'portfolio-category', NULL ) ) {
    $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
    $separator         = ', ';
    $categories_output = '';
    foreach ( $categories as $category ) {
    $categories_output .= '<a href="'
    . get_term_link( $category->slug, 'portfolio-category' )
    . '" title="'
    . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
    . '"> '
    . $category->name
    . '</a>'
    . $separator;
    }
    $categories_list = sprintf( '<span> %s',
    trim( $categories_output, $separator )
    );
    } else {
    $categories_list = '';
    }
    } else {
    $categories        = get_the_category();
    $separator         = ', ';
    $categories_output = '';
    foreach ( $categories as $category ) {
    $categories_output .= '<a href="'
    . get_category_link( $category->term_id )
    . '" title="'
    . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
    . '"> '
    . $category->name
    . '</a>'
    . $separator;
    }
    $categories_list = sprintf( '<span>%s',
    trim( $categories_output, $separator )
    );
    }
    if ( comments_open() ) {
    $title  = get_the_title();
    $link   = get_comments_link();
    $number = get_comments_number();
    if ( $number == 0 ) {
    $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
    esc_url( $link ),
    esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
    __( 'Leave a Comment' , '__x__' )
    );
    } else if ( $number == 1 ) {
    $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
    esc_url( $link ),
    esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
    $number . ' ' . __( 'Comment' , '__x__' )
    );
    } else {
    $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
    esc_url( $link ),
    esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
    $number . ' ' . __( 'Comments' , '__x__' )
    );
    }
    } else {
    $comments = '';
    }
    if ( x_does_not_need_entry_meta() ) {
    return;
    } else {
    printf( '<p class="p-meta">%1$s%2$s%3$s</p>',
    $categories_list,
    $date,
    $comments
    );
    }
    }
    endif;
    // =============================================================================

    I need to adjust the post except length. I have it set here to 200:

    
    $excerpt = wp_trim_words( strip_tags( get_the_excerpt() ), 200, '<a href="'.get_permalink().'">read more</a>' );

    But it’s not reflecting here:http://6bd.152.myftpupload.com/

    Thoughts?

    #988059
    Mobility
    Participant

    Problem solved- please disregard. 🙂

    #988295
    Prasant Rai
    Moderator

    Happy to hear that. Feel free to ask us again. Have a great day! 🙂

  • <script> jQuery(function($){ $("#no-reply-988052 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>