• Hey guys I am working on a website and am having issues with my search results. When someone searches something on my site and there is nothing that matches their search it just brings up an empty page. I would like to for it to display something saying that there were no results. Sadly, I have zero coding knowledge. This is what i’m working with if you guys could let me know what I need to put in I will be very grateful.

    <?php get_header();

    if (have_posts()) :

    while (have_posts()) : the_post(); ?>

    <div id=”post-<?php the_ID(); ?>” <?php post_class(‘contents’); ?>>

    <?php if ( get_theme_mod(‘display_post_title_setting’) == ‘off’ ) : else : ?>

    <h4><?php if (get_theme_mod(‘display_date_setting’) != ‘off’ ) : ?><time datetime=”<?php the_time(‘Y-m-d H:i’) ?>”><?php the_time(‘M’) ?>
    <?php the_time(‘jS’) ?></time><?php endif; ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php if ( get_the_title() ) { the_title(); } else { _e(‘(No Title)’, ‘localize_adventure’); } ?></h4>

    <?php endif;

    if ( get_theme_mod(‘display_excerpt_setting’) != ‘on’ ) : the_content(); else : the_excerpt(); endif ?>

    <span class=”tag”>

    <?php wp_link_pages(); ?>

    <?php if (get_theme_mod(‘author_setting’) != ‘off’) : _e(‘ by ‘, ‘localize_adventure’); the_author_posts_link(); endif;

    if (get_theme_mod(‘commentsclosed_setting’) != ‘off’) :

    if ((get_theme_mod(‘comments_setting’) != ‘none’) || (get_theme_mod(‘comments_setting’) != ‘single’)) :

    if (comments_open(hello)) :

    _e(‘with ‘, ‘localize_adventure’); comments_popup_link( __(‘no comments yet’, ‘localize_adventure’), __(‘1 comment’, ‘localize_adventure’), ‘% ‘ . __(‘comments’, ‘localize_adventure’), ‘comments-link’, __(‘comments disabled’, ‘localize_adventure’));

    _e(‘.’, ‘localize_adventure’);

    endif;

    endif;

    endif; ?>

    </span>

    </div>

    <?php endwhile;

    endif; ?>

    <div class=”contents”>
    <h3>
    <span class=”left”><?php next_posts_link( ‘‹ ‘ . __(‘Older Posts’, ‘localize_adventure’) ); ?></span>
    <span class=”right”><?php previous_posts_link( __(‘Newer Posts’, ‘localize_adventure’) . ‘›’ ); ?></span>
    </h3>
    </div>

    <?php get_footer(); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello, and to my knowledge,

    If you use a standard theme, like from Automattic, there are built-in 404 pages for that to customize at will (thedemotheme/404.php).

    Many themes also use a specific (thedemotheme/search.php) page that can again be customized, then you can call things to filter the wp_loop main function.

    Thread Starter jeremyf1

    (@jeremyf1)

    So can I not make a custom message with the theme I selected?

    change the end of the loop, from:

    <?php endwhile;
    
    endif; ?>

    to:

    <?php endwhile;
    
    else: ?>
    
    <!-- your 'not found' html text section here -->
    
    <?php endif; ?>
    Thread Starter jeremyf1

    (@jeremyf1)

    Awesome! Thank you, but is there anyway to make the font size larger and maybe move it into the content box. Right now it is acting like a title. I really am thankful for your help.

    make the font size larger and maybe move it into the content box.

    add some html and CSS classes to your ‘not found’ message, and style with CSS.

    details would depend on the existing formatting of your theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Need coding help’ is closed to new replies.