Loading wordpress posts after user clicks anchor - wordpress

This is my tab menu, where user can select tab
<div id="slider-menu" class="row">
<div class="span12">
<ul class="nav nav-tabs" id="myTab">
<li class="active">Latest events<div class="triangle"></div></li>
<li>Our champions</li>
<li>We have puppies!</li>
</ul>
</div>
</div>
And there are my tabs, in which content is loaded when page loads
<div class="tab-content">
<div class="tab-pane active" id="home">
<img src="<?php bloginfo('template_url'); ?>/img/slider.png" />
<div class="span12">
<?php
query_posts('cat=7');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
<div class="tab-pane" id="profile">
<img src="<?php bloginfo('template_url'); ?>/img/slider.png" />
<div class="span12">
<?php
query_posts('cat=8');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
<div class="tab-pane" id="messages">
<img src="<?php bloginfo('template_url'); ?>/img/slider.png" />
<div class="span12">
<?php
query_posts('cat=9');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
</div>
When there will be a lot of posts, it will take page to load too long, so my basic idea is to load all posts to the first tab when page loads, and load posts to another tab when user selects it.
I struggle how to combine wp posts loop and ajax to load posts when user clicks specific tab.
Thank you for your help in advance.

$.ajaxSetup({cache:false});
$('#myTab li').click(function(){
var cat_id = $(this).children().attr('rel');
$.get('location.href' + cat_id, function(data) {
$('#' + cat_id).html(data);
return false;
});
So I output category id to anchor rel attribute, then I add click event handler in which I call .get function. After all, I output data.

Related

<?php wp_link_pages(); ?> is working on posts but not on pages to display pagination

I created a theme from scratch and have pagination working on the post pages using , it's working on single.php.
<?php get_header(); ?>
<?php
while(have_posts()) {
the_post();
?>
<div class="mainConent">
<div class="leftSidebar">
<div class="sidebarTitleWrapper">
<?php dynamic_sidebar('left_sidebar') ?>
</div>
</div>
<div class="recentBlogsWrapper">
<div class="blogWrapper">
<h2><?php the_title(); ?></h2>
<p><?php the_time('F j, Y') ?></p>
<?php if(has_post_thumbnail()) { ?>
<div class="card-image">
<img class="page-image" src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" alt="Card Image">
</div>
<?php } ?>
<div class="card-description">
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php comments_template(); ?>
<?php } ?>
<div class="backarrowwrap">
<a class="backhomelink" href="<?php echo site_url(); ?>" <?php if(is_front_page()) echo 'class="active"' ?>>
<img class="backarrow" src="<?php echo get_template_directory_uri(); ?>/img/backarrow.png" alt="back arrow" />
Go Back Home
</a>
</div>
</div>
</div>
</div>
<div class="rightSidebar" id="sidebar">
<div class="sidebarTitleWrapper">
<?php dynamic_sidebar('right_sidebar') ?>
</div>
</div>
I put it right below the_content(); and it's working exactly like I want it to. However, it's not working on page.php, even though it's in the same place on the page.
<?php get_header();
while(have_posts()) {
the_post();
?>
<div class="pageWrapper">
<h2><?php the_title(); ?></h2>
<?php if(has_post_thumbnail()) { ?>
<div class="card-image">
<img class="page-image" src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" alt="Card Image">
</div>
<?php } ?>
<div class="card-description">
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php } ?>
</div>
</div>
<?php get_footer(); ?>
I've included the
<!–-nextpage-–>
code in one of my pages just like I did for the blogs, but it's not paginating between the paragraphs.
What am I doing wrong?
You need at least one <!--nextpage-->, if the content of a page (or post) has at least one <!--nextpage--> tag (and this code is in The Loop), this prints linked page numbers (“Pages: 1 2 3 4 and so on...”), without a link on current page number, and by default within tags:.

How do I add a page featured image to nivo slider in wordpress?

I've followed the guide below in trying to manually install nivo slider into Wordpress: http://www.aoclarkejr.com/author/aj/
I'm trying to get the slider to pick up and display the featured image. I think perhaps there is a problem with the code in step 6, and not just the missing ' (see below). As the slider appears to be loading i.e I get the next/prev tabs and can see the code when viewing the page source, but it's not picking up and displaying the featured image.
<div id="slider-wrap">
<div id="slider">
<?php query_posts(array(
'post_type'=>'slides
));
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post();
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
?>
<img src="<?php echo $thumbnail[0]; ?>" width="" height="" />
<?php endwhile; ?>
</div><!--/slider nivoSlider-->
</div><!--/slider-wrap -->
I should add that I'm trying to get this to work on a page, not custom post.
My ultimate goal is the get the same implementation as this: http://pexetothemes.com/demos/story_wp/home-default/
Here is my code now:
<?php get_header(); ?>
<div class="header-wrapper">
<div id="slider-wrap">
<div id="slider">
<?php query_posts(array(
'post_type'=>'page'
));
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
?> <img src="<?php echo $thumbnail[0]; ?>" width="" height="" />
<?php // endwhile; ?>
</div><!--/slider nivoSlider-->
</div><!--/slider-wrap -->
</div>
<div class="clear"></div>
<div id="content-container" class="content-boxed layout-full">
<div id="full-width" class="content">
<div class="content-box">
<?php the_content(); ?>
</div>
</div>
</div>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div><!-- page wrapper -->
<?php get_footer(); ?>
For some reason part of the page is repeating itself.
<div class="header-wrapper"></div>
<div id="slider-wrap">
<div id="slider">
<img width="" height="" src="http://localhost:8888/defylife/assets/images/posts/ccm_adventure_450gp_left.jpg"></img>
</div>
<!--
/slider nivoSlider
-->
</div>
<!--
/slider-wrap
-->
<div class="clear"></div>
<div id="content-container" class="content-boxed layout-full">
<div id="full-width" class="content">
<div class="content-box"></div>
</div>
</div>
<img width="" height="" src=""></img>
</div>
<!--
/slider nivoSlider
-->
</div>
<!--
/slider-wrap
-->

WordPress custom post type pagination on Zylyz theme

Sorry for asking in my first question, but I have a big problem with my theme and nobody could solve it. Actually it's so simple:
I am using Zylyz recipe theme. I set the home page to a custom post type (recipes), but as you might guess, when I press the "Older Entries" button it gives "not found" error, because it tries to get ordinary blog posts, not "recipes" (you know, if I had enough blog post it wouldn't give error, but would show posts, not recipes).
So, how can I get rid of this problem?
Thank you very much in advance.
Here's the home page's codes:
<div id="content">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=recipes'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="post clearfix" id="post-<?php the_ID(); ?>">
<?php
if ( has_post_thumbnail() ) { ?>
<img class="postimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=200&w=200&zc=1" alt="<?php the_title(); ?> Recipe"/>
<?php } else { ?>
<img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.jpg" alt="" />
<?php } ?>
<div class="cover">
<div class="title">
<h2><?php the_title(); ?></h2>
</div>
<div class="recipemeta">
<span class="cooktime"> <strong>ready in</strong> <?php $cooktime=get_post_meta($post->ID, 'wtf_cooktime', true); echo $cooktime; ?> mins </span> <span class="serve"> <strong>Serving:</strong> <?php $serving=get_post_meta($post->ID, 'wtf_serving', true); echo $serving; ?> people</span>
</div>
<div class="entry" align="justify">
<?php wpe_excerpt('wpe_excerptlength_recipe', ''); ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="clear"></div>
<?php getpagenavi(); ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div>

What would make the_date function in wordpress only show up on random posts

I am working on a website for a client and I specifically needed to modify a given wordpress template. The template uses the get_template_part function to call the content. So for the loop on the index page it should be showing the_date under the header but for some reason it is showing up on some of the posts and not all.
index.php
<?php get_header(); ?>
<!-- Content -->
<div class="container contentarea">
<div class="row">
<div class="column-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- Call content.php -->
<?php get_template_part( 'content' ); ?>
<?php endwhile; ?>
<div class="clearfix"></div>
<div class="paging">
<?php if(function_exists('lugada_kriesi_pagination')) : lugada_kriesi_pagination(); else: ?>
<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(__( '<span class="meta-nav">«</span> Older posts', 'newzeo' )) ?></div>
<div class="nav-next"><?php previous_posts_link(__( 'Newer posts <span class="meta-nav">»</span>', 'newzeo' )) ?></div>
</div>
<?php } endif; ?>
</div>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title">Nothing Found</h1>
</header>
<div class="entry-content">
<p>Sorry, we can't find post you request. Please try search for a related post.</p>
</div>
</article>
<?php endif; ?>
</div> <!-- #content -->
</div> <!-- .column-content -->
<div class="column-sidebar nomargin">
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
content.php
<div class="content-box bucket">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> itemscope itemtype="http://schema.org/Article" >
<h2 class="entry-header">
<div class="entry-meta clearfix" >
<!-- Sticky post -->
<?php if (is_sticky()) : ?>
<div class="sticky-label"></div>
<?php endif; ?>
<!-- Post title -->
<?php the_title(); ?>
</div> <!-- .entry-meta -->
</h2> <!-- .header -->
<!-- Content -->
<div class="entry-content clearfix" itemprop="description">
<?php the_date('','<p><strong>','</strong></p>',true); ?>
<?php the_content('Continue reading'); ?>
<div class="clearfix"></div>
<?php wp_link_pages( array('before' => '<div class="page-link"> <span> Pages: </span>', 'after' => '</div>')); ?>
</div>
<div class="entry-meta footerbox" >
<!-- Category -->
<span class="cat-links">
<span>Posted in</span>
<?php echo get_the_category_list(', '); ?>
</span>
<!-- If single & have tag -->
<!-- Tag -->
<?php if ( is_single() ): if (has_tag()) : ?>
<span class="sep"> | </span>
<span class="tag-links">
<span>Tagged</span>
<?php echo get_the_tag_list('',', ',''); ?>
</span>
<?php endif; ?>
<?php edit_post_link('Edit', '<span class="edit-link"><span class="sep"> | </span>', '</span>'); ?>
<div class="socialshareboxsingle clearfix">
Share this post, let the world know <?php lugada_social_button();?>
</div>
<?php endif; ?>
</div> <!-- .footer -->
</div> <!-- article -->
</div>
<hr class="post-shadow"/>
<!-- If its single, a user has filled out their description and this is a multi-author blog, show a bio on their entries -->
<?php if ( is_single() ) : ?>
<?php if ( get_the_author_meta( 'description' ) && ( ! function_exists( 'is_multi_author' ) || is_multi_author() ) ) : ?>
<div class="content-box">
<div id="author-info">
<div id="author-avatar">
<?php echo get_avatar( get_the_author_meta( 'user_email' ), 80 ); ?>
</div>
<div id="author-description">
<h2 >About <?php echo get_the_author(); ?></h2>
<?php the_author_meta( 'description' ); ?>
</div>
<div id="author-link" class="clearfix">
<?php if ( get_the_author_meta( 'user_url' )) : ?>
<span>Add my circles on Google+ : </span>
<span itemprop="author"><?php echo get_the_author(); ?></span>
<br/>
<?php endif; ?>
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
View all posts by <?php echo get_the_author(); ?><span class="meta-nav">→</span>
</a>
</div>
</div>
</div>
<hr class="post-shadow"/>
<?php endif; endif; ?>
They're not random posts. Read the Codex:
When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.
Change:
<?php the_date('','<p><strong>','</strong></p>',true); ?>
To:
<p><strong><?php the_time('F j, Y'); ?></strong></p>

Simplify while loop containing posts code in wordpress

The code below should display the content of the page followed by certain page content.
<!-- Section -->
<section>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- Article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- Posts for homepage -->
<?php
if ( is_front_page() ) { ?>
<?php the_content(); ?>
<!-- Show page content according to page ID -->
<div class="title-home clearfix">
<div class="four title-home-text">Services Spotlight</div>
<div class="four title-home-text" style="margin-left: 115px;">Industry Expertise</div>
<div class="four title-home-text" style="margin-left: 125px;">Features & Benefits</div>
</div>
<div class="four-wrapper clearfix">
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=40');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=41');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=42');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-3')) ?>
</div>
</div>
</div>
<?php
}
else {
?>
<h1><?php the_title(); ?> </h1>
<?php the_content(); ?>
<?php } ?>
<!-- end post homepage -->
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /Article -->
<?php endwhile; ?>
<?php else: ?>
<!-- Article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /Article -->
<?php endif; ?>
</section>
<!-- /Section -->
<?php get_footer(); ?>
However, it displays the last query as loop.
Output Code:
<article id="post-6" class="post-6 page type-page status-publish hentry">
<article id="post-42" class="post-42 page type-page status-publish hentry">
post-42 should not be displayed in the article.
Also, I know the code is not simplified for using while loop. I want to fix the article problem and simplify this code.
The codex advises against using query_posts for secondary loops as per Codex Query Posts Page
It looks like you are stomping on the main loop (article) since query_posts alters the main loop. If you want to use query_posts it is recommended that you call wp_reset_query() when done. The preferred method is to use WP_query().

Resources