永久链接转到404页面

时间:2017-06-19 12:20:11

标签: php wordpress permalinks

我有一个循环,我用来显示新闻类别的帖子,如果我点击标题,缩略图和阅读更多,它应该能够引导我到相关的帖子。

我的循环看起来像这样:

<?php
    $args = array(
        'post_type' => 'post',
        'posts_per_page' => 3,
        'category_name' => 'news'
    );
    $query = new WP_Query($args);
    while($query->have_posts()) : $query->the_post();
?>  
    <div class="news_box_content">
        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
        <figure><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></figure>
        <?php if($post->post_excerpt) { ?>
            <p><?php echo substr(get_the_excerpt(), 0,300); ?></p>
            <a href="<?php the_permalink(); ?>">Read more...</a>
        <?php } else {
            echo get_excerpt(); 
        } ?>
    </div>
<?php endwhile; wp_reset_postdata(); ?>

除了阅读更多链接外,一切正常。

问题是,当我点击阅读更多时,它会引导我进入404页面而不是帖子内容。

我该如何解决?

2 个答案:

答案 0 :(得分:1)

<?php if( get_the_excerpt() ) { ?>
            <p><?php echo substr(get_the_excerpt(), 0,300); ?></p>
            <a href="<?php the_permalink(); ?>">Read more...</a>
        <?php } else {
            echo get_excerpt(); 
        } ?>

试试这个

答案 1 :(得分:1)

我刚才意识到主题functions.php有一个功能来获取摘录,并且正在添加永久链接:

function get_excerpt(){
    $excerpt = get_the_content();
    $excerpt = preg_replace(" ([.*?])",'',$excerpt);
    $excerpt = strip_shortcodes($excerpt);
    $excerpt = strip_tags($excerpt);
    $excerpt = substr($excerpt, 0, 145);
    $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
    $excerpt = $excerpt.'<a class="more-link" href="<?php the_permalink();?>">Read more</a>';
    return $excerpt;
}

我删除了添加了标记的行,而是编辑了我的循环:

<?php if($post->post_excerpt) { ?>
    <p><?php echo substr(get_the_excerpt(), 0,300); ?></p>
    <a href="<?php the_permalink(); ?>">Read more...</a>
<?php } else { ?>
    <?php echo get_excerpt(); ?>
    <a class="more-link" href="<?php the_permalink();?>">Read more</a>

<?php } ?>
相关问题