WordPress.org

Forums

Custom search results layout (2 posts)

  1. Kenn Nielsen
    Member
    Posted 2 years ago #

    Hi,

    I want to easily change the layout of the search results page, without making a lot of code changes or new files etc.

    The search page is

    if($format == '')
    get_template_part( 'includes/post-formats/standard' );

    Therefore I am editing the standard post page.

    I want to remove the p tag from excerpt IF it is on search page and then echo the excerpt for my permalink to show correctly underneath, but I can't get it working properly.

    The code on standard is:

    <div class="excerpt">
    
    <?php 
    
    $content = get_the_content();
    $excerpt = get_the_excerpt();
    
    if (has_excerpt() && (!is_search)) {
    
    	the_excerpt();
    
    	else (is_search()) {
    
      	$myExcerpt = get_the_excerpt();
      	$tags = array("<p>", "</p>");
      	$myExcerpt = str_replace($tags, "", $myExcerpt);
      	echo $myExcerpt;
    
    	}
    
    } else {
    
    	if(!is_search()) {
    
    	echo my_string_limit_words($content,135);
    
    	} else {
    
    	echo my_string_limit_words($excerpt,135);
    
    	}
    
    }
    
    if(is_search()) {
    echo '<p><span class="search-permalink">'; the_permalink(); echo'</span></p>';
    }
    
    ?>
    </div>

    I hope you can help me out :)

    Cheers,
    Kenn Nielsen

  2. Kenn Nielsen
    Member
    Posted 2 years ago #

    GOT IT! :)

    Can you guys confirm if the IF statement is correct?

    <div class="excerpt">
    
    <?php 
    
    $content = get_the_content();
    $excerpt = get_the_excerpt();
    
    if (has_excerpt() && !is_search() ) {
    
            the_excerpt();
    
            if (is_search()) {
    
            $myExcerpt = get_the_excerpt();
            $tags = array("<p>", "</p>");
            $myExcerpt = str_replace($tags, "", $myExcerpt);
            echo $myExcerpt;
    
            }
    
    } else {
    
            if(!is_search()) {
    
            echo my_string_limit_words($content,135);
    
            } else {
    
            echo my_string_limit_words($excerpt,135);
    
            }
    
    }
    
    if(is_search()) {
    echo '<p><span class="search-permalink">'; the_permalink(); echo'</span></p>';
    }
    
    ?>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic