简体   繁体   English

Wordpress 帖子以相反的顺序显示(最早的在前)

[英]Wordpress Posts Are Showing In Reverse Order (oldest first)

I am helping a friend with their Wordpress site and all of their blog posts are showing in reverse order (oldest first).我正在帮助一个朋友使用他们的 Wordpress 网站,他们所有的博客文章都以相反的顺序显示(最早的在前)。 I haven't found any plugins responsible and haven't identified any code that was added.我没有找到任何负责的插件,也没有发现任何添加的代码。 I also tried adding the code我也尝试添加代码

//function to modify default WordPress query
function wpb_custom_query( $query ) {

// Make sure we only modify the main query on the homepage  
    if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {

        // Set parameters to modify the query
        $query->set( 'orderby', 'date' );
        $query->set( 'order', 'DESC' );
        $query->set( 'suppress_filters', 'true' );
    }
}

// Hook our custom query function to the pre_get_posts 
add_action( 'pre_get_posts', 'wpb_custom_query' );```

They are using the theme RT-Theme 18

Does anyone have any idea why this might be happening?

As mentioned by @fraggley, start off by disabling all plugins and setting the theme to TwentyTwenty (the default theme).正如@fraggley 所提到的,首先禁用所有插件并将主题设置为 TwentyTwenty(默认主题)。 The RT-Theme 18 also exhibits similar behaviour in their demo with no obvious setting to change this behaviour. RT-Theme 18 在他们的演示中也表现出类似的行为,没有明显的设置来改变这种行为。 If you aren't already, ensure you're making customisations in a child-theme.如果您还没有,请确保您在儿童主题中进行自定义。 Without creating a new function, try using a standard loop to start off to see whether the order is still incorrect.在不创建新的 function 的情况下,尝试使用标准循环启动,看看顺序是否仍然不正确。

<?php

get_header();

if ( have_posts() ) : 

    while ( have_posts() ) : the_post();

        the_content();

    endwhile;

else :

    _e( 'Sorry, no posts matched your criteria.', 'textdomain' );

endif;

get_footer();

?>

This would typically be placed in your home.php or index.php at the root of your child theme.这通常放在您的 home.php 或 index.php 子主题的根目录中。 WordPress provides good documentation on this in their codex . WordPress 在他们的codex中提供了很好的文档。 You can determine this by checking which file the original code occurs in the parent theme.您可以通过检查原始代码出现在父主题中的哪个文件来确定这一点。 So if the loop occurs in the parent theme home.php, create a file called home.php in the same relative location on your child theme.因此,如果循环出现在父主题 home.php 中,请在子主题的相同相对位置创建一个名为 home.php 的文件。 More documentation on this here .更多关于这里的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM