Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 如何使用wp_trim_单词并阅读更多内容?_Wordpress - Fatal编程技术网

Wordpress 如何使用wp_trim_单词并阅读更多内容?

Wordpress 如何使用wp_trim_单词并阅读更多内容?,wordpress,Wordpress,我需要使用wp\u trim\u words()函数,以及一个“阅读更多”文本,当单击该文本时,它会在下方显示其余内容,如切换 这可能吗?试试这个 <?php echo wp_trim_words(get_the_content(), 40, '...'); ?> 或 或 对于tuggle,您需要使用javascript或jquery。使用jquery/script时,无需使用wp\u trim\u words函数,只需使用一些带有ancher标记(控件)的文本,并在单

我需要使用
wp\u trim\u words()
函数,以及一个“阅读更多”文本,当单击该文本时,它会在下方显示其余内容,如切换

这可能吗?

试试这个

<?php
echo wp_trim_words(get_the_content(), 40, '...');
?>




对于tuggle,您需要使用javascript或jquery。使用jquery/script时,无需使用wp\u trim\u words函数,只需使用一些带有ancher标记(控件)的文本,并在单击时隐藏/显示一些内容。

要显示页面内容,您可能需要使用内容()或echo get\u内容()。但是,你只需要使用下面的行

echo wp_trim_words(get_the_content(), $string_length, $text_read_more_optional); //example, $string_length=50, $text_read_more_optinal='Read More'
我猜你的代码应该是这样的:

if(have_posts()){
    while(have_posts()){
        the_post();
        the_title(); //display title
        echo wp_trim_words(get_the_content(), 100, 'Read More'); //display content
    }
}

你在找类似的东西吗?到目前为止你试过什么?将当前代码添加到问题Davy M,是!但应用于wp_trim_words()函数。cmaher echo wp_trim_words(获取内容(),40,“…”);我需要一个“阅读更多”按钮,点击该按钮时显示其余内容。您知道一种根据浏览器分辨率使用不同的wp_trim_单词(…)字长的方法吗?
echo wp_trim_words(get_the_content(), $string_length, $text_read_more_optional); //example, $string_length=50, $text_read_more_optinal='Read More'
if(have_posts()){
    while(have_posts()){
        the_post();
        the_title(); //display title
        echo wp_trim_words(get_the_content(), 100, 'Read More'); //display content
    }
}