Wordpress posts repeating - php

Hey guys I am using the Imbalance2 theme for WordPress and I have created a new loop to deal with a different page as I have got one category directing to a page, however the posts that are on the page when first loaded are just repeating as I scroll down the page. It is using an ajax thing to load on scroll. Below is my code for the new loop:
<?php if ( ! have_posts() ) : ?>
<div id="post-0" class="post error404 not-found">
<h1 class="entry-title"><?php _e( 'Not Found', 'imbalance2' ); ?></h1>
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'imbalance2' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</div><!-- #post-0 -->
<?php endif; ?>
<?php $imbalance2_theme_options = get_option('imbalance2_theme_options') ?>
<div id="boxes">
<?php while ( have_posts() ) : the_post(); ?>
<div class="box">
<div class="rel">
<?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?>
<?php if ($imbalance2_theme_options['images_only'] == 0): ?>
<h1 style="padding-top:8px; padding-bottom:2px;"><?php the_title(); ?></h1>
<?php the_excerpt() ?>
<div class="categories" style="padding-top:5px;"><?php
$key = 'title';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo "<strong>Job Title: </strong>";
echo $themeta;
}
?>
<br />
<?php
$key = 'location';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo "<strong>Location: </strong>";
echo $themeta;
}
?>
</div>
<div class="posted"><?php imbalance2_posted_on() ?> <span class="main_separator">/</span>
<?php echo comments_popup_link( __( 'No comments', 'imbalance2' ), __( 'One Comment', 'imbalance2' ), __( '% Comments', 'imbalance2' ) ); ?>
</div>
<?php endif ?>
<div class="texts">
<?php if ($imbalance2_theme_options['images_only'] == 1): ?>
<a class="transparent" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a>
<?php endif ?>
<div class="abs">
<?php if ($imbalance2_theme_options['images_only'] == 0): ?>
<?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?>
<?php endif ?>
<h1 style="padding-top:8px; padding-bottom:2px;"><?php the_title(); ?></h1>
<?php the_excerpt() ?>
<div class="categories" style="padding-top:5px;"><?php
$key = 'title';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo "<strong>Job Title: </strong>";
echo $themeta;
}
?>
<br />
<?php
$key = 'location';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo "<strong>Location: </strong>";
echo $themeta;
}
?>
</div>
<?php the_excerpt() ?>
<div class="posted"><?php imbalance2_posted_on() ?> <span class="main_separator">/</span>
<?php echo comments_popup_link( __( 'No comments', 'imbalance2' ), __( 'One Comment', 'imbalance2' ), __( '% Comments', 'imbalance2' ) ); ?>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php if ( $wp_query->max_num_pages > 1 ) :
if ( $imbalance2_theme_options['navigation'] == 0 ) : // Default ?>
<div class="fetch">
<?php next_posts_link( __( 'Load more posts', 'imbalance2' ) ); ?>
</div>
<script type="text/javascript">
// Ajax-fetching "Load more posts"
$('.fetch a').live('click', function(e) {
e.preventDefault();
$(this).addClass('loading').text('Loading...');
$.ajax({
type: "GET",
url: $(this).attr('href') + '#boxes',
dataType: "html",
success: function(out) {
result = $(out).find('#boxes .box');
nextlink = $(out).find('.fetch a').attr('href');
$('#boxes').append(result).masonry('appended', result);
$('.fetch a').removeClass('loading').text('Load more posts');
if (nextlink != undefined) {
$('.fetch a').attr('href', nextlink);
} else {
$('.fetch').remove();
}
}
});
});
</script>
<?php elseif ( $imbalance2_theme_options['navigation'] == 1 ) : // Infinite scroll ?>
<div class="infinitescroll">
<?php next_posts_link( __( 'Load more posts', 'imbalance2' ) ); ?>
</div>
<script type="text/javascript">
// Infinite Scroll
var href = 'first';
$(document).ready(function() {
$('#boxes').infinitescroll({
navSelector : '.infinitescroll',
nextSelector : '.infinitescroll a',
itemSelector : '#boxes .box',
loadingImg : '<?php echo get_bloginfo('stylesheet_directory') ?>/images/loading.gif',
loadingText : 'Loading...',
donetext : 'No more pages to load.',
debug : false
}, function(arrayOfNewElems) {
$('#boxes').masonry('appended', $(arrayOfNewElems));
if (href != $('.infinitescroll a').attr('href'))
{
href = $('.infinitescroll a').attr('href');
}
});
});
</script>
<?php endif; ?>
<?php endif; ?>
Thanks for any help,
Adam

I think its because you have two <?php the_excerpt() ?> inside one loop, on line 54 and 73.

Related

How to add new categories in Wordpress search.php

I'm struggling to add new categories in search.php. But I failed. Actually the php file is beyond me. I need help :( I have 4 categories, location, sub-location, city and municipality. But these search codes use only titles. How can I add these categories in search.php file? Anybody can say the resolve please?
if( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'noo_property' ) :
?>
<?php
global $wp_query;
$show_map = noo_get_option('noo_property_listing_map',1);
$show_search = noo_get_option('noo_property_listing_search',1);
$disable_map = ( ! $show_map && $show_search ) ? ' disable_map="true"' : '';
$disable_search_form = ( $show_map && ! $show_search ) ? ' disable_search_form="true"' : '';
$search_layout = noo_get_option('noo_property_listing_map_layout','horizontal');
$advanced_search = ($show_search && noo_get_option('noo_property_listing_advanced_search',0)) ? ' advanced_search="true"' : '';
$title = __('Properties matching your search', 'noo');
?>
<?php get_header();
?>
<div class="container-wrap">
<?php if(!empty($show_map) || !empty($show_search)):?>
<?php echo do_shortcode('[noo_advanced_search_property style="'.$search_layout.'"' . $disable_map . $disable_search_form . $advanced_search . ']');?>
<?php endif;?>
<div class="main-content container-boxed max offset">
<div class="row">
<div class="<?php noo_main_class(); ?>" role="main">
<?php if ( have_posts() ) : ?>
<?php
$args = array(
'query' => $wp_query,
'title' => $title,
'display_mode' => true,
'default_mode' => '',
'show_pagination' => true,
'ajax_pagination' => false,
'show_orderby' => noo_get_option('noo_property_listing_orderby', 1)
);
re_property_loop( $args ); ?>
<?php else : ?>
<?php noo_get_layout( 'no-content' ); ?>
<?php endif; ?>
<?php
wp_reset_query();
wp_reset_postdata();
?>
</div> <!-- /.main -->
<?php get_sidebar(); ?>
</div><!--/.row-->
</div><!--/.container-boxed-->
</div><!--/.container-wrap-->
<?php get_footer(); ?>
<?php else :
?>
<?php get_header(); ?>
<div class="container-wrap">
<div class="main-content container-boxed max offset">
<div class="row">
<div class="<?php noo_main_class(); ?> <?php noo_page_class(); ?>" role="main">
<h1><?php _e('Results For', 'noo'); ?><span>"<?php the_search_query(); ?>"</span></h1>
<div id="search-results">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php if( get_post_type($post->ID) == 'post' ){ ?>
<article class="result">
<div class="content-featured">
<?php noo_featured_content( $post->ID ); ?>
</div>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Blog Post', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php }
else if( get_post_type($post->ID) == 'page' ){ ?>
<article class="result">
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Page', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php }
else if( get_post_type($post->ID) == 'product' ){ ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''. get_the_post_thumbnail($post->ID, 'full', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Product', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } else if( get_post_type($post->ID) == 'noo_property' ){ ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''. get_the_post_thumbnail($post->ID, 'property-image', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Property', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } else { ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''.get_the_post_thumbnail($post->ID, 'full', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } ?>
<?php endwhile;
else: echo "<p>" . __('No results found', 'noo') . "</p>"; endif;?>
</div><!--/search-results-->
<?php noo_pagination(); ?>
</div> <!-- /.main -->
<?php get_sidebar(); ?>
</div><!--/.row-->
</div><!--/.container-boxed-->
</div><!--/.container-wrap-->
<?php get_footer(); ?>
<?php endif; ?>
Am I looking wrong php file? Or true

Wordpress getting first post

I am trying to change the class if $firstPost = 0but i'm not sure 100% about the while loop etc as I have an idea I don't need it
PHP/HTML
<?php
$getPosts = new wp_query(array('showposts' => 5, 'orderby' => 1));
if($getPosts->have_posts()):
$firstPost = 0;
while($getPosts->have_posts()):
$getPosts->the_post();
$cssClass = '';
if($firstPost == 0)
{
$cssClass = array('article','first-post');
}else{
$cssClass = array('article');
}
?>
<article <?php post_class($cssClass); ?> id="post-<?php the_ID(); ?>" itemscope itemtype="http://schema.org/Article">
<?php if ( is_front_page() && is_home() ): ?>
<div class="post-thumbnail">
<?php if ( get_the_post_thumbnail($post_id) != '' ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else { ?>
<img src="<?php echo catch_that_image(); ?>" alt="" />
<?php } ?>
</div>
<article class="post-content">
<header class="post-header">
<div class="post-category"><?php the_category( ', ' ) ?></div>
<h2 class="post-title" itemprop="name"><?php the_title(); ?></h2>
<div class="post-date"><?php echo get_the_date( 'F j, Y' ) ?>.</div>
<div class="post-comment"><?php comments_popup_link( __( '0 comments','adelle-theme' ), __( '1 Comment','adelle-theme' ), __( '% Comments','adelle-theme' ) ); ?></div>
</header>
<?php the_excerpt(); ?>
<footer class="post-footer"></footer><!-- .post-footer -->
</article><!-- .post-content -->
<?php endif; ?>
</article><!-- .article -->
It's better to use a boolean value for $firstPost. For example:
<?php
$getPosts = new WP_Query(array('showposts' => 5, 'orderby' => 1));
if($getPosts->have_posts()):
$firstPost = true;
while($getPosts->have_posts()):
$getPosts->the_post();
$cssClass = '';
if($firstPost)
{
$cssClass = array('article','first-post');
}else{
$cssClass = array('article');
}
?>
<article <?php post_class($cssClass); ?> id="post-<?php the_ID(); ?>" itemscope itemtype="http://schema.org/Article">
<?php if ( is_front_page() && is_home() ): ?>
<div class="post-thumbnail">
<?php if ( get_the_post_thumbnail($post_id) != '' ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else { ?>
<img src="<?php echo catch_that_image(); ?>" alt="" />
<?php } ?>
</div>
<article class="post-content">
<header class="post-header">
<div class="post-category"><?php the_category( ', ' ) ?></div>
<h2 class="post-title" itemprop="name"><?php the_title(); ?></h2>
<div class="post-date"><?php echo get_the_date( 'F j, Y' ) ?>.</div>
<div class="post-comment"><?php comments_popup_link( __( '0 comments','adelle-theme' ), __( '1 Comment','adelle-theme' ), __( '% Comments','adelle-theme' ) ); ?></div>
</header>
<?php the_excerpt(); ?>
<footer class="post-footer"></footer><!-- .post-footer -->
</article><!-- .post-content -->
<?php endif; ?>
</article><!-- .article -->
<?php
$firstPost = false;
endwhile;
endif;
?>

How to insert "Author" code in Wordpress Required theme?

Been trying to insert "By Author" by <?php the_author() ?> code on a Wordpress theme(Required by 8Bit). Request to help. Need to insert after the post/page title and before date.
The code is as follows:
<header>
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h1><!-- /.entry-title -->
<?php } // end if ?>
<div class="post-meta">
<span class="post-date">
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<?php the_time( get_option( 'date_format' ) ); ?>
<?php } else { ?>
<a href="<?php the_permalink(); ?>">
<?php the_time( get_option( 'date_format' ));?>
</a>
<?php } // end if/else ?>
</span><!-- /.post-date -->
<?php _e( ' | ', 'required' ); ?>
<span class="comment-link">
<?php
comments_popup_link( 'Comment', '1 comment', '% comments',
'comments-link', '');
?>
</span><!-- /.comment-link -->
<?php edit_post_link( '- edit ', '<span>', '</span>'); ?>
</div><!-- /.post-meta -->
</header>
Thanks :)
This is the loop code:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
get_template_part( 'content', get_post_format() );
} // end while
Here's an example, between the title and date:
<header>
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h1><!-- /.entry-title -->
<?php } // end if ?>
<div class="post-meta">
<?php the_author(); ?>
<span class="post-date">
<?php if ( 0 < strlen( get_the_title() ) ) { ?>
<?php the_time( get_option( 'date_format' ) ); ?>
<?php } else { ?>
<a href="<?php the_permalink(); ?>">
<?php the_time( get_option( 'date_format' ));?>
</a>
<?php } // end if/else ?>
</span><!-- /.post-date -->
<?php _e( ' | ', 'required' ); ?>
<span class="comment-link">
<?php
comments_popup_link( 'Comment', '1 comment', '% comments',
'comments-link', '');
?>
</span><!-- /.comment-link -->
<?php edit_post_link( '- edit ', '<span>', '</span>'); ?>
</div><!-- /.post-meta -->
</header>

Only show specific category in wordpress loop?

How Can I only show a specific category in my wordpress index page? Below is my theme code...
Also, when looking at the URL for my category (how I usually get the ID) it seems a strange format..
http://oil.wpengine.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=1179&post_type=post
<?php query_posts( array ( 'Event_News' => 'event-news' ) ); ?>
<?php if (have_posts()) : ?>
<ul class="posts">
<li id="post-<?php the_ID(); ?>">
<?php
get_the_image( array( 'size' => 'loop-main', 'width' => 160, 'height' => 120, 'before' => '<div class="cover">', 'after' => '</div>' ) );
?>
<div class="postcontent">
<h2><?php the_title(); ?></h2>
<div class="postmetadata">
<ul>
<?php if (option::get('display_date') == 'on') { ?><li class="calendar"><time datetime="<?php the_time("Y-m-d"); ?>" pubdate><?php the_time("j F Y"); ?></time></li><?php } ?>
<?php if (option::get('display_author') == 'on') { ?><li class="author"><?php _e('By', 'wpzoom');?> <?php the_author_posts_link(); ?></li><?php } ?>
<?php if (option::get('display_category') == 'on') { ?><li class="category"><?php the_category(', '); ?></li><?php } ?>
<?php if (option::get('display_comments') == 'on') { ?><li class="comments"><?php comments_popup_link( __('0 comments', 'wpzoom'), __('1 comment', 'wpzoom'), __('% comments', 'wpzoom'), '', ''); ?></li><?php } ?>
</ul>
</div><!-- end .postmetadata -->
<?php the_excerpt(); ?>
<p class="more"><?php _e('continue reading »', 'wpzoom');?> <?php edit_post_link( __('Edit this post', 'wpzoom'), ' | ', ''); ?></p>
</div><!-- end .postcontent -->
<div class="cleaner"> </div>
<div class="sep"> </div>
</li><!-- end #post-<?php the_ID(); ?> -->
<?php endwhile; // ?>
</ul>
<div class="cleaner"> </div>
<?php else : ?>
<p class="title"><?php _e('There are no posts in this category', 'wpzoom');?></p>
<?php endif; ?>
<?php get_template_part( 'pagination'); ?>
</div><!-- end .box -->
You can do query_post just before the loop
query_posts( array ( 'category_name' => 'my-category-slug' ) );
If you want posts from more than one category then you can use
query_posts('cat=8,4,3');
8,4,3 are the id for the 3 categories
and after the loop use
wp_reset_query();
For more details view this link
http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category

I am using ajax and getting a failure but no error message

I am using Wordpress 3.5 and making a custom page template to do a database look up. It is failing and the output is:
[object Object]: error:
I tried this in jsfiddler but it gave the same error.
The page code is:
<?php
// Exit if accessed directly
if ( !defined('ABSPATH')) exit;
/*
Template Name: DBLookup
*/
?>
<script language='JavaScript' type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type='text/javascript' language='javascript'>
function getlist(form) {
//alert(form.mname.value);
//$('#result_table').html(form.mname.value);
$.ajax({
url: 'getlist.php',
type: 'POST',
data: {n : form.mname.value},
dataType: 'html',
success: function(output_string) {
$('#result_table').html(output_string);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#result_table').html(XMLHttpRequest + ': ' + textStatus + ': '+ errorThrown);
}
} // End of success function of ajax form
); // End of ajax call
}
</script>
<?php get_header(); ?>
<div id="content" class="grid col-620">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $options = get_option('responsive_theme_options'); ?>
<?php if ($options['breadcrumb'] == 0): ?>
<?php echo responsive_breadcrumb_lists(); ?>
<?php endif; ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( comments_open() ) : ?>
<div class="post-meta">
<?php responsive_post_meta_data(); ?>
<?php if ( comments_open() ) : ?>
<span class="comments-link">
<span class="mdash">—</span>
<?php comments_popup_link(__('No Comments ↓', 'responsive'), __('1 Comment ↓', 'responsive'), __('% Comments ↓', 'responsive')); ?>
</span>
<?php endif; ?>
</div><!-- end of .post-meta -->
<?php endif; ?>
<div class="post-entry">
<?php the_content(__('Read more ›', 'responsive')); ?>
<?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
</div><!-- end of .post-entry -->
<?php if ( comments_open() ) : ?>
<div class="post-data">
<?php the_tags(__('Tagged with:', 'responsive') . ' ', ', ', '<br />'); ?>
<?php the_category(__('Posted in %s', 'responsive') . ', '); ?>
</div><!-- end of .post-data -->
<?php endif; ?>
<div class="post-edit"><?php edit_post_link(__('Edit', 'responsive')); ?></div>
</div><!-- end of #post-<?php the_ID(); ?> -->
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="navigation">
<div class="previous"><?php next_posts_link( __( '‹ Older posts', 'responsive' ) ); ?></div>
<div class="next"><?php previous_posts_link( __( 'Newer posts ›', 'responsive' ) ); ?></div>
</div><!-- end of .navigation -->
<?php endif; ?>
<?php else : ?>
<h1 class="title-404"><?php _e('404 — Fancy meeting you here!', 'responsive'); ?></h1>
<p><?php _e('Don't panic, we'll get through this together. Let's explore our options here.', 'responsive'); ?></p>
<h6><?php _e( 'You can return', 'responsive' ); ?> <?php _e( '← Home', 'responsive' ); ?> <?php _e( 'or search for the page you were looking for', 'responsive' ); ?></h6>
<?php get_search_form(); ?>
<?php endif; ?>
<div>
<form name="DBLookup" action="javascript:void(0);">
Full or partial malware name<br>
<input style="width: 350px;" type="text" name="dataname" id="mname">
<input type="submit" name="submit" onClick="getlist(this.form);">
</form>
<div id='result_table'></div>
</div>
</div><!-- end of #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
getlist.php is simply:
<?php
echo "got it";
?>

Categories