Child version of search results in Pro?

do you have documentation on how to create a child theme version of the search results?

basically, I need to replace the_title() in the search results template with relevanssi_the_title() and i don’t want the change to be overwritten when I update.

Thanks

1 Like

Hello There,

Thanks for writing in!

What you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

To have a custom search page, you can check out this thread: https://theme.co/apex/forum/t/how-to-customize-the-search-page/27984/2

Hope this helps.

Are you sure this is the same process in Pro? I’ve followed the steps in the thread you referenced, but replaced “renew” with my stack (integrity) and also replaced the references to X with Pro i.e.

/wp-content/themes/pro/framework/views/integrity/

and not:

\wp-content\themes\x\framework\views\renew\

but all it seemed to do was stop returning any search results at all.

Here is the entire process of what I did:

  1. downloaded this: /wp-content/themes/pro/framework/views/integrity/wp-index.php

  2. in wp-index.php file, replaced this line:

<?php x_get_view( 'global', '_index' ); ?>

with this:

      <?php if(is_search()){
      	
        x_get_view( 'global', '_search' ); 
      }else{
      	x_get_view( 'global', '_index' ); 
      } ?>
  1. copied the newly updated file to the directory below (required creating the ‘integrity’ directory via sftp):
    /wp-content/themes/pro-child/framework/views/integrity/wp-index.php

  2. created a _search.php file with the following code:

    <?php

    // =============================================================================
    // VIEWS/GLOBAL/_SEARCH.PHP
    // -----------------------------------------------------------------------------
    // Includes the index output.
    // =============================================================================

    $stack = x_get_stack();

    ?>

    <?php if ( have_posts() ) : ?>
     <?php while ( have_posts() ) : the_post(); ?>
       <?php  x_get_view( $stack, 'content', get_post_format() ); ?>
     <?php endwhile; ?>
    
    <?php else : ?>
     <?php x_get_view( 'global', '_content-none' ); ?>
    
    <?php endif; ?> <?php pagenavi(); ?>
  3. uploaded to:
    /wp-content/themes/pro-child/framework/views/integrity

Also, no idea what’s going on with your forum, but for some reason it wants to show you that I do not know how to count. See left side editor, right side preview lol:

Pro child setup on backend:

Hi There,

I couldn’t find any _search.php or wp-index.php file in your child theme.

Did you remove them? Can you add them again?

Thank you.

I didn’t remove them:

Hey There,

Since you are using are using this line x_get_view( 'global', '_search' ); , the _search.php file must be place in the “global” folder and not inside the “integrity” folder.

Hope this helps. Please let us know how it goes.

Done:

So now that the child file has been created, I’m trying to replace the_title() in the search results template with relevanssi_the_title() (so that the Relevanssi plugin will highlight search phrases if they appear in titles of the search results) …however I noticed the _search.php file doesn’t seem to reference the_title() anywhere.

Where is this hiding?

Hello There,

The the_title() line can be found in wp-content/themes/x/framework/views/{your-stack}/_content-post-header.php file.

Hope this helps.

What’s the process for making a child version of _content-post-header.php? Similar to above?

Hi,

Yes, just create the same path in your child theme wp-content/themes/x-child/framework/views/{your-stack}/_content-post-header.php

Copy the file from your parent theme to your child theme then you can edit it as you wish.

Thanks

I’ve located the_title() and replaced with relevanssi_the_title() but no changes are taking place…

I know you can’t help me with a third party plugin, but are you sure that the search results titles from Pro are being generated from _content-post-header.php?

Hello There,

Yes the header titles in the search results is coming from _content-post-header.php file. Please provide ftp details so that we can check your file and hopefully resolve your issue.

Thank you.

I was able to resolve this issue after speaking with Relevanssi support. My final _content-post-header.php child file looks like this:

<?php

// =============================================================================
// VIEWS/INTEGRITY/_CONTENT-POST-HEADER.PHP
// -----------------------------------------------------------------------------
// Standard <header> output for various posts.
// =============================================================================

?>

<header class="entry-header">
  <?php if ( is_single() ) : ?>
  <h1 class="entry-title"><?php the_title(); ?></h1>
  <?php elseif ( is_search() && function_exists( 'relevanssi_the_title' ) ) : ?>
  <h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php relevanssi_the_title(); ?></a>
  </h2>
  <?php else : ?>
  <h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php x_the_alternate_title(); ?></a>
  </h2>
  <?php endif; ?>
  <?php x_integrity_entry_meta(); ?>
</header>

Also to clarify the previous message from @paul.r - since i’m using Pro and not X, this path is not accurate:

wp-content/themes/x-child/framework/views/{your-stack}/

My child file needed to go here:

wp-content/themes/pro-child/framework/views/{your-stack}/

Thank you for sharing the information.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.