-
AuthorPosts
-
November 28, 2014 at 2:50 pm #154699
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,
DanielNovember 29, 2014 at 9:59 am #155011Hi 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.
December 1, 2014 at 11:23 am #155971Hello, 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,
DanielDecember 1, 2014 at 12:59 pm #156025Hi 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.
December 1, 2014 at 2:45 pm #156085Hi, 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,
DanielDecember 1, 2014 at 5:19 pm #156175Hi Daniel,
Did you change the Blog pages show at most to 5? This will display 5 posts per page.
December 2, 2014 at 3:39 am #156392Hi,
Yes, that’s what I did. But I’d like the search page to display a different number of items.December 2, 2014 at 7:15 am #156497Hi 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,
CheersDecember 2, 2014 at 11:41 am #156721Hi there,
I’m sorry, but where do I have add this code exactly? In x-child-ethos/functions.php?
Cheers,
DanielDecember 2, 2014 at 12:25 pm #156757Hi Daniel,
Sorry for not being specific,
and yes, please try adding it on your child theme functions.php
Let me know how it works
December 2, 2014 at 1:03 pm #156795Well, 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-portfolioCheers,
DanielDecember 2, 2014 at 2:20 pm #156853Hi 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.
December 2, 2014 at 3:32 pm #156950Hi 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 ofif ( ! is_admin() && $query->is_main_query() && $query->is_search() )
but it didn’t change anything. I’ll check the WordPress codex…Cheers,
DanielDecember 2, 2014 at 4:39 pm #157001Sorry,
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
December 6, 2014 at 7:08 am #159422Hello, 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 -
AuthorPosts