Community Forums › Forums › Archived Forums › Design Tips and Tricks › custom loop in search page no results
- This topic has 19 replies, 2 voices, and was last updated 9 years, 7 months ago by alexadark.
-
AuthorPosts
-
May 27, 2015 at 9:29 am #153829alexadarkMember
HI,
i'm working on a custom theme for a client
http://www.sarah.webstantly.com/
the loop on the homepage content posts with different categories, and the custom post type projects
all is customised trough the functions.phpNow the client wants that the search page no results: http://www.sarah.webstantly.com/?s=%60zxz%60x
has the same feed of posts as the homei have that in my function.php
//custom no result page remove_action( 'genesis_loop_else', 'genesis_do_noposts' ); add_action( 'genesis_loop_else', 'my_do_noposts' ); function my_do_noposts() { $term = $_GET['s']; // store the search term in a variable printf( '<p class="no-result-title">%s</p>', apply_filters( 'genesis_noposts_text', __( 'unfortunately, there’s nothing matching that phrase. search again or browse below', 'genesis' ) ) ); include('search-helper.php'); echo '</div><!-- close entry-content -->'; echo '</div><!-- close post -->'; }
but don't know what to write in the search-helper.php
Hope somebody can help.
http://www.sarah.webstantly.com/May 27, 2015 at 3:54 pm #153868JamesParticipantHi Alex
could you create a custom loop in the search-helper.php to pull is posts?
May 28, 2015 at 12:45 am #153914alexadarkMemberHI, yes i have tried that:
<?php add_action('genesis_loop','wst_nosearch_loop'); function wst_nosearch_loop { global $paged; // accepts any wp_query args $args = (array( 'post_type' => 'post, projects', 'paged' => $paged, 'posts_per_page' => 10 )); }
and it gives an error
i have tried a wp_Query , and it gives a blank page
// WP_Query arguments $args = array ( 'name' => 'post, projects', 'pagination' => true, 'posts_per_page' => '10', ); // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // do something } } else { // no posts found } // Restore original Post Data wp_reset_postdata();
May 28, 2015 at 2:49 am #153921JamesParticipanthere you go
this goes in the functions.php
//* Remove The Default No Posts Action remove_action( 'genesis_loop_else', 'genesis_do_noposts' ); //* Add custom action add_action( 'genesis_loop_else', 'my_do_noposts' ); function my_do_noposts() { $term = $_GET['s']; // store the search term in a variable echo '<div class="post">'; echo '<h1 class="entry-title">Search Results: ' . $term . '</h1>'; echo '<div class="entry-content">'; printf( '<p>%s</p>', apply_filters( 'genesis_noposts_text', __( 'Sorry. I don\'t have anything in the archives that matches your criteria. Try another search term or use the archive links below.', 'genesis' ) ) ); include('search-helper.php'); echo '</div><!-- close entry-content -->'; echo '</div><!-- close post -->'; }
and create a file called search-helper.php and add it to your main theme folder
and add this to that file
<div class="archive-page"> <h4><?php _e( 'Categories', 'genesis' ); ?></h4> <ul> <?php wp_list_categories( 'sort_column=name&title_li=' ); ?> </ul> <h4><?php _e( 'Articles by Month', 'genesis' ); ?></h4> <p> <select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option> <?php wp_get_archives( 'type=monthly&format=option&show_post_count=1' ); ?> </select> </p> </div><!-- end .archive-page--> <div class="archive-page"> <h4><?php _e( 'Tags', 'genesis' ); ?></h4> <ul> <?php wp_tag_cloud(); ?> </ul> </div><!-- end .archive-page--> <h4 style="clear:both"><?php _e( 'Article Listing', 'genesis' ); ?></h4> <ul> <?php wp_get_archives( 'type=postbypost&limit=50' ); ?> </ul>
May 28, 2015 at 3:03 am #153923alexadarkMemberThank you Jamie, but this is not what my client wants, she wants exactly the same content as the home page (feed of all posts and CPT projects) with that at the top:
UNFORTUNATELY, THERE’S NOTHING MATCHING THAT PHRASE. SEARCH AGAIN OR BROWSE BELOW
May 28, 2015 at 4:08 am #153928JamesParticipantthat would require quite a bit of work and testing, more than i can offer for free on the forum.
it is unusual to want to duplicate the home page on a search results page, why not just have a link back to the home page?
May 28, 2015 at 4:12 am #153930alexadarkMemberBecause it is a super picky client, and don't want to make concessions to anything, neither give more money.
i have already did more work than the budget.
but it's a client i have from codeable (https://codeable.io/) where i am a contractor, and has she asked that since the beginning, ia m obliged to do it 🙁
how much would be your price to do that ?May 28, 2015 at 4:32 am #153931JamesParticipantI understand
When is the project deadline ?
it is night time here now, so i wouldn't be able to look at anything further till tomorrow for you
May 28, 2015 at 4:36 am #153932alexadarkMemberthe dead line is asap, she wanted the project in 2 weeks, and saturday it will be 3 weeks, because of all the deatils she si not happy with, and where i need other developers
i know sridhar is also looking the project
just tell me what you can do!
you can contact me on skype : webstantly
i'm europe, it's noon hereThanks!
May 28, 2015 at 4:51 am #153934JamesParticipantyou say sridhar is taking a look at this as well?
he would be faster than i am, as he has a lot of stuff already written
let me know how you go
May 28, 2015 at 4:54 am #153935alexadarkMemberYes i hope!
i have sent him the access this morning, as he answered me at midnight my time
i will keep you informedAnyway thank you and good night!
I have to avoid this type of client, but you don't always know before 🙁
May 28, 2015 at 5:00 am #153937JamesParticipantcool, let Sridhar do that then if he has already started.
keep me posted
May 29, 2015 at 2:31 am #154062alexadarkMemberHi,
i have no answer from sridhar or other.
perhaps a friend will help me.
but the client absolutely wants that.
so tell me of you can help and your conditionsThanks
May 29, 2015 at 2:55 am #154063JamesParticipantdo you have a link to the site?
May 29, 2015 at 2:56 am #154064alexadarkMemberhttp://www.sarah.webstantly.com/
this the demo, the real site is http://www.thinkcreatelive.com/
but she has a maintenance
i can send you the access in privateMay 29, 2015 at 2:58 am #154065alexadarkMemberI just have somebody helping me
i keep you informedMay 29, 2015 at 3:00 am #154066JamesParticipantcool, no problem
was that the home page here http://www.sarah.webstantly.com/, and she wants all that on the search page?
May 29, 2015 at 3:13 am #154067alexadarkMemberhttp://www.sarah.webstantly.com/?s=asdasd
the search with no results
as it is now, with this title that i have already implemented, but with the same content (feed of posts + projects as the home)
i'm going to test my friend solution,and pass you the code if you are interested, or ask for more help if i don;t succedMay 29, 2015 at 4:12 am #154071JamesParticipantyep, would love to check the code, good for reference too should something similar come up
funny, creating a custom loop is no big deal for either posts or custom post types, but both at the same time got me stumped.
i'm not sure whether to create a loop and add the CPT to it, or create 2 loops, one for each
perhaps your friend will shed some light here.
May 30, 2015 at 1:25 am #154190alexadarkMemberHi, finally we found a solution making a redirection and appending the title with jquery
not superclean, but it works, and client happy!
This type of thing seems easy, but really complex at the end.
for one time i think i should have been easier with classic wordpress.
i'm curious to know if the " clean" solution!
http://www.sarah.webstantly.com/?n=x
if you're interested i can pass you the code for that, can always be usefull
the real site is here: http://www.thinkcreatelive.com/
under maintenance for the momentThanks for trying to help me, don't hesitate to contact me if you need something 🙂
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.