Previous post is shown after submitting a comment - wordpress

What is wrong with my code that it results in page going to the previous post after submitting a comment?
This is the webpage.
You may try if you want.
This is the code from comments.php:
<?php
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) { ?>
This post is password protected. Enter the password to view comments.
<?php
return;
}
?>
<?php if ( have_comments() ) : ?>
<h2 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?></h2>
<div class="navigation">
<div class="next-posts"><?php previous_comments_link() ?></div>
<div class="prev-posts"><?php next_comments_link() ?></div>
</div>
<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>
<div class="navigation">
<div class="next-posts"><?php previous_comments_link() ?></div>
<div class="prev-posts"><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ( comments_open() ) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<p>Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ( comments_open() ) : ?>
<div id="respond">
<h2><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h2>
<div class="cancel-comment-reply">
<?php cancel_comment_reply_link(); ?>
</div>
<?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
<p>You must be logged in to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ( is_user_logged_in() ) : ?>
<p>Logged in as <?php echo $user_identity; ?>. Log out »</p>
<?php else : ?>
<div>
<input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author">Name <?php if ($req) echo "(required)"; ?></label>
</div>
<div>
<input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email">Mail (will not be published) <?php if ($req) echo "(required)"; ?></label>
</div>
<div>
<input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
<label for="url">Website</label>
</div>
<?php endif; ?>
<!--<p>You can use these tags: <code><?php echo allowed_tags(); ?></code></p>-->
<div>
<textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea>
</div>
<div>
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<?php comment_id_fields(); ?>
</div>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
I read this question but don't understand what the solution is.
What do I do to get <?php do_action( 'comment_form', $post->ID ); ?> to behave as expected?
UPDATE:
This is my single.php and as you see, $post is set so don't know what the issue can be:
<?php get_header(); ?>
<nav>
<?php wp_nav_menu(array('menu' => 'Main Nav Menu')); ?>
</nav>
<div id="main-content">
<div class="post-bg-single">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-title-single"><h2><?php the_title(); ?></h2></div>
<h5 class="date-single">Posted on <?php the_time(get_option('date_format')); ?></h5>
<div class="separator-up-single"></div>
<div class="thumbnail-single"><?php
if( has_post_thumbnail() ){
echo get_the_post_thumbnail(); // or just simply, the_post_thumbnail()
}
?></div>
<div class="entry">
<?php the_content(); ?>
<h5 class="expand">Expand post area</h5>
<!-- <h5 class="print">Printable version</h5> -->
</div>
<div class="separator-down"></div>
<h5 class="categories">Categories: <?php the_category(', ') ?></h5>
<h5 class="tags"><?php the_tags('Tags: ', ', ', '<br />'); ?></h5>
<h5 class="edit"><?php edit_post_link(__('→ Edit post← '), ''); ?></h5>
</div>
</div>
<h84>Read more:</h84>
<div id="related-posts">
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>4, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '
<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<?php $bg_image = post_thumb( get_the_post_thumbnail() );?>
<a href="<?php the_permalink() ?>"><div class="post-bg-archive" style="background: #777777 url(<?php echo $bg_image;?>);">
<div id="title-bg">
<div class="transparency"></div>
<div class="archive-title"><h10><?php the_title(); ?></h10></div>
</div>
</div></a>
<?php
}
echo '</ul>';
}
}
?>
</div>
<div class="comments-bg">
<?php comments_template(); ?>
</div>
<?php endwhile; endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

When you do a new WP_Query, it overwrite the global $post variable with the new query.
Either try get_posts() and rewriting the query or add in wp_reset_query(); right before calling comments_template();
wp_reset_query(); would be the fastest way to get it displaying properly.

Related

Woocommerce search.php

How can I add price to 'search.php' in Woocommerce?
Current code is:
<?php
get_header();
global $wp_query;
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?
<hr width=“20%”>
<h3><b><a href="<?php echo get_permalink(); ?>"></b>
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail( 'shop_thumbnail' ) ?>
<br/>
<div class="h-readmore"> <I>Click to see full details</I></div>
</hr width=“20%”>
<?php } ?>
</ul>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
This also has the sidebar at the bottom and not the side - so if anyone can advise how to have the sidebar on the LEFT that too would help.
<?php
get_header();
global $wp_query;
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?>
<hr width=“20%”>
<h3><b><a href="<?php echo get_permalink(); ?>"></b>
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail( 'shop_thumbnail' ) ?>
<br/>
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
<div class="h-readmore"> <I>Click to see full details</I></div>
</hr width=“20%”>
<?php } ?>
</ul>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
update you search.php with above code the price can we call with this <p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>

WordPress search results not displaying

I am using the naked word press theme to build my site with and it all works great apart from when I use the search bar. I type in my search and it takes me to a version of my homepage, but with no content on it.
How do I get my search results to display?
Create a search.php and use this code as an example.
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : ?>
<h1>Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('acapellas'); wp_reset_query(); ?></h1>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</li>
<?php endwhile; endif; ?>
</ul>
</div>
<?php get_footer(); ?>
Make sure your searchform.php complies with Wordpress's standards, heres an example.
<form method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( 'Search:', 'label' ) ?></span>
<span>Search</span>
<input type="search" class="search-field" placeholder="Search" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search:', 'label' ) ?>" />
</label>
<button type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>">
</button>
</form>

wordpress search page don't give search results

I made my own search form page and search page, But know when I search for something the search result gives back nothing I searched alot on the web and following some tutorials to find the issue but I can't. Her's the code:
searchform.php:
<form role="search" method="get" class="visible-lg search-form arrow_box search-back navbar-form navbar-right" action="<?php echo home_url( '/' ); ?>">
<div class="form-group">
<input type="search" class="search-field form-control" size="49" placeholder="بگەڕێ" value="" name="s" title="بگەڕێ" />
</div>
<input type="submit" class="search-submit search-button btn btn-default" value="بگەڕێ" />
</form>
search.php:
<?php
/*
Template Name: Search Page
*/
?>
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-md-5 news">
<?php if ( have_posts() ) : ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<?php printf( __( 'ئەنجامەکانی گەڕان بۆ: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'search' ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'search' ); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
After I tried many codes I finally found that I have to add the title or the content after the while loop, I don't know why but this is the solution I just changed the search.php:
<?php
/*
Template Name: Search Page
*/
?>
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-md-5 news">
<?php if ( have_posts() ) : ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<?php printf( __( 'serch results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>
<br/><br/>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h4 class=""><?php the_title(); ?></h4>
<div class="naskh"><?php the_excerpt(); ?></div>
<?php endwhile; ?>
<?php else : ?>
<h4>Nothing found try something else.</h4>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>

Basic search in wordpress

I am creating a wordpress template in which I want to integrate a simple search form. I googled a lot about this in the last 3 days and tried several tutorials but I am afraid there is something I don't get at all. I have 3 pages for the search: search.php, searchform.php and searchpage.php. All the tutorials I read provide similar code like this:
search.php:
<?php if (have_posts()) : ?>
…
<?php while (have_posts()) : the_post(); ?>
…
<?php endwhile; else: ?>
… <p>The key word <strong><?php the_search_query(); ?></strong> is not on this website.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php include (TEMPLATEPATH . "/searchpage.php"); ?>
<?php endif; ?>
searchform.php:
<?php
$querystring = esc_attr(apply_filters('the_search_query', get_search_query()));
$searchstring = "Suchbegriff eingeben";
if (empty($querystring)) { $querystring = $searchstring; }
?>
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<div>
<input type="text" name="s" id="s" value="<?php echo $querystring; ?>"
onblur="if (this.value == '') { this.value = '<?php echo $searchstring; ?>'; }"
onfocus="if (this.value == '<?php echo $searchstring; ?>') { this.value = ''; }" />
<input type="submit" id="searchsubmit" value="Suchen" />
</div>
</form>
searchpage.php (adapted from page.php):
<?php
/*
Template Name: Search Page
*/
?>
<div id="content">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="blogpost">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php $this->posts = $wpdb->get_results($this->request); ?>
</div> <!-- end class blogpost -->
<?php endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
If there is no match with the key word the search works. But if there is a match I only get … … … … … … … as output. I know that must be from the search.php but I have no idea how I can change that. Thanks for your advise and help, I really appreciate it!
The important file is search.php, which displays any matching results, or a failure message if there are no matches. Try something like this:
<?php
/**
* Search results page
*/
?>
<?php if ( have_posts() ): ?>
<h2>Search Results for '<?php echo get_search_query(); ?>'</h2>
<ol>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate><?php the_date(); ?> <?php the_time(); ?></time> <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?>
<?php the_content(); ?>
</li>
<?php endwhile; ?>
</ol>
<?php else: ?>
<h2>No results found for '<?php echo get_search_query(); ?>'</h2>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Wordpress Comment Pagination

Here is a post with 12 comments :
http://test1.zomghentai.com/kateikyoushi-no-onee-san-2-h-no-hensachi-agechaimasu-episode-1
In my wordpress Discussion Settings, I have set it to
"Break Comments into Pages with 5 comments each"
As you can see, at the bottom of comments I have links to Page 1, 2, and 3.
The problem?
1) Page 1 (default page) is showing all 12 comments at once, instead of showing just 5
and
2) Page 2, and 3, are all the same as Page 1
My comments.php file is as followed :
<div id="comments">
<?php // Do not delete these lines
if ('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
?>
<h3>This post is password protected. Enter the password to view comments.</h3>
<?php
return;
}
}
/* This variable is for alternating comment background */
$oddcomment = 'alt';
?>
<?php if ($comments) : ?>
<span style="font-size: 13px;"><strong>Comments</strong></span>
<ul>
<?php foreach ($comments as $comment) : ?>
<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
<div class="cauthor"><strong><?php comment_author_link() ?></strong> says on <?php comment_date('M jS, Y') ?> at <?php comment_time() ?><?php if ($comment->comment_approved == '0') : ?> (Your comment is awaiting moderation)<?php endif; ?></div>
<div class="cbox">
<?php comment_text() ?>
</div>
<div style="clear: both;"></div>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php endforeach; /* end for each comment */ ?>
</ul>
<?php paginate_comments_links() ?>
<?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. -->
<p>Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ('open' == $post-> comment_status) : ?>
<div class="postinput">
<span style="font-size: 13px;padding: 10px 0 0 0;"><strong>Leave a Comment</strong></span>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be logged in to post a comment.</p>
<?php else : ?>
<form action="http://www.hentaidreaming.com/wp-comments-post.php" method="post" id="commentform">
<?php if ( $user_ID ) : ?>
<p>Logged in as <?php echo $user_identity; ?>. Logout »</p>
<?php else : ?>
<p>
<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="20" tabindex="1" />
<label for="author"><small>Name <?php if ($req) _e('<strong>(required)</strong>'); ?></small></label>
</p>
<p>
<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="20" tabindex="2" />
<label for="email"><small>Mail <?php if ($req) _e('<strong>(required, will not be published)</strong>'); ?></small></label>
</p>
<?php endif; ?>
<p>
<textarea name="comment" id="comment" tabindex="4" rows="10" cols="50" ></textarea>
</p>
<p>
<input name="submit" type="image" id="submit" class="input-submit" tabindex="5" value="Submit Comment" title="Please review your comment before submitting" alt="Submit Comment" src="http://www.hentaidreaming.com/wp-content/themes/hdreamwp/images/submit.gif" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
<?php endif; // if you delete this the sky will fall on your head ?>
</div> <!-- End "postinput" -->
</div> <!-- End "comments" -->
paginate_comments_links()
This is what you should have posted, what you posted tells nothing.

Resources