WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] custom style does not show for pages in search results (7 posts)

  1. chez-victoria
    Member
    Posted 1 year ago #

    Hi, I was wondering if there's anything that can fix how my coding seems to be stripped for pages in the search results page?

    This versus this.

    Thank you!! :)

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    search result templates in some themes use the_excerpt() instead of the_content() in the loop;
    http://codex.wordpress.org/Function_Reference/the_excerpt

    check if your theme has a search.php, and if, check for those functions and replace them accordingly.

  3. chez-victoria
    Member
    Posted 1 year ago #

    Hmmm there doesn't seem to be the_excerpt() in my search.php? This is all there is:

    <?php get_header() ?>
    
    <h1 class="archive-title">
    	<?php printf( __( 'Search Results for: %s', 'origami' ), '<span>' . get_search_query() . '</span>' ); ?>
    </h1>
    
    <?php if(have_posts()) : ?>
    	<?php get_template_part('loop', 'index') ?>
    	<div id="posts-nav">
    		<?php posts_nav_link('', __('forward', 'origami'), __('backward', 'origami')); ?>
    	</div>
    <?php else : ?>
    	<div class="content">
    		<?php print so_setting('messages_no_results') ?>
    	</div>
    <?php endif ?>
    
    <?php get_footer() ?>
  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    follow this clue:

    <?php get_template_part('loop', 'index') ?>

    and have a look in loop-index.php or loop.php

    might be in the form of a conditional statement such as:

    <?php if( is_search() ) : ?>
    <?php the_excerpt(); ?>
    ...

    or similar.

  5. chez-victoria
    Member
    Posted 1 year ago #

    Ahh this is so strange but I cannot find the_excerpt() in loop.php or in the rest of the .php files as well. I'll put up my loop.php in case it helps:

    <?php if(have_posts()) : ?>
    	<?php while(have_posts()) : the_post(); global $post; ?>
    		<div <?php post_class() ?>>
    
    			<?php if(has_post_thumbnail() && get_post_format() != 'image' && so_setting('display_featured_image')) : ?>
    				<div class="featured-image">
    					<?php the_post_thumbnail(null, array('class' => 'main-image desktop')) ?>
    					<?php the_post_thumbnail('post-thumbnail-mobile', array('class' => 'main-image mobile')) ?>
    				</div>
    			<?php endif; ?>
    
    			<?php if(!in_array(get_post_format(), array('aside', 'link', 'status'))) : ?>
    				<h1 class="entry-title">
    					<?php if(is_singular()) : ?>
    					<?php the_title() ?>
    					<?php else : ?>
    					<a href="<?php the_permalink() ?>"><?php the_title() ?></a>
    					<?php endif; ?>
    				</h1>
    
                                            <div class="post-info"><?php if(has_category()) :  ?>
    					[ <?php the_category(', ') ?> ]
    					<?php endif; ?>
    				</div>
    
    					 <div class="date"><a href="<?php the_permalink() ?>"><?php the_date() ?></a></div>
    			<?php endif; ?>
    
    			<?php
    			if(so_setting('display_use_columns') && get_post_format() === false){
    				$columns = get_post_meta($post->ID, 'content_columns', true);
    				if($columns === false) $columns = 2;
    			}
    			else $columns = 1;
    			?>
    			<div class="content column-<?php print $columns ?>">
    				<?php if(has_post_thumbnail() && get_post_format() == 'image') : ?>
    					<div class="featured-image">
    						<?php the_post_thumbnail(null, array('class' => 'main-image desktop')) ?>
    						<?php the_post_thumbnail('post-thumbnail-mobile', array('class' => 'main-image mobile')) ?>
    					</div>
    				<?php endif; ?>
    
    				<?php the_content(' '); ?>
    				<div class="clear"></div>
    			</div>
    
    			<?php
    			wp_link_pages(array(
    				'before' => '<p class="page-links content">' . __('Pages:', 'origami'),
    				'after' => '</p>',
    			))
    			?>
    
    			<?php $tags = wp_get_post_tags($post->ID); ?>
    			<?php if(!empty($tags) || !is_singular()) : ?>
    				<div class="below-content">
    					<p>
    <?php comments_popup_link( '♡ Leave a comment', '♡  1 comment', '♡  % comments', '♡  comments-link', '♡  Comments are off for this post'); ?>
                                                   </p>
                                                    <?php if(has_tag()) : ?>
    						<div class="tags">
    							<svg version="1.1" width="18px" height="18px" viewBox="0 0 48 48">
    								<path d="M 41.29511 48 L 41.29511 .091884613 L 6.999998 .091884613 L 6.999998 47.78994 L 24.042513 30.74741 Z" />
    							</svg>
    							<div class="the_tags">
    								<?php the_tags('') ?>
    							</div>
    						</div>
    					<?php endif ?>
    
    					<?php if((!is_singular() && preg_match( '/<!--more(.*?)?-->/', $post->post_content )) || empty($post->post_title)) : ?>
    						<div class="read-more">
    							<a href="<?php the_permalink() ?>"><?php _e('Continue Reading', 'origami') ?></a>
    							<svg version="1.1" width="18px" height="18px" viewBox="0 0 48 48">
    								<path d="M 0 32 L 0 16 L 26 16 L 26 8 L 48 24 L 26 40 L 26 32 Z" />
    							</svg>
    						</div>
    					<?php endif; ?>
    					<div class="clear"></div>
    
    					<?php if(is_singular() && so_setting('social_share')) locate_template('social-share.php', true); ?>
    				</div>
    			<?php elseif(so_setting('social_share') && function_exists('so_share_render')) : so_share_render(array('twitter' => so_setting('social_twitter'))); endif; ?>
    
    			<?php if(is_singular()) : ?>
    				<div id="single-comments-wrapper">
    					<?php comments_template() ?>
    				</div>
    			<?php endif; ?>
    
    		</div>
    	<?php endwhile; ?>
    <?php endif; ?>

    Sorry this is so troublesome!

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the 'formatting' actually does not come from the page content itself, but from the template; the search result is missing the .post class which does the centering.

    possibly edit loop.php; change this (third line from the top):

    <div <?php post_class() ?>>

    to:

    <div <?php post_class('post') ?>>

    this forces the .post class even for the search results.

  7. chez-victoria
    Member
    Posted 1 year ago #

    It worked, thank you!! :)

Topic Closed

This topic has been closed to new replies.

About this Topic