Search Results for 'is_paged()'

Home Forums Search Search Results for 'is_paged()'

Viewing 15 results - 1 through 15 (of 39 total)
  • Author
    Search Results
  • Leo
    Staff
    Customer Support

    It should work just with a different filter:

    add_filter( 'generate_block_element_display', function( $display ) {
        if ( is_paged() ) {
           $display = false;
        }
    
        return $display;
    } );

    Let me know 🙂

    David
    Staff
    Customer Support

    Hi there,

    use this for your template condition:

    if ( is_front_page() && !is_paged() )

    Jiri

    Your PHP snippet took me to an interesting coding “trip”. 🙂 I have already resolved the first page before I wrote here. But the snippet, after some changes, is also usable to add new CSS classes into paged parts of infinite scroll. After some hard investigation I get to this version of PHP and jQuery codes.

    I changed the PHP snippet to use current page number to generate new classes for infinite scroll pages

    
    add_filter( 'post_class', function( $classes ) {
        
    	if ( is_paged() ) {
    	    $pagenum = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$classes[] = 'page-'.$pagenum.'-post';
    	}
    	
    	return $classes;
    	
    });
    

    jQuery script adding the tracking code I changed to use the new classes with current page number (and added also new functionality – add target _blank to the links)

    
    <script type="text/javascript">
    jQuery( document ).ready( function($) {
        var $container = $( '#main article' ).first().parent();
    
        $container.on( 'append.infiniteScroll', function( event, response, path, items ) {
            var $infScroll = $container.data('infiniteScroll');  //current page number
    	var pagenum = $infScroll.pageIndex;
    	var aclass1 = '.page-' + pagenum + '-post .post-image a'; //create css classes based on current page number
    	var aclass2 = '.page-' + pagenum + '-post h2.entry-title a';
      
    		//select all classes and set target _blank
            	document.querySelectorAll(aclass1 + "," + aclass2) 
            	.forEach(function(elem) {
            	elem.setAttribute('target', '_blank');
            	});
               
    			//select all classes and add tracking code prefix to href 			
    			$(aclass1 + "," + aclass2).one('click',function(){  
               		url=$(this).attr('href');
               		$(this).attr('href','/tracking/track.php?u=' + escape(url));
               		});
        } );
    } );
    </script>
    

    Thank you very much for the PHP snippet. It helped me a lot.
    Now it seems to be working fine. But I appreciate your possible suggestions to the new code.

    Have a nice rest of the weekend

    Tom
    Lead Developer
    Lead Developer

    Hmm, just did some searching around and couldn’t figure out a way to target newly appended items only.

    One idea is to add classes to the posts on the first page only, then target those classes:

    add_filter( 'post_class', function( $classes ) {
        if ( ! is_paged() ) {
            $classes[] = 'first-page-post';
        }
    
        return $classes;
    } );

    Then you could do this: .first-page-post .post-image a, .first-page-post h2.entry-title a

    #1393841
    David
    Staff
    Customer Support

    Try this condition:

    if ( 0 === $wp_query->current_post && !wp_is_mobile() && !is_paged() && !is_author() ) {

    #1393450
    Joey

    Thank you David. It worked well to remove the featured post but I have a longer excerpt on the featured post of the author page still. I had used the following code to make the excerpt longer:

    add_filter( 'excerpt_length', function( $length ) {
        global $wp_query;
        if ( 0 === $wp_query->current_post && !wp_is_mobile() && !is_paged() ) {
            $length = 50;
        } else {
            $length = 20;
        }
    	return $length;
    }, 200);

    Is there a way I can modify this code so it doesn’t affect the author pages?

    David
    Staff
    Customer Support

    Try changing this:

    if ( 0 === $wp_query->current_post && !wp_is_mobile() ) {

    to

    if ( 0 === $wp_query->current_post && !wp_is_mobile() && !is_paged() ) {

    David
    Staff
    Customer Support

    Hi there,

    yes, the method that Tom provided is to disable a Header Element when viewing a Paged page.
    How did you add the Meta Slider ? If its using a Hook Element then you would use this Filter:

    https://docs.generatepress.com/article/generate_hook_element_display/

    add_filter( 'generate_hook_element_display', function( $display ) {
        if ( is_paged() ) {
           $display = false;
        }
    
        return $display;
    } );
    David
    Staff
    Customer Support

    Hi there,

    you can use this PHP Snippet to disable the Header Element on paged template:

    add_filter( 'generate_header_element_display', function( $display ) {
        if ( is_paged() ) {
           $display = false;
        }
    
        return $display;
    } );

    Then those pages will respect the colors set in the Customizer.

    David
    Staff
    Customer Support

    Hi there,

    try wrapping your WPSP Shortcode in a condtion like this:

    <?php
    if ( !is_paged() ) {
        echo do_shortcode( '[wpsp shortcode here]' );
    }
    ?>
    #1283918

    In reply to: Featured Posts Grid

    David
    Staff
    Customer Support

    Sorry my bad… add this PHP Snippet to your Site:

    add_filter( 'generate_header_element_display', function( $display ) {
        if ( is_paged() ) {
           $display = false;
        }
    
        return $display;
    } );

    https://docs.generatepress.com/article/adding-php/

    #1278117

    In reply to: Magazine Grid

    Tom
    Lead Developer
    Lead Developer

    Hmm, this is a complicated one.

    What about this?:

    function my_function_for_excluding_posts( $query ) {
        if ($query->is_home() && $query->is_main_query()) {
            $query->set( 'offset', 4 );
        }
    }
    add_action( 'pre_get_posts', 'my_function_for_excluding_posts' );
    
    function myprefix_adjust_offset_pagination($found_posts, $query) {
        if ( $query->is_home() && $query->is_main_query() && ! $query->is_paged() ) {
            return $found_posts - 4;
        }
        return $found_posts;
    }
    add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
    #1277319

    In reply to: Magazine Grid

    Tom
    Lead Developer
    Lead Developer

    Hi there,

    What if you do this instead?:

    function my_function_for_excluding_posts( $query ) {
        if ($query->is_home() && $query->is_main_query() && ! $query->is_paged()) {
            $offset = 4;
            $paged = 0 == $query->get( 'paged' ) ? 1 : $query->get( 'paged' );
            $query->set( 'offset', $paged * $offset );
        }
    }
    add_action( 'pre_get_posts', 'my_function_for_excluding_posts' );
    
    function myprefix_adjust_offset_pagination($found_posts, $query) {
        if ( $query->is_home() && $query->is_main_query() && ! $query->is_paged() ) {
            return $found_posts - 5;
        }
        return $found_posts;
    }
    add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );

    Let me know 🙂

    #1267383
    Divakara

    Hi David,
    This is the code i have added to Hook element.
    https://prnt.sc/sa5oe9

    <?php
    /**
     * A template partial to output pagination for the Twenty Twenty default theme.
     *
     * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
     *
     * @package WordPress
     * @subpackage Twenty_Twenty
     * @since 1.0.0
     */
    
    /**
     * Translators:
     * This text contains HTML to allow the text to be shorter on small screens.
     * The text inside the span with the class nav-short will be hidden on small screens.
     */
    
    $prev_text = sprintf(
    	'%s <span class="nav-prev-text">%s</span>',
    	'<span aria-hidden="true">&larr;</span>',
    	__( 'Newer <span class="nav-short">Posts</span>', 'twentytwenty' )
    );
    $next_text = sprintf(
    	'<span class="nav-next-text">%s</span> %s',
    	__( 'Older <span class="nav-short">Posts</span>', 'twentytwenty' ),
    	'<span aria-hidden="true">&rarr;</span>'
    );
    
    $posts_pagination = get_the_posts_pagination(
    	array(
    		'mid_size'  => 1,
    		'prev_text' => $prev_text,
    		'next_text' => $next_text,
    	)
    );
    
    // If we're not outputting the previous page link, prepend a placeholder with visibility: hidden to take its place.
    if ( strpos( $posts_pagination, 'prev page-numbers' ) === false ) {
    	$posts_pagination = str_replace( '<div class="nav-links">', '<div class="nav-links"><span class="prev page-numbers placeholder" aria-hidden="true">' . $prev_text . '</span>', $posts_pagination );
    }
    
    // If we're not outputting the next page link, append a placeholder with visibility: hidden to take its place.
    if ( strpos( $posts_pagination, 'next page-numbers' ) === false ) {
    	$posts_pagination = str_replace( '</div>', '<span class="next page-numbers placeholder" aria-hidden="true">' . $next_text . '</span></div>', $posts_pagination );
    }
    
    if ( $posts_pagination ) { ?>
    
    	<?php if ( mytheme_is_amp() && ! is_paged()  ) : ?>
    		<?php
    		// @todo This is not the ideal way to obtain the subsequent pages, but WordPress doesn't provide such a way.
    		// @todo The page titles aren't ideal.
    		$pages = array_filter( array_map(
    			static function( $link ) {
    				if ( preg_match( '#<a.+?href="(.+?)">(.+?)</a>#s', $link, $matches ) ) {
    					$amp_url = html_entity_decode( $matches[1] );
    					$title   = html_entity_decode( $matches[2] );
    					return [
    						'title'  => $title,
    						'ampUrl' => $amp_url,
    						'image'  => get_site_icon_url(),
    					];
    				}
    				return null;
    			},
    			paginate_links( [ 'type' => 'array' ] )
    		) );
    
    		$amp_next_page = [
    			'pages'         => array_values( $pages ),
    			'hideSelectors' => [
    				'#site-header',
    				'.header-footer-group',
    				'#site-footer',
    				'#wpadminbar',
    			],
    		];
    		?>
    		<amp-next-page>
    			<script type="application/json"><?php echo wp_json_encode( $amp_next_page ); ?></script>
    		</amp-next-page>
    
    	<?php else : ?>
    
    		<div class="pagination-wrapper section-inner">
    
    			<hr class="styled-separator pagination-separator is-style-wide" aria-hidden="true" />
    
    			<?php echo $posts_pagination; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped during generation. ?>
    
    		</div><!-- .pagination-wrapper -->
    		<?php
    	endif;
    
    }
    #1240754
    Felipe

    Thank you very much, I just added it with the help of the code “Code Snippets” and I have placed it like this:

    add_filter( 'generate_site_title_output', function( $output ) {
    	return sprintf(
    		'<%1$s class="main-title" itemprop="headline">
    				<a href="%2$s" rel="home">
    					%3$s
    				</a>
    			</%1$s>',
    			( is_front_page() && is_home() && !is_paged()) ? 'p' : 'h1',
    			esc_url( apply_filters( 'generate_site_title_href', home_url( '/' ) ) ),
    			get_bloginfo( 'name' )
    	);
    } );

    😉

Viewing 15 results - 1 through 15 (of 39 total)