• Resolved Dekadinious

    (@dekadinious)


    Hello!

    I have a problem with navigation on the search page. The navigation works fine in the other pages, but at the search result page it breaks. It’s a custom theme that I did not make and that I cannot contact the author for help.

    The problem is that search results pages gets this URL:

    https://domain.com/?s=apage/2/

    It should be this:

    https://domain.com/page/2/?s=a

    If I type the latter manually it works. Where would I start to look to solve this problem? I was hoping it would just be to move some simple code so that “page/2/” would appear first, but sadly I don’t think it will be so easy.

    Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi!

    That’s just a weird result, now isn’t it? lol

    Have you tried deactivating all your plugins to see if that resolves the issue? Try resaving your permalink settings just in case.

    Thread Starter Dekadinious

    (@dekadinious)

    Hello!

    I deactivated all plugins and resaved the permalinks, but the issue is still there. I suspect some theme-files are causing the issue, but I don’t quite know where to look.

    Have a nice day!

    Moderator keesiemeijer

    (@keesiemeijer)

    Does your theme have a search.php file?
    Can you post the content of that file here.

    Thread Starter Dekadinious

    (@dekadinious)

    It does not. It has a “searchform.php” file with these contents:

    <?php $search_terms = htmlspecialchars( $_GET["s"] ); ?>
    
    <form role="form" action="<?php bloginfo('siteurl'); ?>/" id="searchform" method="get">
        <label for="s" class="sr-only">S?k</label>
        <div class="input-group">
            <input type="text" class="form-control" id="s" name="s" placeholder="S?k"<?php if ( $search_terms !== '' ) { echo ' value="' . $search_terms . '"'; } ?> />
            <span class="input-group-btn">
                <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
            </span>
        </div> <!-- .input-group -->
    </form>

    It also has a loop-nav.php file that might be the culprit:

    <?php
    
    if ( !is_singular() ) {
    
        global $wp_query;
        $total = $wp_query->max_num_pages;
    
        if ( $total > 1 )  {
            echo '<nav class="pagination-centered">';
    
            $current_page = max(1, get_query_var('paged'));
    
            $mid_size = 7 - $current_page;
            if ($mid_size < 4) $mid_size = 4;
    
            $page_links = paginate_links(array(
                'base' => get_pagenum_link(1) . '%_%',
                'format' => 'page/%#%/',
                'current' => $current_page,
                'total' => $total,
                'mid_size' => $mid_size,
                'type' => 'array',
                'prev_text' => '?',
                'next_text' => 'Neste side ?'
                ));
    
            if (count($page_links) > 0) {
                echo '<ul class="pagination">';
                // echo '<li><span class="page-numbers pages">Side ' . $current_page . ' av ' . $total . '</span></li>';
                foreach ($page_links as $link) {
                    echo '<li>' . $link . '</li>';
                }
    
            }
            echo '</nav>';
        }
    
    }
    
    ?>

    Thanks!

    Moderator keesiemeijer

    (@keesiemeijer)

    Try replacing this:

    'base' => get_pagenum_link(1) . '%_%',

    with this

    'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%',

    Thread Starter Dekadinious

    (@dekadinious)

    Thank you!

    That works perfectly. I just wanted to add that I now get https://domain.com//page/2/?s=a in the search, with a double /. This does not matter for me as it works, but do you know if that is incompatible with some browsers? ??

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    'base' => preg_replace('/\?.*/', '', get_pagenum_link(1)) . '%_%',

    Thread Starter Dekadinious

    (@dekadinious)

    Perfect!

    Thank you very much indeed!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Problem with search page navigation’ is closed to new replies.