Wordpress returns white page when searching - php

Whenever I search on my site I get an blank error page. I have tried the following:
Disable plugin.
Turn on debug.
Scanned my code with theme checker for deprecated tags.
Search.php
get_header(); ?>
<section id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
</header><!-- .page-header -->
<?php shape_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'search' ); ?>
<?php endwhile; ?>
<?php shape_content_nav( 'nav-below' ); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'search' ); ?>
<?php endif; ?>
</div><!-- #content .site-content -->
</section><!-- #primary .content-area -->
Searchform.php
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" role="search">
<label for="s" class="assistive-text"><?php _e( 'Search', 'shape' ); ?></label>
<input type="text" class="field" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" id="s" placeholder="<?php esc_attr_e( 'Search …', 'shape' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'shape' ); ?>" />
</form>
The weird thing is that all my html show up when searching, but I am still getting a white page of death.
What am I doing wrong?

All code is readable with CTRL+U. So your WordPress works. One of the problems is the display:none value in the CSS under .search class. So delete the .search { display:none; } line from CSS.

Related

BuddyPress registration form shortcode

I'm trying to get the registration form for BuddyPress.
I searching for a shortcode or just php code.
I've try to copy the field in template's of buddypress plugin. But it's dosen't work.
Here is the code I place in a custom post type.
<div id="buddypress">
<?php do_action( 'bp_before_register_page' ); ?>
<div class="page" id="register-page">
<form action="" name="signup_form" id="signup_form" class="standard-form" method="post" enctype="multipart/form-data">
<?php if ( 'registration-disabled' == bp_get_current_signup_step() ) : ?>
<?php do_action( 'template_notices' ); ?>
<?php do_action( 'bp_before_registration_disabled' ); ?>
<p><?php _e( 'User registration is currently not allowed.', 'buddypress' ); ?></p>
<?php do_action( 'bp_after_registration_disabled' ); ?>
<?php endif; // registration-disabled signup setp ?>
<?php if ( 'request-details' == bp_get_current_signup_step() ) : ?>
<?php do_action( 'template_notices' ); ?>
<p><?php _e( 'Registering for this site is easy. Just fill in the fields below, and we\'ll get a new account set up for you in no time.', 'buddypress' ); ?></p>
<?php do_action( 'bp_before_account_details_fields' ); ?>
<div class="register-section" id="basic-details-section">
<?php /***** Basic Account Details ******/ ?>
<h4><?php _e( 'Account Details', 'buddypress' ); ?></h4>
<label for="signup_username"><?php _e( 'Username', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
<?php do_action( 'bp_signup_username_errors' ); ?>
<input type="text" name="signup_username" id="signup_username" value="<?php bp_signup_username_value(); ?>" />
<label for="signup_email"><?php _e( 'Email Address', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
<?php do_action( 'bp_signup_email_errors' ); ?>
<input type="text" name="signup_email" id="signup_email" value="<?php bp_signup_email_value(); ?>" />
<label for="signup_password"><?php _e( 'Choose a Password', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
<?php do_action( 'bp_signup_password_errors' ); ?>
<input type="password" name="signup_password" id="signup_password" value="" class="password-entry" />
<div id="pass-strength-result"></div>
<label for="signup_password_confirm"><?php _e( 'Confirm Password', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
<?php do_action( 'bp_signup_password_confirm_errors' ); ?>
<input type="password" name="signup_password_confirm" id="signup_password_confirm" value="" class="password-entry-confirm" />
<?php do_action( 'bp_account_details_fields' ); ?>
</div><!-- #basic-details-section -->
<?php do_action( 'bp_after_account_details_fields' ); ?>
<?php /***** Extra Profile Details ******/ ?>
<?php if ( bp_is_active( 'xprofile' ) ) : ?>
<?php do_action( 'bp_before_signup_profile_fields' ); ?>
<div class="register-section" id="profile-details-section">
<h4><?php _e( 'Profile Details', 'buddypress' ); ?></h4>
<?php /* Use the profile field loop to render input fields for the 'base' profile field group */ ?>
<?php if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( array( 'profile_group_id' => 1, 'fetch_field_data' => false ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
<div<?php bp_field_css_class( 'editfield' ); ?>>
<?php
$field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() );
$field_type->edit_field_html();
do_action( 'bp_custom_profile_edit_fields_pre_visibility' );
if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
<p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">
<?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?>
</p>
<div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>">
<fieldset>
<legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend>
<?php bp_profile_visibility_radio_buttons() ?>
</fieldset>
<a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a>
</div>
<?php else : ?>
<p class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">
<?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?>
</p>
<?php endif ?>
<?php do_action( 'bp_custom_profile_edit_fields' ); ?>
<p class="description"><?php bp_the_profile_field_description(); ?></p>
</div>
<?php endwhile; ?>
<input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="<?php bp_the_profile_field_ids(); ?>" />
<?php endwhile; endif; endif; ?>
<?php do_action( 'bp_signup_profile_fields' ); ?>
</div><!-- #profile-details-section -->
<?php do_action( 'bp_after_signup_profile_fields' ); ?>
<?php endif; ?>
<?php if ( bp_get_blog_signup_allowed() ) : ?>
<?php do_action( 'bp_before_blog_details_fields' ); ?>
<?php /***** Blog Creation Details ******/ ?>
<div class="register-section" id="blog-details-section">
<h4><?php _e( 'Blog Details', 'buddypress' ); ?></h4>
<p><input type="checkbox" name="signup_with_blog" id="signup_with_blog" value="1"<?php if ( (int) bp_get_signup_with_blog_value() ) : ?> checked="checked"<?php endif; ?> /> <?php _e( 'Yes, I\'d like to create a new site', 'buddypress' ); ?></p>
<div id="blog-details"<?php if ( (int) bp_get_signup_with_blog_value() ) : ?>class="show"<?php endif; ?>>
<label for="signup_blog_url"><?php _e( 'Blog URL', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
<?php do_action( 'bp_signup_blog_url_errors' ); ?>
<?php if ( is_subdomain_install() ) : ?>
http:// <input type="text" name="signup_blog_url" id="signup_blog_url" value="<?php bp_signup_blog_url_value(); ?>" /> .<?php bp_signup_subdomain_base(); ?>
<?php else : ?>
<?php echo home_url( '/' ); ?> <input type="text" name="signup_blog_url" id="signup_blog_url" value="<?php bp_signup_blog_url_value(); ?>" />
<?php endif; ?>
<label for="signup_blog_title"><?php _e( 'Site Title', 'buddypress' ); ?> <?php _e( '(required)', 'buddypress' ); ?></label>
<?php do_action( 'bp_signup_blog_title_errors' ); ?>
<input type="text" name="signup_blog_title" id="signup_blog_title" value="<?php bp_signup_blog_title_value(); ?>" />
<span class="label"><?php _e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?></span>
<?php do_action( 'bp_signup_blog_privacy_errors' ); ?>
<label><input type="radio" name="signup_blog_privacy" id="signup_blog_privacy_public" value="public"<?php if ( 'public' == bp_get_signup_blog_privacy_value() || !bp_get_signup_blog_privacy_value() ) : ?> checked="checked"<?php endif; ?> /> <?php _e( 'Yes', 'buddypress' ); ?></label>
<label><input type="radio" name="signup_blog_privacy" id="signup_blog_privacy_private" value="private"<?php if ( 'private' == bp_get_signup_blog_privacy_value() ) : ?> checked="checked"<?php endif; ?> /> <?php _e( 'No', 'buddypress' ); ?></label>
<?php do_action( 'bp_blog_details_fields' ); ?>
</div>
</div><!-- #blog-details-section -->
<?php do_action( 'bp_after_blog_details_fields' ); ?>
<?php endif; ?>
<?php do_action( 'bp_before_registration_submit_buttons' ); ?>
<div class="submit">
<input type="submit" name="signup_submit" id="signup_submit" value="<?php esc_attr_e( 'Complete Sign Up', 'buddypress' ); ?>" />
</div>
<?php do_action( 'bp_after_registration_submit_buttons' ); ?>
<?php wp_nonce_field( 'bp_new_signup' ); ?>
<?php endif; // request-details signup step ?>
<?php if ( 'completed-confirmation' == bp_get_current_signup_step() ) : ?>
<?php do_action( 'template_notices' ); ?>
<?php do_action( 'bp_before_registration_confirmed' ); ?>
<?php if ( bp_registration_needs_activation() ) : ?>
<p><?php _e( 'You have successfully created your account! To begin using this site you will need to activate your account via the email we have just sent to your address.', 'buddypress' ); ?></p>
<?php else : ?>
<p><?php _e( 'You have successfully created your account! Please log in using the username and password you have just created.', 'buddypress' ); ?></p>
<?php endif; ?>
<?php do_action( 'bp_after_registration_confirmed' ); ?>
<?php endif; // completed-confirmation signup step ?>
<?php do_action( 'bp_custom_signup_steps' ); ?>
</form>
</div>
<?php do_action( 'bp_after_register_page' ); ?>
</div><!-- #buddypress -->
Are you not happy with the default form that shows up? When buddypress is installed it creates a few pages on your site. If you navigate to Settings->BuddyPress ->pages, you will see that the register page is pointing to... well Register :) There should be a "Register" page present in your All Pages. This is installed by buddypress
By Default, buddypress installs a Register page at : www.yoursite.com/Register
Open it while you are not log in and you can see the Registration Form.
Go to buddypress plugin template folder:
wp-content\plugins\buddypress\bp-templates\bp-legacy\buddypress
Copy the buddypress folder and paste it into your theme's root.
Now go to:
wp-content\YOURTHEME\buddypress\bp-templates\bp-legacy\buddypress\members folder and you will find a register.php file. You can work with it.

Wordpress search page loading on homepage

I'm pretty new to Wordpress and I've been building a theme with reverie-master but the only problem is the search page. All the other pages, category, archive, etc are working.
I use this for searching in my header.php :
<form method="post" action="<?php echo home_url('/'); ?>" class="search-form" role="search">
<div class="small-9 columns no-pad">
<input type="text" class="search-input" name="s" placeholder="Search" value="" />
</div>
<div class="small-3 columns no-pad">
<input class="btn-submit postfix search-input" type="submit" value=""/>
</div>
This shows the search results on the homepage. If I type in "ok" in the search bar it takes me to example : www.homepage.com when it should be on www.homepage.com/?s=ok. The problem with it being on the home page, the paginations will take you to page 2 of the home blog feed instead on www.homepage.com/page/2/ when it should be something ilke this www.homepage.com/page/2/?s=test
When I manualy type in this url in the browser : www.homepage.com/page/2/?s=test the pagination is working. My problem is the pagination and I am wondering why the posts displays on the homepage(which I assume is the problem)
Here is my search.php code :
Starts with <?php get_header(); ?> and ends with <?php get_footer(); ?>
This is the loop in between with pagination :
<h2><?php _e('Search Results for', 'reverie'); ?> "<?php echo get_search_query(); ?>"</h2>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="row pad-row">
<div class="large-11 columns bor-bottom">
<a class="fade" href="<?php the_permalink(); ?>"><p class="feed-title"><?php the_title(); ?></p></a>
<p class="feed-info">By <span class="feed-author"><?php the_author(); ?> </span> • <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?> •
<?php
foreach((g_the_category()) as $category) {
if ($category->cat_name != 'featured') {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
}
}
?>
• <span class="feed-cmt"><?php comments_number( '0 Comments', '1 Comments', '% Comments' ); ?>. </span></p>
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; // end have_posts() check ?>
<!-- Start Pagination -->
<div class="row pad-row">
<div class="large-11 columns pagination-centered large-centered panel-page">
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( function_exists('reverie_pagination') ) { reverie_pagination(); } else if ( is_paged() ) { ?>
<nav id="post-nav">
<div class="post-previous"><?php next_posts_link( __( '← Older posts', 'reverie' ) ); ?></div>
<div class="post-next"><?php previous_posts_link( __( 'Newer posts →', 'reverie' ) ); ?></div>
</nav>
<?php } ?>
</div>
</div>
Do not put search form directly. WP has a functionality to get search form called get_search_form(). This function prints wp basic search form, but still you can customize this. In order to customize, you can use a filter called get_search_form.
function custom_search_form( $form ) {
$form = '<form method="get" action="' . home_url('/') . '" class="search-form" role="search">
<div class="small-9 columns no-pad">
<input type="text" class="search-input" name="s" id="s" placeholder="Search" value="' . get_search_query() . '" />
</div>
<div class="small-3 columns no-pad">
<input class="btn-submit postfix search-input" id="searchsubmit" type="submit" value="'. esc_attr__( 'Search' ) .'"/>
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'custom_search_form' );
And put this to functions.php

My search form is redirecting to the homepage. How to solve?

Everytime when I try to search on my website, it keeps returning to the homepage. I have a search form though, built-in with my theme. Can't find the problem. Can you help me?
<?php get_header(); ?>
<div class="content">
<?php tie_breadcrumbs(); ?>
<div class="page-head">
<h2 class="page-title">
<?php if ( have_posts() ) : ?>
<?php printf( __( 'Search Results for: %s', 'tie' ), '<span>' . get_search_query() . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Nothing Found', 'tie' ); ?>
<?php endif; ?>
</h2>
<div class="stripe-line"></div>
</div>
<?php if ( have_posts() ) : ?>
<?php get_template_part( 'loop', 'search' ); ?>
<?php if ($wp_query->max_num_pages > 1) tie_pagenavi(); ?>
<?php else : ?>
<div id="post-0" class="post not-found post-listing">
<div class="entry">
<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'tie' ); ?></p>
</div>
</div>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
This is the website: http://plugr.nl
Addition: The HTML
<?php if(tie_get_option( 'top_right' ) == 'search'): ?>
<div class="search-block">
<form method="get" id="searchform" action="<?php echo home_url(); ?>/">
<button class="search-button" type="submit" value="<?php if( !$is_IE ) _e( 'Search' , 'tie' ) ?>"></button>
<input type="text" id="s" name="s" value="<?php _e( 'Search...' , 'tie' ) ?>" onfocus="if (this.value == '<?php _e( 'Search...' , 'tie' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search...' , 'tie' ) ?>';}" />
</form>
</div><!-- .search-block /-->
Looks like this search URL is what your template is expecting:
http://plugr.nl/?s=waar
Your form has code like:
<form method="get" id="searchform" action="http://plugr.nl/">
<input type="text" name="inputBox" placeholder="Typ wat je zoekt en druk op enter">
</form>
Change the input name to "s" and see what that does for you.
You might need to grep through the files in your template to find where this form is actually generated. Nested template files will not show up in the wordpress GUI editor. It's also possible your search form is provided through a widget which the template depends on, so you might need to dig a little further.
You need to place "s" for the name value...name="s". Its a default setting for wordpress which will detect this variable for what kind of search you did.. /?s="whatever you searched for"

Wordpress exclude search page from empty search

I've created a search page and using the loop return results based on users input. Problem is when I go to the search page it displays the search page title when the user hasn't entered anything. Is there a way I can remove the search page from the results? I've tried plugins but they don't work - am convinced there is something wrong with my loop but I don't see it.
My code is:
<?php
/*
Template Name: Search Page
?>
<?php get_header(); ?>
<section id="post-<?php the_title(); ?>" class="search-section left <?php post_class(); ?>" role="main">
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<?php if ( have_posts() ) : ?>
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
<?php endif; ?>
</div>
</section>
<aside class="search-sidebar right">
<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-4' ); ?>
<?php endif; ?>
</aside>
screenshot of bug thats happening:
Basically from my understand, you want it so that if the user goes to the search page, they don't see a title on the page that says 'Search Results for: ' with nothing after the colon. I have a proposed code change that will eliminate the title, and allow you to put a message for the user to search for something, to display results.
<?php
/*
Template Name: Search Page
?>
<?php get_header(); ?>
<section id="post-<?php the_title(); ?>" class="search-section left <?php post_class(); ?>" role="main">
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<?php /* ADD THIS CODE */>
<?php $search_term = get_search_query(); ?>
<?php if (!empty($search_term)): /* if search term is not empty */ ?>
<?php /* END ADD THIS CODE */>
<?php if ( have_posts() ) : ?>
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
<?php endif; ?>
<?php /* ADD THIS CODE */>
<?php else: /* if search term is empty */ ?>
<p>Please enter some search text to display search results.</p>
<?php endif; ?>
<?php /* END ADD THIS CODE */>
</div>
</section>
<aside class="search-sidebar right">
<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-4' ); ?>
<?php endif; ?>
</aside>
There are two code blocks to add, one up top, and one down low. Hope this helps!
EDIT (after clarification)
After we talked, it looks like the problem is related to the fact that you have a custom URL for the search page, something like '/search', which is actually a WordPress page labeled 'Search'. The problem is that when you load this search page, your loop already has one result in it, the current page. What you need to do is first check if your current loop is for the search, or if it is for the display of the search page. Do this like so:
<?php
/*
Template Name: Search Page
?>
<?php get_header(); ?>
<section id="post-<?php the_title(); ?>" class="search-section left <?php post_class(); ?>" role="main">
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<?php /* CHANGE THESE LINES FROM ABOVE, KEEP LOWER LINES */ ?>
<?php global $wp_query; ?>
<?php if (!empty($wp_query->query_vars['s'])): ?>
<?php /* END CHANGE THESE LINES FROM ABOVE, KEEP LOWER LINES */ ?>
<?php if ( have_posts() ) : ?>
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
<?php endif; ?>
<?php /* ADD THIS CODE */>
<?php else: /* if search term is empty */ ?>
<p>Please enter some search text to display search results.</p>
<?php endif; ?>
<?php /* END ADD THIS CODE */>
</div>
</section>
<aside class="search-sidebar right">
<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-4' ); ?>
<?php endif; ?>
</aside>
Keep the lower lines, and change those top lines to what I have. This is going to check that your loop is actually the loop that has the results of the search in it. If it is, then it draws the results, if not, then it displays the message below.
Try this:
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
Try this method which I found WordPress StackExchange
$exclude_pages = array('music', 'contact');
$exclude_post_types = array('music', 'any_here');
if ( have_posts() ) : while ( have_posts() ) : the_post();
if ( is_page() && ! empty($exclude_pages) && (
in_array($post->post_name, (array)$exclude_pages) ||
in_array($post->post_title, (array)$exclude_pages)
) ||
( is_single() && in_array(get_post_type(), (array)$exclude_post_types) ) ) continue;
Let me know if it works, or need improvement

Wordpress: Comments: Submitting a comment opens a related post

I have a problem with my comments form.
Submitting a comment leads to open a related post.
Here's my comments.php:
<?php
if ( post_password_required() ) :
echo '<h3 class="comments-header">' . __('Password Protected', 'buddypress') . '</h3>';
echo '<p class="alert password-protected">' . __('Enter the password to view comments.', 'buddypress') . '</p>';
return;
endif;
if ( is_page() && !have_comments() && !comments_open() && !pings_open() )
return;
?>
<?php if ( have_comments() ) : ?>
<div id="comments">
<?php
// Only include comments
$numTrackBacks = 0; $numComments = 0;
foreach ( (array)$comments as $comment )
if ( 'comment' != get_comment_type() )
$numTrackBacks++;
else
$numComments++;
?>
<h3 id="comments">
<?php
printf( _n( '1 Kommentar', '%1$s Kommentare', $numComments, 'buddypress' ),
number_format_i18n( $numComments ), '<em>' . get_the_title() . '</em>' );
?>
</h3>
<?php do_action( 'bp_before_blog_comment_list' ) ?>
<ol class="commentlist">
<?php wp_list_comments() ; ?>
</ol><!-- .comment-list -->
<?php do_action( 'bp_after_blog_comment_list' ) ?>
<?php if ( get_option( 'page_comments' ) ) : ?>
<div class="comment-navigation paged-navigation">
<?php paginate_comments_links(); ?>
</div>
<?php endif; ?>
</div><!-- #comments -->
<?php else : ?>
<?php if ( pings_open() && !comments_open() && is_single() ) : ?>
<p class="comments-closed pings-open">
<?php printf( __('Comments are closed, but trackbacks and pingbacks are open.', 'buddypress'), trackback_url( '0' ) ); ?>
</p>
<?php elseif ( !comments_open() && is_single() ) : ?>
<p class="comments-closed">
<?php _e('Keine Kommentare erlaubt.', 'buddypress'); ?>
</p>
<?php endif; ?>
<?php endif; ?>
<?php if ( comments_open() ) : ?>
<div id="respond">
<div class="comment-avatar-box">
<div class="avb">
<?php if ( bp_loggedin_user_id() ) : ?>
<a href="<?php echo bp_loggedin_user_domain() ?>">
<?php echo get_avatar( bp_loggedin_user_id(), 50 ); ?>
</a>
<?php else : ?>
<?php echo get_avatar( 0, 50 ); ?>
<?php endif; ?>
</div>
</div>
<div class="comment-content">
<h3 id="reply" class="comments-header">
<?php comment_form_title( __( 'Leave a Reply', 'buddypress' ), __( 'Leave a Reply to %s', 'buddypress' ), true ); ?>
</h3>
<p id="cancel-comment-reply">
<?php cancel_comment_reply_link( __( 'Click here to cancel reply.', 'buddypress' ) ); ?>
</p>
<?php if ( get_option( 'comment_registration' ) && !$user_ID ) : ?>
<p class="alert">
<?php printf( __('You must be logged in to post a comment.', 'buddypress'), wp_login_url( get_permalink() ) ); ?>
</p>
<?php else : ?>
<?php do_action( 'bp_before_blog_comment_form' ) ?>
<form action="<?php echo site_url( 'wp-comments-post.php' ) ?>" method="post" id="commentform" class="standard-form">
<?php if ( $user_ID ) : ?>
<p class="log-in-out">
<?php printf( __('Logged in as %2$s.', 'buddypress'), bp_loggedin_user_domain(), $user_identity ); ?> <?php _e('Log out →', 'buddypress'); ?>
</p>
<?php else : ?>
<?php $req = get_option( 'require_name_email' ); ?>
<p class="form-author">
<label for="author"><?php _e('Name', 'buddypress'); ?> <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
<input type="text" class="text-input" name="author" id="author" value="<?php echo $comment_author; ?>" size="40" tabindex="1" />
</p>
<p class="form-email">
<label for="email"><?php _e('Email', 'buddypress'); ?> <?php if ( $req ) : ?><span class="required"><?php _e('*', 'buddypress'); ?></span><?php endif; ?></label>
<input type="text" class="text-input" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="40" tabindex="2" />
</p>
<p class="form-url">
<label for="url"><?php _e('Website', 'buddypress'); ?></label>
<input type="text" class="text-input" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="40" tabindex="3" />
</p>
<?php endif; ?>
<p class="form-textarea">
<label for="comment"><?php _e('Comment', 'buddypress'); ?></label>
<textarea name="comment" id="comment" cols="60" rows="10" tabindex="4"></textarea>
</p>
<?php do_action( 'bp_blog_comment_form' ) ?>
<p class="form-submit">
<input class="submit-comment button" name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit', 'buddypress'); ?>" />
<?php comment_id_fields(); ?>
</p>
<div class="comment-action">
<?php do_action( 'comment_form', $post->ID ); ?>
</div>
</form>
<?php do_action( 'bp_after_blog_comment_form' ) ?>
<?php endif; ?>
</div><!-- .comment-content -->
</div><!-- #respond -->
<?php endif; ?>
<?php if ( $numTrackBacks ) : ?>
<div id="trackbacks">
<span class="title"><?php the_title() ?></span>
<?php if ( 1 == $numTrackBacks ) : ?>
<h3><?php printf( __( '%d Trackback', 'buddypress' ), $numTrackBacks ) ?></h3>
<?php else : ?>
<h3><?php printf( __( '%d Trackbacks', 'buddypress' ), $numTrackBacks ) ?></h3>
<?php endif; ?>
<ul id="trackbacklist">
<?php foreach ( (array)$comments as $comment ) : ?>
<?php if ( get_comment_type() != 'comment' ) : ?>
<li><h5><?php comment_author_link() ?></h5><em>on <?php comment_date() ?></em></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
An answer would be appreciated
Update:
My single.php:
<?php get_header(); ?>
<!-- LAESST DEN HEADER ERSCHEINEN -->
<div id="main">
<!-- DAS IST DER LOOP! HIER WIRD DER BEFEHL GEGEBEN, DEN INHALT ANZUZEIGEN (ARTIKEL ETC) -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2> <!-- DIESER BEFEHL ZEIGT UND VERLINKT DIE ARTIKEL UEBERSCHRIFT -->
<div class="entry">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="author-box">
<p><?php echo get_avatar( get_the_author_meta( 'user_email' ), '50' ); ?></p>
<p><?php printf( __( 'Geschrieben von %s', 'buddypress' ), bp_core_get_userlink( $post->post_author ) ) ?> am <?php the_time('j. F Y'); ?> um <?php the_time(); ?></p>
<p> Kategorie(n): <?php the_category(', '); ?> </p>
</div>
<div id="related-posts"
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>3, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<h3>Das könnte dich auch interessieren</h3><ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li><?php the_title(); ?></li>
<?php
}
echo '</ul>';
}
}
?>
</div>
<!--"NEXT POST" BZW "PREVIOUS POST" NAVIGATION -->
<p align="center"><?php next_posts_link('« Ältere Einträge') ?> <?php previous_posts_link('Neuere Einträge »') ?></p>
<?php endif; ?>
<?php comments_template(); ?> <!-- LAESST DAS KOMMENTARFELD ERSCHEINEN -->
</div><!-- main -->
<div id="sidebar">
<?php get_sidebar(); ?>
<!-- LAESST DIE SIDEBAR ERSCHEINEN -->
</div><!-- sidebar -->
<?php get_footer(); ?>
<!-- DIESER BEFEHL LAESST DEN FOOTER ERSCHEINEN -->
But why is it displayed incorrectly?
The only point in your code that could be responsible for your problem, as far as I can see, is at:
<div class="comment-action">
<?php do_action( 'comment_form', $post->ID ); ?>
</div>
$post->ID should hold the id of the current post or be null. If there is a problem with $post, it will be on the page that calls this comments template, single.php probably. You could try changing your current single.php file for the twentyten one and see if that solves the problem. Or post here that single.php file contents so we can check it.
EDIT:
On the single.php file, you have a new query being executed to get the related posts:
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>3, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
This code is populating the $post variable with each of the related posts found, so once that code is done you will have the $post var holding the last post of the related posts retrieved with that query.
Easiest solution: cut the code for the related posts functionality (everything inside de "related-posts" div, including the opening and closing div tags) and paste it just before the </div><!-- main --> so it doesn't affect the comments or navigation parts.

Categories