Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #154699

    danielmoutou
    Participant

    Hello there!
    I’m using the latest Ethos stack with WordPress 4.0.1 and I have set up a child theme.

    I have a portfolio page with the portfolio-items displayed on four columns : http://wp.mof69.fr/annuaire-des-mof-du-rhone/

    I also have a custom sidebar with a few custom taxonomies to search through (the category filtering didn’t suit my needs).

    For now, when I perform a search, I get something like the default blog index page: http://wp.mof69.fr/bienetrebeaute/esthetique/?post_types=x-portfolio

    Is it possible to display a search results page like the portfolio page is set up and displayed (masonry-like, number of columns, number of items)? And additionally, to keep the custom sidebar of the portfolio page in the search results page?

    Cheers,
    Daniel

    #155011

    Christopher
    Moderator

    Hi there,

    Search page doesn’t have page template .It get the blog page style.
    You can use CSS below to change the number items per row ,but it won’t be masonry exactly.
    Please add the following CSS code under Customize -> Custom -> CSS:

    @media (min-width:979px){
    .search-results article {
    width: 24.95%;
    padding: 0 1em 2em !important;
    float: left;
    }
    .search-results .entry-wrap {
    width: 100% !important;
    padding-left: 0 !important;
    }
    .search-results .entry-content.excerpt {
    display: none;
    }
    .search-results h2.entry-title {
    font-size: 90%;
    }
    }

    Hope it helps.

    #155971

    danielmoutou
    Participant

    Hello, X-man (or X-woman)

    Thanks a lot for your answer. I tried your code but there were some display issues with my stack (Ethos).
    Anyway, I found that if I select Masonry style for the Archives page in Customizer > Blog, my search page for the portfolio items inherits that setting. So I’m half happy.

    But it would be GREAT if there was a way to override the number of items displayed in that search page…

    Cheers,
    Daniel

    #156025

    Zeshan
    Member

    Hi Daniel,

    Thank you for writing in!

    You can change the number of posts/items displayed in the search page by going into General > Reading and change the number under Blog pages show at most to your desired value (see: http://prntscr.com/5c64xk).

    Hope this helps. 🙂

    Thank you.

    #156085

    danielmoutou
    Participant

    Hi, X Support!

    That’s precisely the default behavior I’d like to override: I want the index page to display 5 blog posts while the search page shows 20 results, for example.

    Cheers,
    Daniel

    #156175

    Nabeel A
    Moderator

    Hi Daniel,

    Did you change the Blog pages show at most to 5? This will display 5 posts per page.

    #156392

    danielmoutou
    Participant

    Hi,
    Yes, that’s what I did. But I’d like the search page to display a different number of items.

    #156497

    Kosher K
    Member

    Hi There,

    can you try adding this code below,

    function cmk_custom_mod( $wp_query ) {
    	$post_type = $wp_query->query['post_type'];
    	if ( $post_type == 'x-portfolio' && is_search() ) {
    		$wp_query->set('posts_per_page', '25');
        }
    }
    add_filter('pre_get_posts', 'cmk_custom_mod');

    or this one

    function cmk_post_result_limits( $limit, $query ) {
    
    	if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
    		return 'LIMIT 0, 25';
    	}
    	return $limit;
    }
    add_filter( 'post_limits', 'cmk_post_result_limits', 10, 2 );

    Hope that helps,
    Cheers

    #156721

    danielmoutou
    Participant

    Hi there,

    I’m sorry, but where do I have add this code exactly? In x-child-ethos/functions.php?

    Cheers,
    Daniel

    #156757

    Kosher K
    Member

    Hi Daniel,

    Sorry for not being specific,

    and yes, please try adding it on your child theme functions.php

    Let me know how it works

    #156795

    danielmoutou
    Participant

    Well, it works with the second code. But only with a regular search like: http://wp.mof69.fr/?s=cuisinier

    And not with a search through x-portfolio post types using custom taxonomies, like:
    http://wp.mof69.fr/gastronomie/cuisinier/?post_types=x-portfolio

    Cheers,
    Daniel

    #156853

    Kosher K
    Member

    Hi Daniel,

    I’m not really sure what you are trying to accomplish,

    But this url http://wp.mof69.fr/gastronomie/cuisinier/?post_types=x-portfolio is not a search url, that is an archive page,

    You may want to try if ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive('x-portfolio') )

    Please check all conditional statement here -> http://codex.wordpress.org/Conditional_Tags and use the one that is for the page result you are trying to modify.

    #156950

    danielmoutou
    Participant

    Hi my friend,

    Oh… I guess that’s what happens when a web designer speaks about web development 😉
    But I think I understand the difference now.
    Anyway, I tried ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive('x-portfolio') ) instead of if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) but it didn’t change anything. I’ll check the WordPress codex…

    Cheers,
    Daniel

    #157001

    Kosher K
    Member

    Sorry,

    It should be like this if ( ! is_admin() && $query->is_main_query() && is_post_type_archive('x-portfolio') )

    If that doesn’t work try the main page argument first,

    e.g. only this one if ( is_post_type_archive('x-portfolio') )

    Cheers

    #159422

    danielmoutou
    Participant

    Hello, there
    Sorry for not replying earlier but I forgot to check “subscribe” again –which is quite annoying by the way.

    Anyway, to sum it up, I tried to add at the end of my child theme’s functions.php:

    function cmk_post_result_limits( $limit, $query ) {
    
      if ( ! is_admin() && $query->is_main_query() && is_post_type_archive('x-portfolio') ) {
        return 'LIMIT 0, 25';
      }
      return $limit;
    }
    add_filter( 'post_limits', 'cmk_post_result_limits', 10, 2 );

    and also this:

    function cmk_post_result_limits( $limit, $query ) {
    
      if ( ! is_post_type_archive('x-portfolio') && is_admin() && $query->is_main_query() ) {
        return 'LIMIT 0, 25';
      }
      return $limit;
    }
    add_filter( 'post_limits', 'cmk_post_result_limits', 10, 2 );

    and also that:

    function cmk_post_result_limits( $limit, $query ) {
    
      if ( is_post_type_archive('x-portfolio') ) {
        return 'LIMIT 0, 25';
      }
      return $limit;
    }
    add_filter( 'post_limits', 'cmk_post_result_limits', 10, 2 );

    … none of them worked 🙁

    Cheers,
    Daniel