Archives

Home Forums Search Search Results for 'is_paged()'

Search Results for 'is_paged()'

Home Forums Search Search Results for 'is_paged()'

Viewing 15 results - 1 through 15 (of 70 total)
  • Author
    Search Results
  • #1937017
    anita

    Hi,

    We would like to add the custom-post-type name (label) to the search results article title.

    Formerly, with twentynineteen we changed the search like this:

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<?php
    		if ( is_sticky() && is_home() && ! is_paged() ) {
    			printf( '<span class="sticky-post">%s</span>', _x( 'Featured', 'post', 'twentynineteen' ) );
    		}
    		echo '<h3>';
    		the_title( sprintf( '<a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '' );
    		
    		if( 'xxx' == get_post_type() ) {
    				echo ' - ' . get_post_type_object(get_post_type($r->id))->labels->singular_name . '';
    	       	}
            	else if ( 'yyy' == get_post_type() ) {
    				echo ' - ' . get_post_type_object(get_post_type($r->id))->labels->singular_name . '';
            	}
            	else if ( 'zzz' == get_post_type() ) {
    				echo ' - ' . get_post_type_object(get_post_type($r->id))->labels->singular_name . '';
            	}
                echo '</a></h3>';
    		
    		?>
    	</header><!-- .entry-header -->
    </article>

    How to achieve this with GP?

    Thanks!

    Ying
    Staff
    Customer Support

    Hi Matt,

    You can try this PHP snippet:

    add_filter( 'generate_block_element_display', function( $display, $element_id ) {
        if ( 100 === $element_id && is_paged() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Replace the 100 with your block element ID which can be found in the URL of the block element:
    https://www.screencast.com/t/BkrLmjoVZ

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

    Let me know if this helps 🙂

    nomadiceman

    if you mean this, I added it and the site broke

    add_action('init', function(){
        global $displayed_posts;
        $displayed_posts = '';
    },100);
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 13152 === $element_id && is_paged() ) { 
            $display = false;
        } 
    
        return $display;
    }, 10, 2 );
    David
    Staff
    Customer Support

    Hi there,

    to confirm – you have the Block Element, and you only want it displayed on Page 1 of Tag Archive Term you have specified in the Element Display Rules ?

    If so you should only need to do:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 12345 === $element_id && is_paged() ) { 
            $display = false;
        } 
    
        return $display;
    }, 10, 2 );

    Change the 12345 for the Element ID.
    And this will simply tell it not to display on a paged view.

    nomadiceman

    Im not a developer so I am unsure, but I think you may need to know that I am using this snippet also given from one of your team

    add_filter( 'generate_block_element_display', function( $display, $element_id ) {
        if ( 11587 === $element_id && !is_paged() && is_tag() ) { 
            $display = true;
        } 
    
        if ( 11587 === $element_id && is_paged() && is_tag() ) { 
            $display = false;
        }
        if ( 11953 === $element_id && !is_paged() && is_tag() ) { 
            $display = false;
        } 
    
        if ( 11953 === $element_id && is_paged() && is_tag() ) { 
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    I added that to the site so that pages 2 onwards of the tag pages have a different header.

    I am guessing that’s what’s causing a conflict or something

    Let me know your thoughts

    Mark

    Can you confirm exactly where I add this code? I seem to be getting errors when I add it. Here is what exists already:

    add_filter( ‘generate_element_display’, function( $display, $element_id ) {
    if ( 4003 === $element_id && is_paged() ) {
    $display = false;
    }

    return $display;

    }, 10, 2 );

    I also want to let the breadcrumb display too

    Mark

    Hi Elvin,

    Yes, I’m using GP Premium (2.0.3).

    I’m using a Child Theme (the template from GP)

    In the functions.php section of the child theme, I’ve added the following code:


    /*
    ========================================================
    Display Custom Category text on 1st Category page ONLY
    ========================================================
    */

    add_filter( ‘generate_element_display’, function( $display, $element_id ) {
    if ( 4003 === $element_id && is_paged() ) {
    $display = true;
    }

    return $display;
    }, 10, 2 );

    =======
    4003 is the postid for the Element I created for a particular category.

    Element type: Hook
    Hook name: after_header

    #1896884
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Looking through the code – this doesn’t look possible right now, unfortunately. We need to add some more filters in the dynamic content block.

    Two options:

    1. Give the content a custom class and use CSS to hide it on paginated pages.
    2. Use a shortcode instead of the dynamic content block:

    add_shortcode( 'paged_dynamic_content', function() {
        if ( is_paged() ) {
            return;
        }
    
        return sprintf(
            '<div class="dynamic-term-description">%s</div>',
            term_description()
        );
    } );

    Let us know if you need more info 🙂

    David
    Staff
    Customer Support

    Hi there,

    only in this line – where it references the ID:

    if ( 10 === $element_id && is_paged() ) {

    You can multiple snippets for each of your conditons.

    OR you can add multiple conditions if you like:

    eg.

    if ( ( 10 === $element_id || 20 === $element_id || 30 === $element_id ) && is_paged() ) {

    This will check if any of the $element_IDs are present, AND if its paged.

    NOTE: The || = OR

    #1895301
    Chaitanya

    After doing hours of research, I added the below code

    add_filter( ‘generate_block_element_display’, function( $display, $element_id ) {
    if ( 58 === $element_id && is_paged() ) {
    $display = false;
    }

    return $display;
    }, 10, 2 );

    And the Problem is solved.

    Mark

    Hi Leo,

    I believe this is the code I should be implementing:

    add_filter( ‘generate_element_display’, function( $display, $element_id ) {
    if ( 10 === $element_id && is_paged() ) {
    $display = true;
    }

    return $display;
    }, 10, 2 );

    In the notes on the link you sent, it says “You need to replace 10 with the ID of your Element.” Do I replace both “10” placements in the above, and how do I determine the number of the Element(s) I want to change?

    I have 3 elements I want to change – can I add them all in this one piece code, or do I need to copy/paste the code in functions.php for each Category and change the “10” of each?

    #1873612
    Leo
    Staff
    Customer Support

    Hi there,

    Try this PHP snippet:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 1111 === $element_id && is_paged() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Change 1111 to the actual ID of the element.

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

    Let me know if this helps 🙂

    Elvin
    Staff
    Customer Support

    By adding the is_category() to the condition specifying the category.

    Example:

    if ( 10 === $element_id && !is_paged() && is_category('news') )

    A wise man once said:
    "Have you cleared your cache?"

    nomadiceman

    Hmm, seems still not to function correctly.

    Ive added this in the “Code Snippet” plugin, is it correct? I’ve give you the link to my staging site

    add_filter( 'generate_header_element_display', function( $display, $element_id ) {
        if ( 9508 === $element_id && !is_paged() ) { 
            $display = true;
        } 
    
        if ( 9508 === $element_id && is_paged() ) { 
            $display = false;
        }
        if ( 11954 === $element_id && !is_paged() ) { 
            $display = false;
        } 
    
        if ( 11954 === $element_id && is_paged() ) { 
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    9508 – The top element header

    11954 – The element header that ive put “Page 2+” text to the side of the title

    Any ideas of what’s going on?

    Elvin
    Staff
    Customer Support

    if 1st page of archive, display header element id 10
    if page 2 onwards of archive, don’t display header element id 10
    if 1st page of archive, don’t display header element id 20
    if 1st page of archive, display header element id 20

    ah yeah the comment is wrong. My bad.

    You can ignore or better yet, completely remove it as it’s not an important part of the code.

    Example:

    add_filter( 'generate_header_element_display', function( $display, $element_id ) {
        if ( 1234 === $element_id && !is_paged() ) { 
            $display = true;
        } 
    
        if ( 1234 === $element_id && is_paged() ) { 
            $display = false;
        }
        if ( 5678 === $element_id && !is_paged() ) { 
            $display = false;
        } 
    
        if ( 5678 === $element_id && is_paged() ) { 
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    This code set header ID 1234 to display on the 1st page of the archive page and set header id 5678 on page 2 onwards.

    A wise man once said:
    "Have you cleared your cache?"

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