Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1242048
    nathansjcorp
    Participant

    Hi, the recent post is showing the excerpt current length (100)on my english page but my code is not working on the chinese pages.

    http://chenhsong.com/customer_success_stories/?lang=zh-hans
    http://chenhsong.com/customer_success_stories

    If i add some english to a chinese post then it works fine. I can only assume that the {‘<span class=”x-recent-posts-excerpt”>’ . strip_tags(excerpt(100)) . ‘</span>’} is not working for chinese characters.

    #1242049
    nathansjcorp
    Participant

    This is my code:

    #1242050
    nathansjcorp
    Participant

    // =============================================================================
    // 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(‘\[[^\]]*\]‘,”,$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’;
    }

    $output .= ‘
    . ‘<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(100)) . ‘</span>’
    . ‘</div>’
    . ‘</div>’
    . ‘</article>’
    . ‘
    ‘;

    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’ );
    }

    #1242052
    nathansjcorp
    Participant
    This reply has been marked as private.
    #1242100
    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in and the very detailed information. Please make sure that both of the English posts and the Chinese post has a an excerpt. Did you created the posts in Cornerstone? If that is the case, this is why you are not seeing any excerpt because shortcodes and Cornerstone formatting codes will be strip off in the excerpt. Excerpts are optional hand-crafted summaries of your content that can be used in your theme. Learn more about manual excerpts here: https://codex.wordpress.org/Excerpt.

    To display the excerpt properly, you have to use the manual excerpts. To add an excerpt to a post, simply write one in the Excerpt field under the post edit box. Please see the screenshot below: http://prntscr.com/9j98do

    Hope this helps.

    #1242103
    nathansjcorp
    Participant

    Hi, no that does not help.

    I added my code so that i don’t need to use the “manual excerpt”

    This works fine in English where it picks up the first 100 characters of my content.
    If you look at the post”high-end-medical-equipment-part-molding” in the back end you can clearly see that there is no “manual excerpt”

    #1242254
    Christian
    Moderator

    Yes, there is no excerpt. You need to manually write it in the Excerpt box (see attachment)

    Thanks.

    #1242342
    nathansjcorp
    Participant

    I’m sorry, but if you look at the links i sent:
    http://chenhsong.com/customer_success_stories/?lang=zh-hans
    http://chenhsong.com/customer_success_stories

    you will see that there is some text under the title of each “recent post”.
    right??
    Now i’m calling that text “excerpt” but you can also call it “beginning of content text” or whatever.
    and as far as i know the code that i put in “functions php” allows that “beginning of content text/ excerpt” to be displayed through the “recent post shortcode”

    Now the problem is that it is not working correctly for chinese characters as made obvious on this page:
    http://chenhsong.com/customer_success_stories/?lang=zh-hans

    Please don’t tell me about “manual excerpt” as i do not intent to use it, i am hoping for (“automatic excerpt/ automatic display of the first few lines of text”)in my post” which has been working just fine for the last month in English but has a problem in chinese.

    thanks.

    #1242498
    Christian
    Moderator

    I see. Regretfully this isn’t a feature offered by X. It could be possible with custom development, but this would be outside the scope of support we can offer. You might want to contact our trusted partners who caters X setup and customization needs. Please see https://community.theme.co/custom-development/. Thanks for understanding. Take care!

    #1243469
    nathansjcorp
    Participant

    Ok no worries!

    Here is a similar problem that should fall under your scope of support:

    Under Appearance>customize> blog > content> the excerpt length is not working for chinese.

    http://chenhsong.com/11.3bk/category/customer-success-stories-ch/?lang=zh-hans

    http://chenhsong.com/11.3bk/category/case-studies/customer-success-stories/

    my excerpt length is set to 10

    I assume you should fix this as this is a function within your customizer?
    Unless Xtheme does not support asian fonts?

    Please go ahead, and turn content off and on, change length ,edit the post in question, etc… this is a backup version.so you can do what you want with it.

    #1243470
    nathansjcorp
    Participant

    If you can’t fix it could you please offer me a hack/ quick fix?

    #1243552
    Paul R
    Moderator

    Hi,

    You can add manual excerpts to your posts.

    Please see screenshot – http://screencast.com/t/ya8A0ZBmclN

    Hope that helps.

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