当wordpress中的全文打开时,如何删除阅读更多?

发布于 2024-12-20 04:48:32 字数 267 浏览 1 评论 0原文

代码看起来像这样,

function new_excerpt_length($length) {
    return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

wp-admin>settings>reading>中有一个选项对于提要中的每篇文章,显示 如果设置为全文 excerpt() 必须返回完整长度的文章而不是指定的长度。

怎么办?

the code looks like this

function new_excerpt_length($length) {
    return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

there is an option in wp-admin>settings>reading>For each article in a feed, show
if this is set to full text
the excerpt() must return full length article instead of specified length.

how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2024-12-27 04:48:32

好问题!答案很简单:编写自己的函数!

在您最喜欢的编辑器中打开 functions.php 并按键盘上的随机按钮,直到得到如下所示的内容:

function my_awesome_excerpt ($post_id = false, $full = false, $length = 22) {
    if (!$post_id) global $post;
    else $post = get_post($post_id);

    $text = $post->post_content;

    if ($full) return $text;

    else {
        $text_array = explode(' ', $text);
        $return_string = array();
        for ($i = 0; $i <= $length; $i++)
            array_push($return_string, $text_array[$i]);

        $new_awesome_string = '<p>';
        $new_awesome_string .= implode(' ', $return_string);
        $new_awesome_string .= '</p><p class="readmore">';
        $new_awesome_string .= '<a href="' . get_permalink($post_id) . '">';
        $new_awesome_string .= 'Read More' . '</a></p>';

        return $new_awesome_string;
    }
}

现在,您已经准备好迎接最酷的部分了。一旦你进入循环,你可以写出一些像这样的魔法:

echo my_awesome_excerpt();

它会自动吐出一个摘录。它使用全局 post 变量和一切!您甚至可以在循环之外使用它:

echo my_awesome_excerpt($cpt->ID, 22);

并设置您自己的特殊长度!

或者也许你只是心里知道这不值得,你只是想展示整个事情。看起来怎么样?

在循环内,您必须为其提供一个帖子 ID,对此感到抱歉。

echo my_awesome_script($post->ID, false);

我希望这有帮助。祝你有美好的一天!

Good question! The answer is simple: write your own function!

Open up functions.php in your favorite editor and mash random buttons on your keyboard until you get something like this:

function my_awesome_excerpt ($post_id = false, $full = false, $length = 22) {
    if (!$post_id) global $post;
    else $post = get_post($post_id);

    $text = $post->post_content;

    if ($full) return $text;

    else {
        $text_array = explode(' ', $text);
        $return_string = array();
        for ($i = 0; $i <= $length; $i++)
            array_push($return_string, $text_array[$i]);

        $new_awesome_string = '<p>';
        $new_awesome_string .= implode(' ', $return_string);
        $new_awesome_string .= '</p><p class="readmore">';
        $new_awesome_string .= '<a href="' . get_permalink($post_id) . '">';
        $new_awesome_string .= 'Read More' . '</a></p>';

        return $new_awesome_string;
    }
}

Now, you're ready for the cool part. Once you're in your loop, you can write out some magic like this:

echo my_awesome_excerpt();

and it will automagically spit out an excerpt. It's using the global post variable and everything! You can even use it outside of the loop:

echo my_awesome_excerpt($cpt->ID, 22);

and set your own special length!

Or maybe you just know in your heart that it's not worth it, you just want to show the whole thing. How's that look?

Inside the loop, you're going to have to give it a post ID, sorry about that.

echo my_awesome_script($post->ID, false);

I hope this helps. Have a great day!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文