[Resolved] Editing the Search Page

Home Forums Support Editing the Search Page

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #249303
    antware

    Hi Tom. I’m needing to edit the Search Page. Using the Relevanssi plugin and only needing my Custom Post Type to be searched. Everything working as expected. However I would like to edit the search page to change the layout. Have copied the search.php to my child theme and once opened I have commented out the sidebars as I want a full page width. However the content is at 75%, due to the class grid-75. So then here are my questions:

    1) How do I change those classes so that the results display at 100% width? Would have liked three columns but take it its pulling through the columns from the Blog Add On, where I set the number of columns to 2, although it is also set to masonry. But if not possible will settle for the 2 columns but would like them set to 100% (so 50% each).

    2) I would like to add an image above the Custom Post Type Title which is a custom field. Which file would I edit to make this happen? Where would I find this file:

    <?php get_template_part( ‘content’, ‘search’ ); ?>

    Look forward to any assistance in this regard. Thank you.

    #249544
    Tom
    Lead Developer
    Lead Developer

    Hi Antony,

    You can do most of this without editing the file.

    For example, making the search results have no sidebar is shown in the third code example on this page: https://generatepress.com/knowledgebase/choosing-sidebar-layouts/ (near the bottom).

    You can set the column count to be different as well using a similar method:

    add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
    function tu_search_column_count( $count )
    {
        if ( is_search() )
            return 3;
    
        return $count;
    }

    As for the image, you could try something along these lines:

    add_action( 'generate_before_content', 'tu_add_field_before_content' );
    function tu_add_field_before_content() {
        if ( is_post_type_archive( 'your_post_type' ) ) {
            echo $your_custom_field;
        }
    }

    Hope this helps 🙂

    #249593
    antware

    Hi Tom

    Thanks for that was able to remove the sidebar with the method you described. So now have 2 columns stretching full width. Check.

    However the Columns Number and Image methods had no effect.

    Used this code for the image:

    add_action( 'generate_before_content', 'tu_add_field_before_content' );
    function tu_add_field_before_content() {
        if ( is_post_type_archive( 'accommodation' ) ) {
            echo types_render_field( "hero-image", array( "size" => "thumbnail" ));
        }
    }

    I’m using Toolset Types to create my CPT and Custom Fields and this is the php code they use to display the image, so have modified it to slot into your code snippet. Not sure if that’s why it’s not working.

    <?php echo types_render_field( "consultant-photo", array( "size" => "thumbnail" )); ?>

    Regarding adding the image it is on the Search Page I need to display this with the results.

    Just to give you a better idea, I’ve added a link to a typical search:
    https://www.travelandstayinsa.co.za/?s=durban

    Once again thank you for your valuable time in assisting.

    #249600
    Tom
    Lead Developer
    Lead Developer

    What if you omit the if ( is_post_type_archive( 'accommodation' ) ) conditional?

    Need to see if it’s the conditional or the custom field not outputting the image.

    #249601
    antware

    Thanks Tom, that got the images to display. Any ideas on the number of columns?

    Also apologies for replying via email…blonde moment…

    #249603
    antware

    Also another thing Tom, how would I add classes as I would like to target elements only on the Search Page and not my Blog page as well? I see the classes are dynamically generated.

    <section id="primary" <?php generate_content_class(); ?>>
    		<main id="main" <?php generate_main_class(); ?>>
    #249793
    Tom
    Lead Developer
    Lead Developer

    Take a look at the bottom of this page to find out how to use the class filters: https://generatepress.com/knowledgebase/filter-list/

    As for columns, you need to find the right conditional for your conditions: https://codex.wordpress.org/Conditional_Tags

    #249860
    antware

    Thanks Tom.

    #250026
    Tom
    Lead Developer
    Lead Developer
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.