I'm having a problem with my Wordpress theme. My next_posts_link() only reloads the same page. Here's my code.
<div id="main">
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="utdrag">
<h2><?php the_title(); ?></h2>
<div class="crop"><a href="<?php the_permalink(); ?>">
<?php
if ( get_the_post_thumbnail($post_id) != '' ) {
echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="';
echo catch_that_image();
echo '" alt="Image unavailable" class="crop" />';
echo '</a>';
}
?></a>
</div>
<?php the_excerpt(); ?>
</div>
<?php endwhile; else: endif; ?>
<?php next_posts_link();?><?php previous_posts_link();?>
</div>
I'm using a static page as my front page. As you can see it's only displaying posts that have the same category as the page title: query_posts('category_name='.get_the_title().'&post_status=publish,future');
This is something I want to keep. So does anyone know why it just reloads? Why it isn't changing to the next page?
I figured it out! I'm posting it here in case someone else is having the same problem!
I added this code at the top:
<?php if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
}
elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
}
else { $paged = 1; }
?>
And replaced this:
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
with this:
<?php query_posts('catery_name='.get_the_title().'&showposts=2'.'&paged='.$paged); ?>
For more information, check out this link:
http://wordpress.org/support/topic/front-page-wp-query-pagination-issue-repeating-posts-next_posts_link-help
These two functions does not work on static pages.
From the documentation for wp_next_post_link():
This function does not work with static pages.
However, take a look at this article. It talks about how to create a static front page with dynamic content.
Related
I'm not quite sure where I've gone wrong here. One of my template parts that I'm using for listing a bunch of posts of a certain category doesn't seem to be working.
Here is the code where I'm trying to get a template part named "content-offer.php" to display these posts, but it will not show any.
<?php query_posts('cat=3'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php static $count = 0;
if ($count == "4") { break; }
else { ?>
<?php get_template_part( 'content', 'offer', get_post_format() ); ?>
<?php $count++; } ?>
<?php endwhile;
endif;
wp_reset_query(); ?>
Here's what's actually within the template part file:
<div class="offer-box">
<div class="offer-left">
<?php
if(has_post_thumbnail()) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" height="100%" height="auto" />';
}
?>
</div>
<div class="offer-right">
<h2 class="offer-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<p class="offer-text">
<a href="<?php the_permalink(); ?>">
<?php the_excerpt(); ?>
</a>
</p>
<a href="<?php the_permalink(); ?>">
<div class="offer-cta">Claim now!</div>
</a>
</div>
Take note that all my files are in the root folder of the wordpress theme currently, so it's surely nothing to do with sub directories.
I have another area that displays posts with the same method just fine, so I'm confused as to why this one doesn't work.
If anyone can help me out and point where I've gone wrong it would be greatly appreciated.
So, it looks like I had the "content-offer.php" file in the root wordpress folder, not the theme root folder. Oops.
I've made a custom metabox that if selected makes the post thumbnail the background of the site.
Now I need that this post thumbnail has a link to the post.
< ?php query_posts ('showposts=5$cat=2');
if (have_posts()) : ?>
if ( has_post_thumbnail() && get_post_meta($post->ID, 'dbt_checkbox', true) ) {
the_post_thumbnail('background');
}
else {}
?>
<?php endwhile; endif; ?>
Wordpress documentation provides an example for this exact situation
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
However, I kind of hate opening and closing php tags so lightly. I'll try something to improve this answer.
Edit: got it. Please try this:
if ( has_post_thumbnail() && get_post_meta($post->ID, 'dbt_checkbox', true) ) {
echo '<a href="' . get_permalink( $post->ID ) . '" >';
echo get_the_post_thumbnail( $post->ID, 'background' );
echo '</a>';
}
got another question to ask:
I would like to display post thumbnails with the post title underneath. I have managed to work that out through asking on here, however now I would like to add a function that checks for a thumbnail and if none is available displays a dummy image.
Here is my try, which does display the thumbnail (if there) but not the dummy (if no thumbnail is attached):
<div class="gallery_container_wrapper">
<?php query_posts( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="gallery_image_container">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<div class="gallery_image_thumb">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail'); }
else {
echo
'<img src="http://www.kunstamkasten.de/wp-content/uploads/2014/08/gallery_dummy.jpg" />'
; } ?>
</div>
<div class="gallery_title">
<h2>
<?php the_title(); ?>
</h2>
</div>
</a>
</div>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
What am I doing wrong here?
This code works for me. Yours is virtually identical.
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/sunlit_path_banner.jpg" alt="Sunlit Path" />
<?php endif; ?>
Note: I also cut and pasted your code and tested on my WP install, and it worked fine.
Or... try this alternative to the if condition:
<?php if ( get_the_post_thumbnail( get_the_ID() ) ) {
the_post_thumbnail('thumbnail'); }
else {
echo
'<img src="http://www.kunstamkasten.de/wp-content/uploads/2014/08/gallery_dummy.jpg" />'
; } ?>
I have a custom static frontpage that show recent blogg updates.
But I cant seem to figure out why the pagination doesn't work? I gives me only the link to previous page but when I click the link it just shows the same page but the url changes from
www.homepage.com
to www.homepage.com/page/2
this is my loop.
<?php query_posts('posts_per_page=2&category=blogg'); ?> <?php while (have_posts()) : the_post(); ?>
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) : /* if post has post thumbnail */ ?>
<div class="image"><?php the_post_thumbnail('archive-preview'); ?></div>
<?php endif; ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
<?php endwhile; ?>
<br/>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<?php next_posts_link(__('← Older Entries', 'framework')) ?>
<?php previous_posts_link(__('Newer Entries →', 'framework')) ?>
<?php } ?>
lease use the code it will help you:
<?php
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('posts_per_page=3&paged=' . $paged);
?>
wordpress codex pagination
I am having a problem with the page http://www.believeinstjohn.com/store/
What I'm ultimately trying to accomplish is moving the sidebar to its proper place (right sidebar column). It is showing three missing </div>tags, it is a WordPress site and the page is using a custom template. I cannot figure out where the missing tags are. The template is pulling resources from the rest of the site, and the other pages are just fine. Two of the divs (container & container-2) are located in the header.php, but closing them out there messes up the whole site. I must have missed something in the template, but cannot see it. Here is the PHP for the template
<?php
/**
* Template Name: Products
*
* Selectable from a dropdown menu on the edit page screen.
* #package WordPress
* #subpackage Adventure_Journal
*/
$themeOpts = get_option('ctx-adventurejournal-options');
get_header();
?>
<div class="content" <?php ctx_aj_getlayout(); ?>>
<div id="col-main" style="<?php echo ctx_aj_customwidth('content'); ?>">
<div id="main-content" <?php //ctx_aj_crinkled_paper(); ?>>
<?php
global $wp_query, $post;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$tax = $wp_query->query_vars['product-category'];
query_posts( array ('post_type' => 'products', 'paged' => $paged, 'product-category' => $tax ) );
$loop_counter = 1;
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li class="product <?php if ( $loop_counter == 2 ) { echo "product-last"; } ?>">
<div class="product_wrap">
<?php
$title = get_the_title().' ';
$chars_title = strlen($title);
$title = substr($title,0,28);
$title = substr($title,0,strrpos($title,' '));
if ($chars_title > 28) { $title = $title."..."; }
$excerpt = get_the_excerpt();
if (strlen($excerpt) > 150) {
$excerpt = substr($excerpt,0,strpos($excerpt,' ',80)); } ;
$excerpt = $excerpt.' ...';
if (has_post_thumbnail()) {
echo '<a href="'. get_permalink() .'" class="product-thumb" title="'. the_title_attribute('echo=0') .'">';
the_post_thumbnail( 'Product Thumb', array('title'=>$post_title) );
echo '</a>';
}
?>
<h3 class="entry-title product-title"><?php echo $title; ?></h3>
<div class="product_content">
<?php echo apply_filters('the_excerpt',$excerpt); ?>
</div>
<div class="product_details">
<a class="button" href="<?php the_permalink(); ?>">More Info</a>
</div>
</div>
</li>
<?php if ( $loop_counter == 2 ) {
$loop_counter = 1;
echo '<li class="clear"></li>';
} else {
$loop_counter++;
} ?>
<?php endwhile; else: endif; ?>
<div class="clear"></div>
<?php get_sidebar('store'); ?>
<?php get_footer(); ?>
Where do you close the following tags ?
<div class="content" <?php ctx_aj_getlayout(); ?>>
<div id="col-main" style="<?php echo ctx_aj_customwidth('content'); ?>">
<div id="main-content" <?php //ctx_aj_crinkled_paper(); ?>>