Site logo

Archived topic

Custom result page and taxonomy

21 replies · Started by Cris on April 25, 2019

Viewing posts 1–15 of 22

Hello,
I need to modify the results page of the searches and taxonomies. How or from where can I modify them?
I have seen that changes can be made from the customizer (in the options of the blog), but this forces me to modify the blog and that is not what I want.

Thanks Leo, that helps me for the search results. For the results of the taxonomies, it does not work. How can I modify them? I would like to use "WP Show Posts Pro" to applicate here.

Those options won't work with WP Show Posts, as it's a different plugin altogether.

If you're using the theme to output the taxonomy archives, you should just be able to duplicate your search results code and use is_tax() instead of is_search().

I do not know if it is possible to put the image, smaller, next to the title. Because the images of the taxonomies are very small and of poor quality.

I do that but doesn't work. Report this error:
Cannot redeclare lh_custom_search_results_page_settings() (previously declared in wp-content/themes/generatepress_child/functions.php:18)

The code is:

add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
    if ( is_tax() ) {
	$options['read_more_button'] = true;
	$options['date'] = false;
	$options['categories'] = false;
	$options['tags'] = false;
	$options['comments'] = false;
    $options['infinite_scroll'] = true;
	$options['infinite_scroll_button'] = true;
	$options['masonry_load_more'] = 'Ver más resultados';
	$options['masonry_loading'] = 'Cargando más resultados';
	$options['post_image'] = true;
	$options['post_image_position'] = 'post-image-above-header';
	$options['post_image_alignment'] = 'post-image-aligned-center';
	$options['column_layout'] = false;
	$options['featured_column'] = false;
	$options['masonry'] = false;
    }
  
    return $options;
}

You need to change the function name to something else.

For example, replace lh_custom_search_results_page_settings with lh_custom_taxonomy_page_settings

It needs to be changed in the function name and in the add_filter function.

Works, thanks!

You're welcome :)

Hi i have the same question, i want to change the default search page. and i read the document on
https://docs.generatepress.com/article/option_generate_blog_settings/#examples

but where can i put the code on?

this code:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( is_search() ) {
$options['read_more_button'] = true;
$options['date'] = false;
$options['categories'] = false;
$options['tags'] = false;
$options['comments'] = false;
$options['infinite_scroll'] = true;
$options['infinite_scroll_button'] = true;
$options['masonry_load_more'] = 'More search results';
$options['post_image'] = true;
$options['post_image_position'] = 'post-image-above-header';
$options['post_image_alignment'] = 'post-image-aligned-center';
$options['column_layout'] = false;
$options['featured_column'] = true;
$options['masonry'] = false;
}

return $options;
}

thank you

Hi

Tom, I think that something is wrong with taxonomy page because the code doesn't work well. See here please. In search result work well, masonry, column, etc. In taxonomy only work post_image_alignment. Why?

Michael, to add code read this instructions: https://docs.generatepress.com/article/adding-php/

Can you show me your full code?

THanks cris

I have this in function.php

<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/

function generatepress_child_enqueue_scripts() {
if ( is_rtl() ) {
wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
}
}
add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );

/*Resultados búsquedas*/
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( is_search() ) {
$options['read_more_button'] = true;
$options['date'] = false;
$options['categories'] = false;
$options['tags'] = false;
$options['comments'] = false;
$options['infinite_scroll'] = true;
$options['infinite_scroll_button'] = true;
$options['masonry_load_more'] = 'Ver más resultados';
$options['masonry_loading'] = 'Cargando más resultados';
$options['post_image'] = true;
$options['post_image_position'] = 'post-image-above-header';
$options['post_image_alignment'] = 'post-image-aligned-center';
$options['column_layout'] = false;
$options['featured_column'] = false;
$options['masonry'] = false;
}

return $options;
}

/*Resultados taxonomías*/
add_filter( 'option_generate_blog_settings', 'lh_custom_taxonomy_page_settings' );
function lh_custom_taxonomy_page_settings( $options ) {
if ( is_tax() ) {
$options['read_more_button'] = false;
$options['infinite_scroll'] = true;
$options['infinite_scroll_button'] = true;
$options['masonry_load_more'] = 'Ver más resultados';
$options['masonry_loading'] = 'Cargando más resultados';
$options['post_image'] = true;
$options['post_image_position'] = 'post-image-above-header';
$options['post_image_alignment'] = 'post-image-aligned-left';
$options['column_layout'] = false;
$options['featured_column'] = false;
$options['masonry'] = false;
}

return $options;
}

/*Buscar solo en post*/
function buscador_mostrar_solo_posts($query)
{
if ($query->is_search)
{
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'buscador_mostrar_solo_posts');

Your code looks ok, but I can't see the page as it's behind a coming soon page.

Sorry, Try now.

This archived topic is closed to new replies.