I have a Wordpress website that has search form.
But when i click the submit button without writing anything inside search bar, then website gives me all the posts and pages that my website has.
Is there any way so that when a user clicks submit button without writing anything inside search field, that user gets message saying something like 'Search Fields was empty - Search Again'.
header.php - this is where i'm using get_search_form(), to get the search form from another page
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<!-- site-header -->
<header class="site-header">
<div class="header-container">
<nav class="site-nav">
<h1 class ="head-title">Title</h1>
<!-- hd-search -->
<div class="hd-search">
<?php get_search_form(); ?>
</div><!-- /hd-search -->
<?php
$args = array(
'theme_location' => 'primary'
);
?>
<?php wp_nav_menu( $args ); ?>
</nav>
</div>
</header><!-- /site-header -->
<div class="container">
searchform.php - this is where my search form is located
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div><label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" placeholder="<?php the_search_query(); ?>" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
search.php - this is the page that i get after i press the search button
<?php
get_header();
if (have_posts()) : ?>
<h2>Search results for: <?php the_search_query(); ?></h2>
<?php
while (have_posts()) : the_post(); ?>
<article class="post <?php if ( has_post_thumbnail() ) { ?>has-thumbnail <?php } ?>">
<!-- post-thumbnail -->
<div class="post-thumbnail">
<?php the_post_thumbnail('small-thumbnail'); ?>
</div><!-- /post-thumbnail -->
<h2><?php the_title(); ?></h2>
<p class="post-info"><?php the_time('F j, Y g:i a'); ?> | by <?php the_author(); ?> | Posted in
<?php
$categories = get_the_category();
$separator = ", ";
$output = '';
if ($categories) {
foreach ($categories as $category) {
$output .= '' . $category->cat_name . '' . $separator;
}
echo trim($output, $separator);
}
?>
</p>
<?php the_excerpt(); ?>
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
**strong text**?>
Related
Looking for help in getting my wordpress theme to display header image on all pages and not just the home page as it currently does. All pages use get_header php command and the header.php contains the following code:
<?php
/**
* The header for our theme
*
* This is the template that displays all of the <head> section and everything up until <div id="content">
*
* #link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* #package Superb_Landingpage
*/
?>
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
<div class="navigation-wrapper">
<div class="site grid-container">
<header id="masthead" class="site-header grid-x grid-padding-x">
<div class="site-branding large-4 medium-10 small-9 cell">
<?php
the_custom_logo();
if ( is_front_page() && is_home() && is_page() ) :
?>
<div class="logo-container">
<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
<?php
else :
?>
<div class="logo-container">
<h2 class="site-title"><?php bloginfo( 'name' ); ?></h2>
<?php
endif;
$superb_landingpage_description = get_bloginfo( 'description', 'display' );
if ( $superb_landingpage_description || is_customize_preview() ) :
?>
<p class="site-description"><?php echo $superb_landingpage_description; /* WPCS: xss ok. */ ?></p>
<?php endif; ?>
</div>
</div><!-- .site-branding -->
<nav id="site-navigation" class="main-navigation large-8 medium-2 small-3 cell">
<?php
wp_nav_menu( array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
) );
?>
</nav><!-- #site-navigation -->
</header><!-- #masthead -->
</div>
</div>
<?php if ( get_header_image() ) : ?>
<?php if ( is_front_page() ) : ?>
<div class="content-wrap">
<div class="bottom-header-wrapper">
<img src="<?php echo esc_url(( get_header_image()) ); ?>" alt="<?php echo esc_attr(( get_bloginfo( 'title' )) ); ?>" />
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<div id="page" class="site grid-container start-container-head">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'superb-landingpage' ); ?></a>
<div id="content" class="site-content grid-x grid-padding-x">
What do I add/remove to simply have the header display on all pages?
I've tried removing the if/else conditions in the header.php but wordpress keeps rolling back the edit claiming errors. Any help is greatly appreciated! Thank you.
Try it
<?php
if ( is_home() ) {
// This is a homepage
} else {
// This is not a homepage
}
?>
<?php
if ( is_front_page() && is_home() ) {
// This is a homepage
} else {
// This is not a homepage
}
?>
If this does not work try this
<?php
if ( is_front_page() ) {
// This is a homepage
} else {
// This is not a homepage
}
?>
I've downloaded the MetaSlider plugin for WordPress, and am able to insert the generated code into my theme's header.php files so that the slider displays in the correct location. However, the site logo and description disappear when I do this (they should be overlaying the header image). Here's the code for the header.php file:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<!-- Preloader -->
<?php get_template_part( 'templates/header/preloader' ); ?>
<!-- Page Wrapper -->
<div id="page-wrap">
<!-- Boxed Wrapper -->
<div id="page-header" <?php echo esc_attr(ashe_options( 'general_header_width' )) === 'boxed' ? 'class="boxed-wrapper"': ''; ?>>
<?php
// Top Bar
get_template_part( 'templates/header/top', 'bar' );
// Page Header
get_template_part( 'templates/header/page', 'header' );
// Main Navigation
get_template_part( 'templates/header/main', 'navigation' );
?>
</div><!-- .boxed-wrapper -->
<!-- Page Content -->
<div id="page-content">
<?php get_template_part( 'templates/sidebars/sidebar', 'alt' ); // Sidebar Alt ?>
To get the slider into the correct location I need to replace the code underneath //Page Header with the code that Meta Slider provides. The Problem, I think, is that it's replacing the Header Template. So, I've looked at the php for the header template as well, but I'm not sure what, if anything, I might do in there to fix the issue. Here's the header template code:
<div class="entry-header">
<div class="cv-outer">
<div class="cv-inner">
<div class="header-logo">
<?php
if ( has_custom_logo() ) :
$custom_logo_id = get_theme_mod( 'custom_logo' );
$custom_logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr( bloginfo('name') ); ?>" class="logo-img">
<img src="<?php echo esc_url( $custom_logo[0] ); ?>" alt="<?php esc_attr( bloginfo('name') ); ?>">
</a>
<?php else : ?>
<?php echo bloginfo( 'title' ); ?>
<?php endif; ?>
<br>
<p class="site-description"><?php echo bloginfo( 'description' ); ?></p>
</div>
</div>
</div>
</div>
Any ideas as to how I might go about fixing this would be much appreciated!!
Have you try to give position:relative; z-index:9999;//z-index number depends to your logo and description?
So I've got this search filter thing but I want the search results to appear on the same as the filter is on. However it keeps taking me to a separate search page to show the results.
I think I just need to get the form action to be the current url or a certain page url or permalink. <form action="http://localhost/siennahomes_www/property-search-sienna/>
ideally I would like it to be
<form action="http://localhost/siennahomes_www/home-designs/>
I've tried putting in an absolute link to test but it appears to be overwritten by a php function. It constantly stays at
no matter how much I try.
The bits of code in the templates are:
Advanced-search:
<?php
global $theme_search_url;
$theme_search_url = get_option('theme_search_url');
global $theme_search_fields;
$theme_search_fields= get_option('theme_search_fields');
if( !empty($theme_search_url) && !empty($theme_search_fields) && is_array($theme_search_fields) ):
?>
<section class="advance-search ">
<?php
$home_advance_search_title= get_option('theme_home_advance_search_title');
if(!empty($home_advance_search_title)){
?><h3 class="search-heading"><i class="fa fa-search"></i><?php echo $home_advance_search_title; ?></h3><?php
}
get_template_part('template-parts/search-form');
?>
</section>
<?php
endif;
?>
home-designs page:
<?php
/*
* Template Name: home designs test
*/
get_header();
/* Theme Home Page Module */
$theme_search_module = get_option('theme_search_module');
?>
<!-- Content -->
<div class="container contents">
<div class="row">
<div class="span12">
<!-- Main Content -->
<div class="main">
<?php
/* Advance Search Form */
get_template_part('template-parts/advance-search-test');
?>
<section class="property-items">
<div class="search-header">
<?php get_template_part('template-parts/sort-controls'); ?>
</div>
<div class="property-items-container clearfix">
<?php
/* List of Properties on Homepage */
$number_of_properties = intval(get_option('theme_properties_on_search'));
if(!$number_of_properties){
$number_of_properties = 4;
}
$search_args = array(
'post_type' => 'property',
'posts_per_page' => $number_of_properties,
'paged' => $paged
);
// Apply Search Filter
$search_args = apply_filters('real_homes_search_parameters',$search_args);
$search_args = sort_properties($search_args);
$search_query = new WP_Query( $search_args );
if ( $search_query->have_posts() ) :
$post_count = 0;
while ( $search_query->have_posts() ) :
$search_query->the_post();
/* Display Property for Search Page */
get_template_part('template-parts/property-for-home');
$post_count++;
if(0 == ($post_count % 2)){
echo '<div class="clearfix"></div>';
}
endwhile;
wp_reset_query();
else:
?><div class="alert-wrapper"><h4><?php _e('No Properties Found!', 'framework') ?></h4></div><?php
endif;
?>
</div>
<?php theme_pagination( $search_query->max_num_pages); ?>
</section>
</div><!-- End Main Content -->
</div> <!-- End span12 -->
</div><!-- End row -->
</div><!-- End content -->
<?php get_footer(); ?>
search-form:
<div class="as-form-wrap">
<form class="advance-search-form clearfix" action="<?php global $theme_search_url; echo $theme_search_url; ?>" method="get">
<?php if ( in_array ( 'keyword-search', $theme_search_fields ) ) {
?>
<div class="option-bar large">
<label for="keyword-txt"><?php _e('Keyword', 'framework'); ?></label>
<input type="text" name="keyword" id="keyword-txt" value="<?php echo isset ( $_GET['keyword'] ) ? $_GET['keyword'] : ''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" />
</div>
<?php
}
if ( in_array ( 'property-id', $theme_search_fields ) ) {
?>
<div class="option-bar large">
<label for="property-id-txt"><?php _e('Property ID', 'framework'); ?></label>
<input type="text" name="property-id" id="property-id-txt" value="<?php echo isset($_GET['property-id'])?$_GET['property-id']:''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" />
</div>
I suspect the culprit is this line on the advanced search page:
$theme_search_url = get_option('theme_search_url');
so I am building a custom wordpress theme for a client (I am a freelancer, pretty new to wordpress) and I have built the main theme that works 100% on the home page, but when I go into a post, archive, etc, the image path breaks, the sidebar breaks. I have attached photos for you to see:
And this is what the post looks like:
======== code edit =======
header.php:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>" />
<?php if (is_search()) { ?>
<meta name="robots" content="noindex, nofollow" />
<?php } ?>
<title>
<?php
if (function_exists('is_tag') && is_tag()) {
single_tag_title("Tag Archive for ""); echo '" - '; }
elseif (is_archive()) {
wp_title(''); echo ' Archive - '; }
elseif (is_search()) {
echo 'Search for "'.wp_specialchars($s).'" - '; }
elseif (!(is_404()) && (is_single()) || (is_page())) {
wp_title(''); echo ' - '; }
elseif (is_404()) {
echo 'Not Found - '; }
if (is_home()) {
bloginfo('name'); echo ' - '; bloginfo('description'); }
else {
bloginfo('name'); }
if ($paged>1) {
echo ' - page '. $paged; }
?>
</title>
<link rel="shortcut icon" href="/favicon.ico">
<link rel="stylesheet" type="text/css" href="wp- content/themes/custom1/css/reset.css" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
<!-- HTML 5 shiv -->
<!--[if lt IE 9]>
<script src="dist/html5shiv.js"></script>
<![endif]-->
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>">
<?php if ( is_singular() ) wp_enqueue_script('comment-reply'); ?>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page-wrap">
<section id="header">
<div id="logo"></div>
<div id="nav">
<div class="wrapper">
<nav>
<ul>
<!-- <li>Home</li>
<li>About Us</li>
<li>FAQ's</li>
<li>Contact Us</li> -->
<?php wp_nav_menu(array('menu' => 'Main Nav Menu')); ?>
</ul>
</nav>
<div class="clear"></div>
</div>
</div>
</section> <!-- end of Header -->
<section id="page">
<div class="wrapper">
index.php:
<?php get_header(); ?>
<section id="main_content">
<article>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?> </h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in <?php the_category(', ') ?> |
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</article>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
and page.php (the buggy one):
<?php get_header(); ?>
<section id="main_content">
<article>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
</div>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
<?php // comments_template(); ?>
<?php endwhile; endif; ?>
</article>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
sorry for the long post :)
So I found the answer after alot of searching in a random blog post (I forgot where, sorry).
What I was doing: the image only worked on the homepage and no other page if I put the link to the image as: wp-content/themes/[mytheme]/images/image.jpg
and it worked on all other pages but not the home page when I put the following: ../wp-content/themes/[mytheme]/images/image.jpg
<?php bloginfo('template_directory'); ?>/images/image1.jpg
So thank you to Nicholas King, George Marques, Domdev and Scott Simpson for putting me on the right track.
Thanks,
Josh
I'm at a loss to for a solution to my comments section not showing on my single post page. I've noticed that this page is not displaying any of the code below the post and tags sections. Would someone be willing to look at the code in the admin for me? I imagine it could be something simple to identify, as the site is organized nicely.
This is the only way I think the problem could be solved.
UPDATE UPDATE UPDATE. Here's Single.php
<?php get_header(); ?>
<?php include ('page_header.php'); ?>
<?php include ('page_navigation.php'); ?>
<div id="page-content" class="clearfix">
<div id="content-container" class="clearfix">
<div id="main-content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( get_option('minimax_post_layout') == 'head-three' ) { ?>
<h2><?php the_title(); ?><em>Posted on <?php the_time('D, M d, Y') ?></em></h2>
<?php if ( has_post_thumbnail() ) { ?>
<div class="post-item-thumb-<?php echo get_option('minimax_post_layout'); ?>">
<?php the_post_thumbnail('thumb_post_3'); ?>
</div>
<?php } ?>
<?php } else { ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="post-item-thumb-<?php echo get_option('minimax_post_layout'); ?>">
<?php the_post_thumbnail('thumb_post_2'); ?>
</div>
<?php } ?>
<h2><?php the_title(); ?><em>Posted on <?php the_time('D, M d, Y') ?></em></h2>
<?php } ?>
<?php the_content(); ?>
<?php edit_post_link('Edit', '<br /><p>', '</p>'); ?>
<?php include ('post_related.php'); ?>
<div id="post-indexing"> <?php the_tags('<strong>Tagged as</strong> ',', ','+'); ?><br /><strong>Categorized as</strong> <?php the_category(', ','single'); ?></div>
<?php include ('post_author.php'); ?>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no pages matched your criteria.'); ?></p>
<?php endif; ?>
</div><!-- end main-content -->
<?php include ('sidebar_post.php'); ?>
</div><!-- end content-container -->
<?php include ('footer_columns_posts.php'); ?>
</div><!-- end page-content -->
<?php get_footer(); ?>
Also, here's the comments.php page:
<div id="comments">
<?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
}
/* This variable is for alternating comment background */
$oddcomment = 'class="alt" ';
?>
<!-- You can start editing here. -->
<?php if ($comments) : ?>
<h2>Comments <span>(<?php comments_number('No Responses', 'One Response', '% Responses' );?
>)</span></h2>
<ul class="commentlist">
<?php wp_list_comments('avatar_size=60&type=comment'); ?>
</ul>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<?php endif; ?>
<?php endif; ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond">
<h3><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>
<div class="cancel-comment-reply">
<?php cancel_comment_reply_link(); ?>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo
urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>
<?php else : ?>
<div id="post-comment" class="clearfix">
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post"
id="commentform">
<fieldset>
<?php if ( $user_ID ) : ?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo
$user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?
action=logout" title="Log out of this account">Log out »</a></p>
<?php else : ?>
<label for="author"><?php if ($req) echo "* "; ?>Your name:</label>
<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22"
tabindex="1" />
<label for="email"><?php if ($req) echo "* "; ?>Mail (will not be published):</label>
<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>"
size="22" tabindex="2" />
<label for="url">Website</label>
<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22"
tabindex="3" />
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?
></code></small></p>-->
<label for="comment" class="comment">Your comment:</label>
<textarea name="comment" id="comment" class="comment" cols="61%" rows="10"
tabindex="4"></textarea>
<input name="submit" type="submit" class="submit" alt="Submit Comment" id="submit" tabindex="5"
value="Submit Comment" />
<input type="hidden" class="hide" name="comment_post_ID" value="<?php echo $id; ?>" />
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $post->ID); ?>
</fieldset>
</form>
</div><!-- end post-comment -->
</div>
<?php endif; // If registration required and not logged in ?>
<?php endif; // if you delete this the sky will fall on your head ?>
</div>
Here is post_author.php
<?php if ( get_option('minimax_author') == 'yes' ) { ?>
<div id="author-desc" class="clearfix">
<?php the_author_image(); ?>
<h4>About the Author</h4>
<?php the_author_description(); ?>
</div>
<?php } ?>
There isn't any function like the_author_image() in Wordpress. So, you have to remove
<?php the_author_image(); ?>
line from your post_author.php. If you want to show author image , Wordpress getting avatars from Gravatar. You can use get_avatar() to display author's Gravatar.
echo get_avatar(get_the_author_id());
In shortly, use this :
<?php echo get_avatar(get_the_author_id()); ?>
instead of this :
<?php the_author_image(); ?>