I am a new of wordpress. I have a problem with pagination when I click to the next post it shows "not found". I installed the plugin wp pagenavi, and I put code in my blog post . It shows the pagination, but I have a problem with the link to the next post. Example when I click to the next post it is show
Something went Wrong!
404
-->
You can see at: http://westecmedia.com/events/
And this is my code in event-page.php:
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; else: endif; ?>
<?php wp_pagenavi(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please ?
Maybe you missed the object here. You can try the code below:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
'category_name'=>get_the_title(),
'post_status'=> array('publish', 'future')
);
query_posts($args);
instead:
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
Related
Hi all I am a new of wordpress I have problame with pagination, I used plugin Wp-pagnavi ,When I click link to page 2 it same as page 1,How to to fix it.
You can see it at
http://westecmedia.com/?page_id=758
And this my code in page-event.php
<?php
/*
* Template Name: Page - Events Page
*/
?>
<?php get_header(); ?>
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; endif; ?>
<?php wp_pagenavi(); ?>
<?php wp_reset_query(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please :(
Include paged, documentation: https://codex.wordpress.org/Pagination
<?php
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
endwhile;
wp_pagenavi();
wp_reset_query(); // Restore global post data
?>
Also don't use query_posts to fetch data in WordPress, consider using https://codex.wordpress.org/Class_Reference/WP_Query.
Please ask WordPress related question here: http://wordpress.stackexchange.com
I hope this helps.
I am creating a custom homepage template in which I am trying to show posts with navigation.
Here is what I have followed.
Created a file homepage.php and gave the template name as "HomePage".
Created a page "Home" from dashboard and assigned this template "HomePage".
Then from settings > reading, chosen static front page "Home".
Here is my code for querying posts.
<div class="posts-container">
<?php query_posts('post_type=post&posts_per_page=2&post_status=publish&paged='. get_query_var('paged')); ?>
<?php if(have_posts()): ?>
<?php while (have_posts() ) : the_post(); ?>
<div class="post">
<h4 class="entry-title"><?php the_title(); ?></h4>
</div>
<?php endwhile; // end of the loop. ?>
</div>
<div class="pagination-nav">
<div class="alignleft"><?php next_posts_link(__('Next »','example')); ?></div>
<div class="alignright"><?php previous_posts_link(__('« Previous','example')); ?></div>
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
Now, on clicking the links generated by pagination functions, I am getting redirected to the page where I was first. While the URL gets updated like
http://localhost/mysite/?paged=2
Lets say if there are 4 posts (post 1, post 2, post 3, post 4) that and the recent ones are post 4 and post 3 respectively, then I cannot get to post 1 and post 2. Both of the pages
http://localhost/mysite
http://localhost/mysite/?paged=2
show me only the post 4 and post 3. What can I do to solve this?
For a static front page you need to check for the page var too, in this way:
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('...&paged=' . $paged);
This was the solution that worked for me. I had to re-write the query and have used WP Query this time.
<?php
global $wp_query, $paged;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_args = array (
'post_type' => 'post',
'post_status'=>'publish',
'posts_per_page' => 4, //for testing purposes
'paged' => $paged,
);
$wp_query = new WP_Query($query_args);
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts()) :
$wp_query->the_post();
?>
<div class="post">
<?php if ( has_post_thumbnail() ) { ?>
<a class="entry-image" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); } ?>
</a>
<h4 class="entry-title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h4>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<div class="pagination-nav">
<div class="alignleft">
<?php next_posts_link(__('Oudere artikelen')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Newer')); ?>
</div>
</div>
</div>
<!-- /posts-container -->
<?php endif; ?>
<?php wp_reset_postdata(); ?>
And Whola!, this one worked.
Might be useful for someone else.
I use the normal pagination method in wordpress
<?php $i = 1 ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => "2", 'paged' => $paged, 'cat' => 26 );
query_posts($args);
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="art_1">
<h5><?php echo $i ?>. <?php the_title(); ?></h5>
<?php $i++; ?>
</div>
<?php endwhile; ?>
<div class="er">
<?php next_posts_link(); ?>
</div>
<div class="err">
<?php previous_posts_link(); ?>
It works fine but the problem is this pagination I use for listing out articles in a particular category ,now I have another category of articles in same page which needs pagination too.pagination of 1st should no affect the other and vice versa. Can anyone suggest me what should I do?
Use this hook after pagination..
<?php wp_reset_query(); ?>
Hello Im new to Wordpress , But I styled some elements, and had the recent posts in them . My question, can I have them for 5 posts repeated after each other ? thanks :)
<div id="main_content">
<h2>Latest Products</h2>
<div class="latest_products">
<div class="group">
<?php query_posts("post_per_page=1"); the_post(); ?>
<h3 class="stick_note"><?php the_title(); ?></h3>
<div class="pro_content">
<div class="product_thumbnail"> <?php the_post_thumbnail('thumbnail'); ?> </div>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div> <!-- END LATEST PRODUCTS -->
</div> <!-- END Main Content -->
You forgot to implement The Loop (click for detailed info).
A full Wordpress loop is as follows:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...render your post here, it will keep repeating...
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
Since you don't have an actual loop implemented it can only render 1 post.
You can use:
get_archives('postbypost', 5);
OR
query_posts("showposts=5");
This help you? Be more specific in your question.
You can find the answer in documentation of wordpress:
http://codex.wordpress.org/Template_Tags/get_posts
http://codex.wordpress.org/Template_Tags/query_posts
http://codex.wordpress.org/Template_Tags/wp_get_archives
EDIT:
$args = array('numberposts' => 5, 'order'=> 'ASC');
$postslist = get_posts( $args );
EDIT2:
You can do:
$args = array('numberposts' => 5, 'order'=> 'ASC');
$postslist = get_posts( $args );
foreach( $postslist as $post ) : setup_postdata($post); ?>
<li>
<?php the_title(); ?>
</li>
<?php endforeach; ?>
First time creating/implementing custom post types in Thesis, not first time using custom post types.
I used the Reed Write plugin to create the custom post types. The site is using Thesis 1.8.5.
On the following page (http://www.snyderleadership.com/press-releases/) I have the main content getting dropped in with the contents of the custom post type after it.
I used the custom_functions.php file to create a custom page template and call the db for the contents of the custom post type. Here is my code:
/* CUSTOM PRESS RELEASE TEMPLATE - ADDED by BRETT ATKIN */
function press_releases_page() {
if (is_page('press-releases') || is_page('583')) { ?>
<div id="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post_box">
<div class="headline_area"><h1><?php the_title(); ?></h1></div>
<div class="format_text">
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif ?>
<?php
$original_query = $wp_query;
$wp_query = null;
$args = array (
'post_type' => 'press-release',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$wp_query = new WP_Query($args);
?>
<div id="press-releases">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="press-wrapper">
<div id="press-image">
<?php echo wp_get_attachment_image(get_post_meta($post->ID, 'release_image', true)); ?>
</div><!-- end press-image div -->
<div id="press-information">
<p class="press-date"><?php echo get_post_meta($post->ID, 'release_date', true); ?></p>
<p class="press-link"><?php echo get_post_meta($post->ID, 'release_title', true); ?></p>
<p class="press-author"><?php echo get_post_meta($post->ID, 'release_author', true); ?></p>
</div><!-- end press-information div -->
<div style="clear:both;"></div>
</div><!-- end press-wrapper div -->
<?php endwhile; endif; wp_reset_postdata(); ?>
</div><!-- end press-releases div -->
</div>
</div>
</div><!-- end content -->
<?php echo thesis_sidebars(); ?>
<?php } }
add_action('thesis_hook_custom_template', 'press_releases_page');
It seems like everything is working correctly, just not pulling in the data for the custom post type.
Having done this on other sites (using custom themes), I'm not sure if I did something wrong here or if it is a Thesis issue.
Any help would be great.
Thanks
Brett
Here is the final working code. Thanks to the help from of a local WP Guru friend and maiorano84. We didn't figure out the cause, but we did fine a solution.
function press_releases_page() {
if (is_page('press-releases') || is_page('583')) { ?>
<div id="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post_box">
<div class="headline_area"><h1><?php the_title(); ?></h1></div>
<div class="format_text">
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif ?>
<?php
$original_query = $wp_query;
$wp_query = null;
$args = array (
'post_type' => 'press-release',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$wp_query = new WP_Query($args);
?>
<div id="press-releases">
<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php $results = get_post_custom(); ?>
<div id="press-wrapper">
<div id="press-image"><?php echo wp_get_attachment_image($results['release_image'][0] ); ?></div><!-- end press-image div -->
<div id="press-information">
<p class="press-date"><?php echo $results['release_date'][0] ?></p>
<p class="press-link"><?php echo $results['release_title'][0] ?></p>
<p class="press-author"><?php echo $results['release_author'][0] ?></p>
</div><!-- end press-information div -->
<div style="clear:both;"></div>
</div><!-- end press-wrapper div -->
<?php endwhile; endif; wp_reset_query(); wp_reset_postdata(); ?>
</div><!-- end press-releases div -->
</div>
</div>
</div><!-- end content -->
<?php echo thesis_sidebars(); ?>
<?php } }
remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');
add_action('thesis_hook_custom_template', 'press_releases_page');
Try changing this:
<div id="press-releases">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="press-wrapper">
To this:
<div id="press-releases">
<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="press-wrapper">
UPDATE:
The only other thing I can see is that you're not resetting your post data, and that the $wp_query variable is actually a Wordpress Global. Try using the reset functions and changing your WP_Query instance name like this:
<?php
wp_reset_query();
wp_reset_postdata();
$args = array (
'post_type' => 'press-release',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query($args);
?>
<div id="press-releases">
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
UPDATE 2:
Now that you have your wrappers being written to your document, you need to normalize your information. Try to avoid using Metadata instead of normal post attributes. I imagine your metadata 'release_image' is a link to an image somewhere on your server:
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<div id="press-wrapper">
<div id="press-image">
<img src="<?php echo get_post_meta(get_the_ID(), 'release_image', true); ?>" />
</div><!-- end press-image div -->
<div id="press-information">
<p class="press-date"><?php echo the_date(); ?></p>
<p class="press-link"><?php the_title(); ?></p>
<p class="press-author"><?php the_author(); ?></p>
</div><!-- end press-information div -->
<div style="clear:both;"></div>
</div><!-- end press-wrapper div -->
<?php endwhile; endif; wp_reset_postdata(); ?>