Add pagination to this Wordpress Home - php

I Guys! I'm working on a pagination for this theme homepage. The original code is:
<?php
/**
Blog
**/
$display_count = get_theme_mod('wpex_home_blog_count', '30');
$wpex_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $display_count,
'no_found_rows' => true,
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<?php
// Display post meta details
wpex_post_meta() ;?>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
What I did is, I changed it to
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=4' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date">
<?php _e('Posted on','wpex'); ?>
<span class="meta-date-text"><?php echo get_the_date(); ?></span>
</li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
</div>
<?php wp_pagenavi();?>
<?php wp_reset_postdata(); ?>
</article>
This seems to work on the first page, but when i go to page 2, it gives an copy after copy after copy of the whole page, like an infinate page one. That's not how it should work.
Any ideas what goes wrong here? Does this make any sense to you?
EDIT:
I tried the following. Right now the first page looks good, but when i press the second page on the pagination, it outputs the same as the first.
<?php
$args = array(
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),
'posts_per_page' => 4
);
query_posts($args);
?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date"><?php _e('Posted on','wpex'); ?> <span class="meta-date-text"><?php echo get_the_date(); ?></span> </li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
<?php wp_pagenavi();?>
</div><!-- #homepage-portfolio -->
<?php endif; ?>
<?php wp_reset_query(); ?>
</article><!-- #post -->
<?php endwhile; ?>
Whole original code:
<div id="primary" class="content-area clr">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article class="homepage-wrap clr">
<?php
/**
Post Content
**/ ?>
<?php if ( get_the_content() !== '' ) { ?>
<div id="homepage-content" class="entry clr">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php } ?>
<?php
/**
Features
**/
$wpex_query = new WP_Query(
array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'features',
'posts_per_page' => '-1',
'no_found_rows' => true,
)
);
if ( $wpex_query->posts ) { ?>
<div id="homepage-features" class="clr">
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-features', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-features -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Portfolio
**/
$display_count = get_theme_mod('wpex_home_portfolio_count', '8');
$wpex_query = new WP_Query(
array(
'post_type' => 'portfolio',
'posts_per_page' => $display_count,
'no_found_rows' => true,
'tax_query' => wpex_home_portfolio_taxonomy(),
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-portfolio" class="clr">
<h2 class="heading"><span><?php _e( 'Recent Work', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-portfolio', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Blog
**/
$display_count = get_theme_mod('wpex_home_blog_count', '30');
$wpex_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $display_count,
'no_found_rows' => true,
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<?php
// Display post meta details
wpex_post_meta() ;?>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->

Try declaring $paged outside, and call this in the query_posts
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 4
);
query_posts($args . '&paged=' . $paged);

I might have found an answer for this myself, apparently it's different when you use pagination on the frontpage. I used this and it seems to be working!:
if( is_front_page() ){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
}

Related

Wrapping a div around the results of a word press loop but excluding the first 2

I have a loop for a custom post type. I'm bringing back a block of title, image and content for each post. I want to apply slick slider to the results to create a slick carousel, but I don;t want to include the first two results of the loop - so I'd need to create a parent div to the results but only start that div after the first two results.
I've trialed ways of querying the results on a loop count to apply a class to only the first two results, but this doesn't really achieve what I'm after.
<div class="wrapper_for_news_items">
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'news',
'order' => 'DESC'
));
if( $posts ): ?>
<?php $post = $posts[0]; $c=0; ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<div class="treatment_block news_block <?php $c++; if($c == 1) { echo ' featured'; } elseif($c == 2) { echo ' featured'; } ?>">
<h2 class="block_title above"> <?php the_title( '' ); ?></h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below"> <?php the_title( '' ); ?></h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div> <!-- treatment news block wrapper -->
You could just create 2 loops.
Use the first for the featured output and the second for the carousel.
<div class="wrapper_for_news_items">
<?php
$args_with_two_posts = array(
'posts_per_page' => 2,
'post_type' => 'news',
'order' => 'DESC'
);
$query_with_two_posts = new WP_Query( $args_with_two_posts );
if( $query_with_two_posts->have_posts ) :
while ( $query_with_two_posts->have_posts ) : $query_with_two_posts->the_posts; ?>
<div class="treatment_block news_block featured">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of 2 post initial news loop -->
</div>
<!-- treatment news block wrapper -->
<?php
// Start your second loop containing the slickslider content
?>
<div class="wrapper_for_news_carousel_items">
<?php
$args_with_all_posts = array(
'posts_per_page' => -1,
'offset' => 2 // Offset the 2 initial posts
'post_type' => 'news',
'order' => 'DESC'
);
$query_with_two_posts = new WP_Query( $args_with_all_posts );
if( $args_with_all_posts->have_posts ) :
while ( $args_with_all_posts->have_posts ) : $args_with_all_posts->the_posts; ?>
<div class="treatment_block news_block">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div>
<!-- treatment news carousel items -->
Or you could count the posts in the loop and asign a wrapper before the third post and after the last post to create the carousel.
<div class="wrapper_for_news_items">
<?php
$args_with_two_posts = array(
'posts_per_page' => 2,
'post_type' => 'news',
'order' => 'DESC'
);
$query = new WP_Query( $args_with_two_posts );
$counter = 1; // Set the counter
if( $query->have_posts ) :
while ( $query->have_posts ) : $query->the_posts;
if ( $count == 3 ) { echo '<div class="slick-slider">'; };
?>
<div class="treatment_block news_block">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php
$counter++; // Add +1 every loop
if (($query->current_post +1) == ($query->post_count)) {
echo '</div>'; // This is the last post
}
endwhile;
?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div>
<!-- treatment news block wrapper -->

Pagination error in custom taxonomy template

I created a custom post type called "library", with its "documentation" taxonomy; The problem occurs in the pagination of the taxonomy template (taxonomy-documentation.php).
I have determined a number of "18" posts per page, for the number of posts there should be "7" pages, but I list "16" pages, the pages from "8" to "16" are empty.
The url of archive for the taxonomy is: Documentation Archive
The template loop is as follows:
<?php
$term = $wp_query->queried_object;
$getterm = $term->slug; // get current slug (E.g. winter2015)
$args = (array(
'post_type' => 'library',
'showposts' => 18,
'paged'=>$paged,
'tax_query' => array(
array(
'taxonomy' => 'documentation',
'field' => 'slug',
'terms' => $getterm
),
),
) );
$query = new wp_query( $args );
if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?>
<?php setPostViews(get_the_ID()); ?>
<div class="col-md-2">
<?php if ( get_post_meta( get_the_ID(), 'download_image', true ) ) : ?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php get_the_title(); ?>">
<?php
$postID = $post->ID;
$imageURI = get_post_meta($postID, 'download_image', true);
$attachmentID = pn_get_attachment_id_from_url ($imageURI);
$imagearray = wp_get_attachment_image_src( $attachmentID, 'full');
$imageURI = $imagearray[0];
$thumbarray = wp_get_attachment_image_src( $attachmentID, 'library-thumbnail');
$thumb_imageURI = $thumbarray[0];
echo "<img class='document-thumbnail' src='". $thumb_imageURI . "' alt='". get_the_title() ."' />";
?>
</a>
<?php endif; ?>
<a class="document-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 40, '...'); ?></a><br />
<span><?php echo __('Published by', 'cyberdocentes'); ?> <a class="author-link" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a></span>
</div>
<?php endwhile; rewind_posts(); ?>
<div class="clear"></div>
<div id="pagination">
<?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('Next posts','cyberdocentes')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Previous posts','cyberdocentes')); ?>
</div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
<?php else : ?>
<?php endif; ?>
<?php flush(); ?>
Solved code:
<div class="documents-list">
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'documentation' ) );
global $wp_query;
query_posts( array_merge( $wp_query->query, array( 'posts_per_page' => 18 ) ) );
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
//CODE OF THE ARTICLES HERE
<?php endwhile; rewind_posts(); ?>
<?php endif; ?>
<div class="clear"></div>
<div id="pagination">
<?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('Next posts','cyberdocentes')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Previous posts','cyberdocentes')); ?>
</div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
<?php flush(); ?>
</div>

WordPress pagination doens't work on home

I created a WordPress template file with latest posts and pagination. But when I set this page as the home page, the pagination wont work and it'll display the first page. As a standalone page it does work. Strange! Any thoughts about this?
<?php get_header(); ?>
<div id="primary" class="content-area clr">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article class="homepage-wrap clr">
<?php
/**
Post Content
**/ ?>
<?php if ( get_the_content() !== '' ) { ?>
<div id="homepage-content" class="entry clr">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php } ?>
<?php
/**
Features
**/
$wpex_query = new WP_Query(
array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'features',
'posts_per_page' => '-1',
'no_found_rows' => true,
)
);
if ( $wpex_query->posts ) { ?>
<div id="homepage-features" class="clr">
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-features', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-features -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Portfolio
**/
$display_count = get_theme_mod('wpex_home_portfolio_count', '8');
$wpex_query = new WP_Query(
array(
'post_type' => 'portfolio',
'posts_per_page' => $display_count,
'no_found_rows' => true,
'tax_query' => wpex_home_portfolio_taxonomy(),
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-portfolio" class="clr">
<h2 class="heading"><span><?php _e( 'Recent Work', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-portfolio', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
$args = array(
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),
'posts_per_page' => 4
);
query_posts($args);
?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date"><?php _e('Posted on','wpex'); ?> <span class="meta-date-text"><?php echo get_the_date(); ?></span> </li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
<?php wp_pagenavi();?>
</div><!-- #homepage-portfolio -->
<?php wp_reset_query(); ?>
<?php endif; ?>
</article><!-- #post -->
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
I might have found an answer for this myself, apparently it's different when you use pagination on the frontpage. I used this and it seems to be working!:
if( is_front_page() ){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
}

the_content(); not showing in images.php

I am having problem getting the_content(); on image.php or attachment.php, the_content(); it's showing in single.php but no in imaage.php, I tried to edit the code but I got nothing,
<div class="content section-inner">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="posts">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="content-inner">
<div class="featured-media">
<?php $imageArray = wp_get_attachment_image_src($post->ID, 'full', false); ?>
<a href="<?php echo esc_url( $imageArray[0] ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
<?php echo wp_get_attachment_image( $post->ID, 'post-image' ); ?></a>
</div> <!-- /featured-media -->
<div class="post-header">
<h2 class="post-title"><?php echo basename(get_attached_file( $post->ID )); ?></h2>
<div class="post-meta">
<span><?php _e('Uploaded', 'lingonberry'); echo ' '; the_time(get_option('date_format')); ?></span>
<span class="date-sep">/</span>
<span><?php _e('Width:', 'lingonberry'); echo ' ' . $imageArray[1] . ' px'; // 1 is the width ?></span>
<span class="date-sep">/</span>
<span><?php _e('Height:', 'lingonberry'); echo ' ' . $imageArray[2] . ' px'; // 2 is the height ?></span>
</div>
</div> <!-- /post-header -->
<?php if ( ! empty( $post->post_excerpt ) ) : ?>
<div class="post-content">
<?php the_excerpt(); ?>
</div> <!-- /post-content -->
<?php endif; ?>
</div> <!-- /content-inner -->
<div class="post-nav">
<?php
/**
* Grab the IDs of all the image attachments in a gallery so we can get the URL of the next adjacent image in a gallery,
* or the first image (if we're looking at the last image in a gallery), or, in a gallery of one, just the link to that image file
*/
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
foreach ( $attachments as $k => $attachment ) :
if ( $attachment->ID == $post->ID )
break;
endforeach;
$l = $k - 1;
$k++;
if ( isset( $attachments[ $k ] ) ) :
// get the URL of the next image attachment
$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
$prev_attachment_url = get_attachment_link( $attachments[ $l ]->ID );
else :
// or get the URL of the first image attachment
$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
endif;
?>
<?php _e('« Previous<span> attachment</span>', 'lingonberry'); ?>
<?php _e('Next<span> attachment</span> »', 'lingonberry'); ?>
<div class="clear"></div>
</div> <!-- /post-nav -->
<?php comments_template( '', true ); ?>
<?php endwhile; else: ?>
<p><?php _e("We couldn't find any posts that matched your query. Please try again.", "lingonberry"); ?></p>
<?php endif; ?>
</div> <!-- /post -->
</div> <!-- /posts -->
I need help on this
Your code is bit of a mystery but if it looks like this
<?php if ( ! empty( $post->post_excerpt ) ) : ?>
<div class="post-content">
<?php the_excerpt(); ?>
<?php the_content(); ?>
</div> <!-- /post-content -->
<?php endif; ?>
the commands the_excerpt() and the_content() will only execute when there is an excerpt present. The if-statement says "if excerpt is not empty then execute the following code.
Try this:
<div class="post-content">
<?php if ( ! empty( $post->post_excerpt ) ) : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php the_content(); ?>
</div> <!-- /post-content -->
There is a shorter way of writing this but this way it shows the change better.

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;
?>

Categories