dongyun65343 2019-03-27 08:49
浏览 81

如何在WordPress上的XML数据中应用摘录

I'm pulling out the data from my CRM to my WordPress site using a XML. It worked actually, but I want to add some functions like read more with the my XML data {Web_Remarks[1]} it contains a long description.

Then I tried to add conditions from from my function.php like excerpt and edit my descriptions code.

For my functions.php I add

<?php
// Customize excerpt for description word count length
function custom_excerpt_length(){
    return 25;
}

add_filter('excerpt_length','custom_excerpt_length');

?>

And for my description.php I change my <?php the_content();?> to

<?php if ($post->post_excerpt) { ?>
        <p>
        <?php echo get_the_excerpt(); ?>
        <a href="<?php  the_permalink();?>">Read More&raquo;</a>
        </p>
    <?php }else{
        the_content();
    }
?>

I expect the output should be "3Bed room with laundry ro..Read More..."

but what I have now is

"3Bed room with laundry room and sea view with 2 car parkings only for 3.06M! -Bright -Spacious -Sea/Palm view -Balconies -Higher floor -No Construction chance infront -Prime location real estate are a Property Investment Firm with an ownership of more than 2500 properties all around the world.These are handpicked exclusive apartments and villas, located within the most prestigious and high-profile developments of Dubai. We do not just believe in customer satisfaction, we aim for customer delight. We understand that our customers define the standard of quality and service and your loyalty must be earned."

  • 写回答

1条回答 默认 最新

  • doubangzhang6992 2019-03-27 09:51
    关注

    Try,

    <?php
    $excerpt = get_the_excerpt();
    if( !empty($excerpt) ) { ?>
       <p>
          <?php echo $excerpt; ?>
          <a href="<?php  the_permalink();?>">Read More&raquo;</a>
       </p>
    <?php
    } else {
       the_content();
    }
    

    Or this will be a another method you can use:

    <?php
    // Add this code in functions.php file
    function wp_get_custom_excerpt( $limit = '25' ) {
        global $post;
    
        $content = get_the_excerpt();
        if( empty($content) ) {
            $content = strip_shortcodes( $post->post_content );
        }
    
        $excerpt = wp_trim_words( $content, $limit, '[...]' );
        return $excerpt;
    }
    
    // Remove your excerpt code and just echo function.
    echo wp_get_custom_excerpt();
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度