• Resolved LoveMeBlu

    (@lovemeblu)


    I have added a searchbox to my nav menu, but would like it to always appear aligned on the right hand side. I would also like it to output the search results as it appears in the blog (i.e. Post title, photo, continue reading link). Can anyone help?

    I currently have this in my child theme functions.php file:

    function menu_search($items){
        $search = '<li class="search">';
        $search .= '<form method="get" id="searchform" action="/">';
        $search .= '<label for="s" class="assistive-text">Search</label>';
        $search .= '<input type="text" class="field" name="s" id="s" placeholder="Search" />';
        $search .= '<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />';
        $search .= '</form>';
        $search .= '</li>';
    
        return $items . $search;
    }
    add_filter('wp_nav_menu_items','menu_search');

    My site is: https://lovemebluphotography.com/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Add this CSS rule to your custom CSS:

    li.search {
       float: right;
       margin-top: 4px;
       margin-right: 0;
    }

    As far as making the search output the same as your blog, you will need to make a copy of search.php from the parent theme into your child theme, then alter it so it resembles category.php (since you are actually displaying posts of a particular category in your blog). The part you’ll want to change will be inside the while section (the start of the loop).

    Thread Starter LoveMeBlu

    (@lovemeblu)

    Thank you!! You explained it so well, that even me – a total newbie – could figure it out!! That worked great!!

    I ended up replacing the get_post_format () with ‘page’ in my search.php file and that worked fantastic! Also, Search box position perfect!!

    Thank you!

    You’re welcome, but something is not quite right with your coding. When I try to do a search, I get this error:

    Parse error: syntax error, unexpected ')' in /home/loveme12/public_html/wp-content/themes/twentytwevlechild/search.php on line 25

    Thread Starter LoveMeBlu

    (@lovemeblu)

    Hhhmmm…. Just checked my coding and deleted a comma which might have been the problem? Is it working now?

    Yep, works now.

    Thread Starter LoveMeBlu

    (@lovemeblu)

    Thanks a lot! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Edit search box position and output results’ is closed to new replies.