• Resolved Andres Soop

    (@moonfly)


    Hey

    I am looking for a way to have most of my category pages showing full posts, except just 1 or 2, where I would like to see only part of the post with the link “Continue reading” which will reveal the whole post.

    I am using a theme where I can change either to one or another.

    So leaving “show full post” to “yes”, is there a way to exclude some specific categories from that.

    Here is the function:

    if ( ! function_exists( 'ct_author_excerpt' ) ) {
    	function ct_author_excerpt() {
    
    		global $post;
    		$show_full_post = get_theme_mod( 'full_post' );
    		$read_more_text = get_theme_mod( 'read_more_text' );
    		$ismore         = strpos( $post->post_content, '<!--more-->' );
    
    		if ( ( $show_full_post == 'yes' ) && ! is_search() ) {
    			if ( $ismore ) {
    				// Has to be written this way because i18n text CANNOT be stored in a variable
    				if ( ! empty( $read_more_text ) ) {
    					the_content( wp_kses_post( $read_more_text ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    				} else {
    					the_content( __( 'Continue reading', 'author' ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    				}
    			} else {
    				the_content();
    			}
    		} elseif ( $ismore ) {
    			if ( ! empty( $read_more_text ) ) {
    				the_content( wp_kses_post( $read_more_text ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    			} else {
    				the_content( __( 'Continue reading', 'author' ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    			}
    		} else {
    			the_excerpt();
    		}
    	}
    }

    I have no knowledge in php to do it properly, a help would be appreciated ??

Viewing 1 replies (of 1 total)
  • Thread Starter Andres Soop

    (@moonfly)

    I managed to figure it out.
    by default the show full post is set to YES.

    Here is the code:

    if ( ! function_exists( 'ct_author_excerpt' ) ) {
    	function ct_author_excerpt() {
    
    		global $post;
    		$categories = get_the_category( $post->ID );
    		$show_full_post = get_theme_mod( 'full_post' ) ;
    		$read_more_text = get_theme_mod( 'read_more_text' );
    		$ismore         = strpos( $post->post_content, '<!--more-->' );
    
    		if ( ( $show_full_post == 'yes' ) && ! is_search() ) {
    			if ( $ismore ) {
    				// Has to be written this way because i18n text CANNOT be stored in a variable
    				if ( ! empty( $read_more_text ) ) {
    					the_content( wp_kses_post( $read_more_text ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    				} else {
    					the_content( __( 'Continue reading', 'author' ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    				}
    				// Next part edited by Andres
    			} else {
    				if ( is_category ( array ( '106' , '107' ) ) ) {
    					the_content();
    				} else {
    					the_excerpt();
    				}
    			}	
    
    		} elseif ( $ismore ) {
    			if ( ! empty( $read_more_text ) ) {
    				the_content( wp_kses_post( $read_more_text ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    			} else {
    				the_content( __( 'Continue reading', 'author' ) . " <span class='screen-reader-text'>" . get_the_title() . "</span>" );
    			}
    		} else {
    			the_excerpt();
    		}
    	}
    }

Viewing 1 replies (of 1 total)
  • The topic ‘How to exclude 1 or 2 category from showing full post’ is closed to new replies.