首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在标题中放置“阅读更多”php WP中的链接

在标题中放置“阅读更多”php WP中的链接
EN

Stack Overflow用户
提问于 2014-09-02 06:44:31
回答 1查看 98关注 0票数 0

PHP帮助需要,所以我有一个wordpress问题,我有显示标题内容和继续阅读文本的功能,我需要把链接从继续阅读文本的标题和隐藏继续阅读文本。下面是文件中生成以下标题的代码:

代码语言:javascript
复制
    function whisper_entry_title2()
{
    if ( !( $title = get_the_title() ) )
        return;

    // Check on singular pages
    $is_single = is_singular() && !is_page_template( 'tpl/blog.php' ) && !is_page_template( 'tpl/blog-boxes.php' );

    // Allow to config via global variable
    if ( isset( $whisper['is_single'] ) )
        $is_single = $whisper['is_single'];

    $tag = $is_single ? 'h1' : 'h2';
    $title = sprintf( '<b class="black">%4$s</b>', $tag, get_permalink(), the_title_attribute( 'echo=0' ), $title );
    echo apply_filters( __FUNCTION__, $title );


}

下面是代码中生成继续读取的部分:

代码语言:javascript
复制
function whisper_content_limitoffer1( $num_words, $more = '...', $echo = true )
{
    $content = get_the_content();

    // Strip tags and shortcodes so the content truncation count is done correctly
    $content = strip_tags( strip_shortcodes( $content ), apply_filters( 'whisper_content_limit_allowed_tags', '<script>,<style>' ) );

    // Remove inline styles / scripts
    $content = trim( preg_replace( '#<(s(cript|tyle)).*?</\1>#si', '', $content ) );

    // Truncate $content to $max_char
    $content = wp_trim_words( $content, $num_words );

    if ( $more )
    {
        //$event_id = get_post_meta(get_the_ID(),'event_id', TRUE);
        //$link="http://example.com/wp/events-offers/";
        $output = sprintf(
            '<p class="event2-cf-oe">%s <a href="%s" class="more-link right o_6" title="%s">%s</a></p>',
            $content,
            get_permalink(),
            sprintf( __( 'Continue reading &quot;%s&quot;', 'whisper' ), the_title_attribute( 'echo=0' ) ),
            $more
        );
    }
    else
    {
        $output = sprintf( '<p class="event2-cf-oe">%s</p>', $content );
    }

    // Still display post formats differently
    $output = whisper_post_formats_content( $output );

    if ( $echo )
        echo $output;
    else
        return $output;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-02 07:20:53

那么,您的“继续阅读”文本将由下面一行输出。

代码语言:javascript
复制
sprintf( __( 'Continue reading &quot;%s&quot;', 'whisper' ), the_title_attribute( 'echo=0' ) ),

所以只要去掉这句话,那条短信就不见了。虽然我怀疑你可能会想要摆脱这整块代码

代码语言:javascript
复制
$output = sprintf(
        '<p class="event2-cf-oe">%s <a href="%s" class="more-link right o_6" title="%s">%s</a></p>',
        $content,
        get_permalink(),
        sprintf( __( 'Continue reading &quot;%s&quot;', 'whisper' ), the_title_attribute( 'echo=0' ) ),
        $more
    );

到你的帖子的链接是由上面那一行生成的,上面写着

代码语言:javascript
复制
get_permalink()

这样你就可以重新安置它了。

您可以很容易地输出文章标题,并使用以下简单的Wordpress函数将其作为文章的链接:

代码语言:javascript
复制
<a href="<?php echo get_permalink(); ?>">
    <?php the_title; ?>
</a>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25617330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档