- This topic has 8 replies, 2 voices, and was last updated 9 years, 4 months ago by
Tom.
-
AuthorPosts
-
November 29, 2016 at 11:22 am #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.
November 29, 2016 at 7:03 pm #249544Tom
Lead DeveloperLead DeveloperHi 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 🙂
November 29, 2016 at 11:19 pm #249593antware
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=durbanOnce again thank you for your valuable time in assisting.
November 29, 2016 at 11:45 pm #249600Tom
Lead DeveloperLead DeveloperWhat 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.
November 29, 2016 at 11:52 pm #249601antware
Thanks Tom, that got the images to display. Any ideas on the number of columns?
Also apologies for replying via email…blonde moment…
November 30, 2016 at 12:12 am #249603antware
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(); ?>>November 30, 2016 at 9:12 am #249793Tom
Lead DeveloperLead DeveloperTake 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
November 30, 2016 at 10:57 am #249860antware
Thanks Tom.
November 30, 2016 at 8:31 pm #250026Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.