WordPress get_query_var() with offset? - wordpress

I am currently using get_query_var() to displays all post in the index.php page, and I wonder if it's possible to skip the latest post ( I am already displaying it on the home page...) using any offset parameter ?
<div class="wrapper section-inner">
<div class="content full-width">
<?php if (have_posts()) : ?>
<div class="posts">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$total_post_count = wp_count_posts();
$published_post_count = $total_post_count->publish;
$total_pages = ceil( $published_post_count / $posts_per_page );
if ( "1" < $paged ) : ?>
<div class="page-title">
<h4><?php printf( __('Page %s of %s', 'hemingway'), $paged, $wp_query->max_num_pages ); ?></h4>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php endwhile; ?>
</div> <!-- /posts -->
<?php endif; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="post-nav archive-nav">
<?php echo get_next_posts_link( __('« Older<span> posts</span>', 'hemingway')); ?>
<?php echo get_previous_posts_link( __('Newer<span> posts</span> »', 'hemingway')); ?>
<div class="clear"></div>
</div> <!-- /post-nav archive-nav -->
<?php endif; ?>
</div> <!-- /content -->
</div> <!-- /wrapper -->
Thanks for your feedback and suggestions

One way is to skip the first index:
<?php
$i = 0;
while (have_posts()) : the_post();
if($i > 0):
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php
endif;
i++;
endwhile;
?>

Related

get post thumbnail image in wordpress and display in 3 coulmn

I am trying to display one particular category posts as a three column layout The problem I have is I am not sure how I can use for or forwach to loop the display of each post thumbnail so whn it comes more than three I can use one_thrid_last. css class.
<?php while ( have_posts() ) : the_post(); ?>
<?php if (is_category('actress-gallery') ):?>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="one_fourth_last">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php echo $image_url = wp_get_attachment_image( get_post_thumbnail_id($post->ID) , 'thumbnail' ); ?>
<h2><?php the_title(); ?></h2>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<div class="wrapper" style="width:800px; height:auto;">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="image-wrapper" style=" width:250px; height:300px;" >
<?php the_title();?>
<?php the_content();?>
<?php the_post_thumbnail(); ?>
</div>
<?php } endwhile; endif; ?>
</div>
<div class="wrapper" style="width:750px; height:700px;">
<?php while (have_posts()) : the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div style="width:250px; height:300px;" >
<?php the_title();?>
<?php the_post_thumbnail(); ?>
</div>
<?php } endif; ?>
</div>
You can use a $count variable and check for the 3rd thumbnail.
<?php if ( have_posts() ) : ?>
<?php $count = 1; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_post_thumbnail() ) : ?>
<?php if ($count % 3 == 0) : ?>
<div class = "one_third_last">
<?php else : ?>
<div class = "other_class">
<?php endif; ?>
<?php the_title();?>
<?php the_content();?>
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<?php $count++; ?>
<?php endwhile; ?>
<?php endif; ?>

Wordpress Pagination

I have a wordpress site : There is a problem with the pagination.. When I click on 2'nd page it shows up the first one(index page). The other pages are working. Can you help me?
I looked up for errors in the loop but i didn't found anything!
this my index.php code
<?php get_header(); ?>
<div id="content">
<?php if(get_option('freshlife_featured_content_enable') == 'on') { ?>
<div id="featured-content">
<div class="heading">
<span class="heading-text"><?php _e('Featured Articles', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<ul>
<?php
$counter = 1;
query_posts( array(
'showposts' => get_option('freshlife_featured_post_num'),
'tag' => get_option('freshlife_featured_post_tags')
) );
if( have_posts() ) : while( have_posts() ) : the_post();
?>
<li class="featured-<?php echo $counter; ?>"><?php the_post_thumbnail('featured-thumb', array('class' => 'entry-thumb')); ?><span class="entry-date"><abbr title="<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'themejunkie'); ?></abbr></span><h2 class="entry-title"><?php the_title(); ?></h2></li>
<?php $counter++; endwhile; endif; wp_reset_query(); ?>
</ul>
</div> <!-- end #featured-content -->
<?php } ?>
<div class="heading">
<span class="heading-text"><?php _e('All Stories', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include(TEMPLATEPATH. '/includes/templates/loop.php'); ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
<div class="pagination">
<div class="left"><?php previous_posts_link(__('Newer Entries', 'themejunkie')) ?></div>
<div class="right"><?php next_posts_link(__('Older Entries', 'themejunkie')) ?></div>
<div class="clear"></div>
</div> <!-- end .pagination -->
<?php } ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It's hard to say without looking at the WP_Query generated by the requests.
But I do see something that might be causing problems, query_posts alters the main query, that could be messing with the pagination.
Try to use get_posts instead query_posts, so the main loop is not affected.
A more detailed explanation can be found here

Wordpress category template is showing posts from all categories instead of specific category posts

I have an archive page that's set up to display category specific posts. However, instead of showing only the posts from a given category on the category page, it's showing all posts. For an example, see here.
Here's the code I'm using on my archive.php page. I know it's improper use of the loop, but I'm not sure how to fix it. Thanks for the help.
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1>
<nav class="blogNav" role="navigation">
<?php bones_blog_nav(); // Adjust using Menus in Wordpress Admin ?>
</nav>
<div id="main" class="eightcol first clearfix" role="main">
<div class="catwhiteBg">
<?php if (is_category()) { ?>
<h1 class="catTitle">
<span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?>
</h1>
<?php echo category_description( $category_id ); ?>
<?php } elseif (is_author()) { ?>
<div class="authorTop">
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<div class="author-pic"><?php echo get_avatar( $curauth->user_email, '80' ); ?></div>
<div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span>
<?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>
</div>
<div class="author-bio"><?php echo $curauth->description; ?></div>
<div class="author-twitter"><span>twitter</span></div>
</div>
<?php } elseif (is_day()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?>
</h1>
<?php } elseif (is_month()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?>
</h1>
<?php } elseif (is_year()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?>
</h1>
<?php } ?>
</div>
<div class="psts">
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
query_posts(array('posts_per_page' => '8','paged'=>$paged));
?>
<?php
$count = 1;
while (have_posts()) : the_post(); ?>
<div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0 )) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>">
<article id="post-<?php the_ID(); ?>" role="article">
<div class="thumb-wrapper mobile">
<?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'post-thumb' ); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?>
<header class="post-thumb-header">
<h2 class="post-title"><?php the_title(); ?></h2>
</header> <!-- end article header -->
<p class="meta"><?php the_category(', '); ?></p>
</div>
<section class="mobile-content">
<?php the_excerpt(); ?>
</section>
</article> <!-- end article -->
</div>
<?php $count++; ?>
<?php endwhile; ?>
<nav class="wp-prev-next">
<?php echo rb_pagination(); ?>
</nav>
</div> <!-- end .psts -->
</div> <!-- end #main -->
<?php get_sidebar(); // sidebar 1 ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
I think you're overriding the original query with this line:
query_posts(array('posts_per_page' => '8','paged'=>$paged));
Can you swap this line with this, and let me know the results?
global $query_string;
query_posts( $query_string . "&posts_per_page=8&paged=$paged" );
if that fails try this:
query_posts(array('posts_per_page' => '8','paged'=>$paged, 'cat' => $category_id ));

How to call Custom Field in Wordpress Template

I want to call custom field in single.php template to complete a short code and thus show a menu.
I places the below code but it is not working
<?php echo do_shortcode("[custommenu menu=<?php echo get_post_meta($post->ID, ‘tabmenu’, true); ?>]?>")
Please help
Here's my template file
I saved this as single-default.php and calling it category wise from single.php file
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="content">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="tab-menu"><?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>
</div>
<div class="entry-content">
<?php if(get_option('resizable_integrate_singletop_enable') == 'on') echo (get_option('resizable_integration_single_top')); ?>
<?php the_content(''); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'themejunkie' ), 'after' => '</div>' ) ); ?>
<?php if(get_option('resizable_integrate_singlebottom_enable') == 'on') echo (get_option('resizable_integration_single_bottom')); ?>
<div class="clear"></div>
<?php printf(the_tags(__('<div class="entry-tags"><span>Tags:</span> ','themejunkie'),', ','</div>')); ?>
<?php edit_post_link('('.__('Edit', 'themejunkie').')', '<span class="entry-edit">', '</span>'); ?>
</div><!-- .entry-content -->
</div><!-- #post-<?php the_ID(); ?> -->
<div class="clear"></div>
<div class="entry-bottom">
<div class="clear"></div>
</div><!-- .entry-bottom -->
</div><!-- #content -->
<?php endwhile; else: ?>
<?php endif; ?>
You need to concatenate the inner echo in the shortcode
<?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>

WordPress Pagination on Page

I have the following code on a WordPress page. It basically just grabs 3 posts and displays them as well as the page content itself up top. What I want to add is pagination so that a user can flick through all the posts, how do I get this working with custom loops like this?
<?PHP
get_header();
/* Template Name: News */
?>
<div style="padding: 0 20px;">
<div class="box clearfix side" style="margin:10px 0;">
<div style="float:left;width:628px;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?><?php edit_post_link('Edit', ' <small>[', ']</small>'); ?></h2>
<?php the_content('<p>Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<hr />
</div>
<?php endwhile; endif; ?>
<hr />
<?php $blog_query = new WP_Query('posts_per_page=3'); while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if ($blog_query->have_posts()) : ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php else: ?>
<h2>oooops!!!</h2>
<?php endif; ?>
</div>
</div>
</div>
<?PHP
get_footer();
?>
Are you sure you're not re-inventing the wheel a little here? Why not set the number of posts to display in the admin, then use WP's native paging for the blog?
Turns out you have to do something like this:
<?php $temp = $wp_query; $wp_query= null; ?>
<?php $wp_query = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged)); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php $wp_query = null; $wp_query = $temp; ?>

Resources