【问题标题】:Post Loop showing on one page but not a different pagePost Loop 显示在一页上,但不在另一页上
【发布时间】:2021-10-19 21:11:59
【问题描述】:

我有我的主页,然后我有一份翻译成法语的副本。两个页面的代码是相同的,但由于某种原因,最新的帖子部分只显示在英文版上,而不是法文版上。我指的区域大约在页面的中间,而在法语版本中,它只是一个白色的盒子,里面有“博客”这个词。

英文:https://dvat.artrageousdemo.com/ 法语:https://dvat.artrageousdemo.com/fr/

这是用于提取最新帖子的代码。它适用于 2 个页面中的 1 个页面,即使它在两个页面上。

<?php
    $loop = new WP_Query( array(
        'post_type'      => 'post',
        'posts_per_page' => 2,
        'order'          => 'ASC'
    ) );
    if ( $loop->have_posts() ) :
        while ( $loop->have_posts() ) : $loop->the_post();
            ?>
                            <span><?php the_time( 'jS F, Y' ); ?></span>
                            <h6><?php the_title(); ?></h6>
                            <p><?php the_excerpt(); ?></p>
                            <a href='<?php the_permalink(); ?>' class='learn-btn'>Learn More <img src='<?php echo get_template_directory_uri(); ?>/images/a2.png' alt=''></a>
        <?php endwhile; endif;
        wp_reset_postdata(); ?>

感谢任何帮助。

【问题讨论】:

  • Learn more 不可翻译。你说的是这个吗?

标签: php wordpress templates post


【解决方案1】:

对于其他语言的帖子,您需要在 WP_Query 参数中传递 'suppress_filters' =&gt; true

这里我分享了示例供您参考:

$loop = new WP_Query( array(
        'post_type'      => 'post',
        'posts_per_page' => 2,
        'order'          => 'ASC',
        'suppress_filters' => true
    ) );

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 2019-07-06
    • 2016-02-23
    • 2012-10-20
    • 2012-08-09
    • 1970-01-01
    相关资源
    最近更新 更多