Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search Results: Dropdown Width & Show Categories
- This topic has 4 replies, 2 voices, and was last updated 9 years ago by
ShawnS52.
-
AuthorPosts
-
May 30, 2017 at 3:44 pm #13316
ShawnS52
ParticipantHello again, I think I have just 2 final questions on setting up the search to look the way I’d like.
Through the element inspector in Chrome I’ve been able to adjust the width of the dropdown search results but I can’t figure out where to edit them in the plugin files. Here is an example of what I’d like to do, have the results dropdown width be 850px or a certain percentage: http://imgur.com/a/oxP62
Second, is it possible to change the Advanced description field to show all of a post’s categories? I had found another ticket where you provided code to functions.php to show the tags, would it be similar for categories?
Let me know if you would like me to submit these separately and thank you again for all the help!
May 30, 2017 at 4:06 pm #13319Ernest Marcinko
KeymasterHi!
1. I would not recommend making direct change to the plugin files, instead use this custom CSS code:
[html]div[id*=ajaxsearchprores] {
width: 850px !important;
}[/html]2. To display all categories, you will need a custom filter. Based on this knowledge-base example, this code should do the trick:
[php]add_filter( ‘asp_results’, ‘asp_add_category_titles’, 1, 1 );
function asp_add_category_titles( $results ) {
foreach ($results as $k=>$v) {// Get the post categories
$post_categories = wp_get_post_categories( $results[$k]->id );
$cats = array();// Concatenate category names to the $cats variable
foreach($post_categories as $c){
$cat = get_category( $c );
$cats[] = $cat->name;
}// Modify the post title
if ( count($cats) > 0 )
$results[$k]->content .= " ".implode(‘, ‘, $cats);
}return $pageposts;
}[/php]I have not tested this code, so please be careful!
May 30, 2017 at 5:34 pm #13320ShawnS52
ParticipantThe results box css worked great!
The Custom Filter didn’t do quite what I was looking for. For this section I would like the categories to be in place of the {descriptionfield}. Is that possible? Thanks!
[code]// Modify the post title
if ( count($cats) > 0 )
$results[$k]->content .= " ".implode(‘, ‘, $cats);
}[/code]May 30, 2017 at 8:28 pm #13324Ernest Marcinko
KeymasterYou are welcome!
To completely replace the content, just change this line in the code:
[php]$results[$k]->content .= " ".implode(‘, ‘, $cats);[/php]
..to this:
[php]$results[$k]->content = implode(‘, ‘, $cats);[/php]
May 31, 2017 at 2:12 pm #13335ShawnS52
ParticipantThis worked fine, thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.