仅在主页上删除分页功能

时间:2020-11-20 作者:Yudi Anto

这是我索引的完整代码。php

<?php
/**
 * The main template file.
/* Exit if accessed directly */
if ( ! defined( \'ABSPATH\' ) ) {
    exit;
}

get_header();

/* Blog layout options via customizer */
$blog_layout = get_theme_mod( \'gmr_blog_layout\', \'gmr-smallthumb\' );

?>

<div id="primary" class="col-md-main">
    <div class="content-area">
        <?php
        $modulehome = get_theme_mod( \'gmr_active-module-home\', 0 );
        if ( 0 === $modulehome ) {
            do_action( \'bloggingpro_display_modulehome\' );
        }
        ?>
        <?php do_action( \'bloggingpro_banner_after_modulehome\' ); ?>

        <?php
        $carousel = get_theme_mod( \'gmr_active-headline\', 0 );
        if ( 0 === $carousel ) {
                do_action( \'bloggingpro_display_carousel\' );
        }
        ?>
        <main id="main" class="site-main gmr-infinite-selector" role="main">
        <?php
        if ( have_posts() ) :
            $count = 0;

            if ( is_home() && ! is_front_page() ) :
                ?>
                <header>
                    <h1 class="page-title screen-reader-text" <?php echo bloggingpro_itemprop_schema( \'headline\' ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?>><?php single_post_title(); ?></h1>
                </header>
                <?php
            endif;

            if ( is_front_page() && is_home() ) :
                ?>
                <header>
                    <h1 class="page-title screen-reader-text"><?php bloginfo( \'name\' ); ?></h1>
                </header>
                <?php
            endif;

            echo \'<div id="gmr-main-load">\';

            /* Start the Loop */
            while ( have_posts() ) :
                the_post();
                $count++;
                $current_page = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;

                /*
                 * Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                 */
                get_template_part( \'template-parts/content\', get_post_format() );

                do_action( \'bloggingpro_banner_between_posts\' );

                if ( 6 === $count && 1 === $current_page ) {
                    /* Home module */
                    if ( is_active_sidebar( \'module-after-1\' ) ) {
                        echo \'<div class="gmr-box-content item-infinite home-module">\';
                        dynamic_sidebar( \'module-after-1\' );
                        echo \'</div>\';
                    }
                }

                if ( 9 === $count && 1 === $current_page ) {
                    /* Home module 2 */
                    if ( is_active_sidebar( \'module-after-2\' ) ) {
                        echo \'<div class="gmr-box-content item-infinite home-module">\';
                        dynamic_sidebar( \'module-after-2\' );
                        echo \'</div>\';
                    }
                }

            endwhile;
            echo \'</div>\';

            echo gmr_get_pagination(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

        else :

            get_template_part( \'template-parts/content\', \'none\' );

        endif;
        ?>

        </main><!-- #main -->
    </div><!-- .content-area -->
</div><!-- #primary -->

<?php
get_sidebar();

get_footer();
我试图删除我的主页上的分页,但允许它在其他页面上,如存档,类别

如果我删除此行

echo gmr_get_pagination();
使用分页的存档和其他页面被破坏

有人能帮我吗?

谢谢

1 个回复
最合适的回答,由SO网友:user3135691 整理而成

你可以试着用一点if语句来回避这个问题。

像这样:

<?php

// If it\'s not the homepage, do the pagination
if(!is_home()){
    echo gmr_get_pagination();
}
?>
希望这能起作用。

相关推荐

从函数.php内修改_POSTS_PAGINATION,而不是模板文件

我知道使用如下函数(在functions.php) 允许我自定义分页选项:function custom_theme_pagination(){ global $wp_query; echo paginate_links(); } 。。。前提是主题文件包含<?php custom_theme_pagination(); ?> 无论我希望分页显示在哪里。然而,我想要实现的是控制<?php the_posts_pagination(); ?