结合wp_trim_words和wp_strip_all_tags

时间:2017-11-02 05:10:48

标签: wordpress tags trim strip words

无法找到在循环中组合wp_trim_words和wp_strip_all_tags的解决方案。 这就是我现在所拥有的:

    package com;

    import java.util.Arrays;
    import java.util.List;
    import java.util.function.Consumer;


    public class AdvanceConsumerTest {

        public static void main(String[] args) {

            TestLookupService testLookupService = new TestLookupService();
            testLookupService.forEach("A",val->{
                System.out.println(" Count of 'A' is "+ val);
            });
            System.out.println("******************************************");
            testLookupService.forEach("B",val->{
                System.out.println(" Count of 'B' is "+ val);
            });
            System.out.println("******************************************");
            testLookupService.forEach("C",val->{
                System.out.println(" Count of 'C' is "+ val);
            });

        }
    }

    class TestLookupService {
        void forEach(String parameter, Consumer<Long> stringConsumer) {
            LocalRepository.forEach(new QueryExecutionContext() {
                @Override
                public String getQuery() {
                    return parameter;
                }

                @Override
                public Consumer<Long> getConsumer() {
                    return stringConsumer;
                }
            });
        };
    }

    class LocalRepository {
        static DataSetRepo dataSetRepo = new DataSetRepo();

        static void forEach(QueryExecutionContext executionContext) {
            executionContext.getConsumer().accept(dataSetRepo.queryResults(executionContext));
        }

    }

    interface QueryExecutionContext {

        String getQuery();

        Consumer<Long> getConsumer();
    }

    class DataSetRepo {
        List<String> cacheOf = Arrays.asList("A", "B", "C", "A", "C", "C", "B");

        long queryResults(QueryExecutionContext context) {
            return cacheOf.stream().filter(s -> s.equalsIgnoreCase(context.getQuery())).count();
        }
    }

我应该创建一些额外的功能吗?

1 个答案:

答案 0 :(得分:0)

嵌套函数......

<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       <div class="news-el">
           <a href="<?php the_permalink(); ?>">
                <div class="news-content">                      
                    <h3><?php echo get_the_title(); ?></h3>
                    <?php echo wp_trim_words( wp_strip_all_tags( get_the_content(), 55 ) );?>
                </div>
            </a>
        </div>
    <?php endwhile; ?>
<?php endif; ?>

在此示例中,函数将“...”输出到55个单词的文本块的末尾,因此您不需要span标记。您可以通过为函数wp_trim_words指定第三个参数来自定义您想要在修剪后的单词后显示的内容。