wp-paginate() showing blank page while navigating to other pages - php

I am using wp-paginate plugin for pagination on my wordpress site. The pagination links are showing fine. The problem is every page shows a blank page.
I am using following code to call pagination. I am new to wordpress so sorry for any mistakes..
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php //twentytwelve_content_nav( 'nav-below' ); ?>
<?php if(function_exists('wp_paginate')) {
wp_paginate();
}
else {
twentytwelve_content_nav( 'nav-below' );
}
?>

You have stared if block but not close it. Enable errors you will get error in php
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php //twentytwelve_content_nav( 'nav-below' ); ?>
<?php if(function_exists('wp_paginate')) {
wp_paginate();
}
else {
twentytwelve_content_nav( 'nav-below' );
}
endif; //<--------------add end if
?>

Finally I found the solution. There was a page named page.php on my server's root folder. I deleted it and problem solved.

Related

Need to exclude first post from Wordpress

I need to exclude first post from wordpress loop on archive.php page. The loop code is this.
<div class="article-container">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'archive' ); ?>
<?php endwhile; ?>
</div>
There are several ways. You can use a counter or boolean variable. This example uses the latter (I don't know what you are using 'global $post_i; $post_i = 1;' for but you could use $post_i as a counter, increment it in the while loop and use a condition, if that was your intention):
<div class="article-container">
<?php global $post_i; $post_i = 1; ?>
<?php $show_post = false; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if($show_post === false): ?>
<?php $show_post = true; ?>
<?php else: ?>
<?php get_template_part( 'content', 'archive' ); ?>
<?php endif; ?>
<?php endwhile; ?>
</div>
Then hook into the 'pre_get_posts' and offset the query by 1. Add this to your functions file:
add_action('pre_get_posts', 'offset_posts_wordpress_archive', 50);
function offset_posts_wordpress_archive($query){
if(!is_admin() && $query->is_archive()){
$query->set('offset', 1);
}
}

WordPress custom theme, Why is my content not showing on page

My pages are not showing any content on them other then the header and footer I think its something to do with the way i am laying out my but don't really know.
index.php and page.php
<?php get_header(); ?>
<?php if( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endif; ?>
<?php get_footer(); ?>
You forgot while statement.
Here's how your code should look:
<?php get_header(); ?>
<?php if( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php get_footer(); ?>

Wordpress loop for static front page template not working

I have a static wordpress front page. I want the code that works on my regular blog template to work on the homepage too.
Currently, it only shows one post. The code in the main index.php is this...
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php wp_pagenavi(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
content.php calls this....
<div class="col-md-4">
<?php the_excerpt(); ?>
</div><!-- /col-md-4 -->
This works great while on the blog page. But i can't get this exact same content on to the static home page. I know I need a different query for homepage but no idea what that is. Any help appreciated!
Your code looks right to me, you can try to reset the loop and query the posts again.
<?php
rewind_posts();
query_posts( $args );
while ( have_posts() ) : the_post();
?>
<!-- Do stuff... -->
<?php endwhile; ?>
global $query_string;
query_posts($query_string.'&post_type=post&posts_per_page=15');
Adding this on top of your code should work. Try it out.

How to import the Wordpress publications into the static page?

I am using in my Wordpress-based site a specific template that has no options display publications, but only static pages. How can I import it to my latest publication?
You can get the latest posts by entering "the Loop" enviroment, the code below is from the Twenty Eleven: Main Index Template by Wordpress
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
you may not want to use twentyeleven_content_nav( 'nav-below' ); nor twentyeleven_content_nav( 'nav-below' ); while using other template (say not based on Twenty Eleven)

How do I exclude sub-pages from a page loop?

This is what I have so far. Unfortunately this grabs ALL my pages' titles and content including sub-pages. I only want to display top-level main pages. How can I do this?
<?php query_posts('post_type=page'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
*Note: I want to display both title and content for the pages. Not just title. Otherwise I would use:
<?php wp_list_pages('depth=1'); ?>
UPDATE: Following konsolenfreddy's advice I was able to loop through my pages properly. However a new problem arose. The content is being striped of its tags. Anyway I can keep them? Here's my new code:
<?php
$pages = get_pages('parent=0');
foreach ($pages as $pagg) {
$option .= $pagg->post_title;
$option .= $pagg->post_content;
echo $option;
}
?>
You can use get_pages() (see http://codex.wordpress.org/Function_Reference/get_pages ), it takes the same arguments as wp_list_pages()
Does this work?
<?php query_posts('post_type=page&post_parent='.$parent);?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>

Categories