Wordpress next/prev post on single custom post page? - wordpress

So I've got a custom post type, all working fine.
Goes to single-portfolio, but it won't paginate.
I can't, no matter what I try get pagination to work on the single page.
Here's my code.
<?php get_header(); ?>
<div class="main-content">
<div class="portfoliopost">
<div class="col-full">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="port-left-single">
<h2><?php the_title(); ?></h2>
<div class="projecttype">
<ul>
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<li>' .$tag->name. '</li>';
}
}
?>
</ul>
</div>
<?php the_field('main_portfolio_meta'); ?>
</div> <!-- end div port-left-single -->
<div class="port-right-single">
<?php the_content(); ?>
</div>
<div style="clear:both;"></div>
</div> <!-- end div post-class -->
<div class="navigation">
<div class="next-posts"><?php next_posts_link('Older Posts') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Posts') ?></div>
</div>
<?php endwhile; endif; ?>
</div> <!-- end div col-full -->
</div> <!-- end div portfolipost -->
<div style="clear:both;"></div>
</div> <!-- end div main content -->
<?php get_footer(); ?>
It's inside the loop, so what gives?

Related

can't get wp-pagenavi to work on a custom page on my wordpress site

I am using wp_pagenavi and i works fantastic on the homepage but on any of the custom pages it will show it has many pages but when i click next or page two the url changes like it should but nothing else change.
Below is the wordpress page template that i am using for all the custom pages.
<?php
/*
Template Name: Pages
*/
?>
<?php get_header(); ?>
<?php get_header(); ?>
<div class="home fix">
<div class="main">
<div class="fix">
<?php query_posts('category_name='.get_the_title().'&post_status=publish');?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<!-- thumbnail wrapper -->
<div class="thumb main">
<!-- 235150image-covers -->
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" alt="" height="150" width="235"/>
<!-- 235150image end -->
<!-- thumbanil title -->
<div class="thumb-title">
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title() ?>
<?php comments_number('{0}', '{1}', '{%}' );?>
</a></h2>
</div>
<!-- thumbanil title end -->
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="post single">
<h2>No matching results</h2>
<div class="entry">
<p>You seem to have found a mis-linked page or search query with no associated or related results.</p>
</div>
</div>
<?php endif; ?>
<!-- adsense -->
<!-- adsense end -->
<!-- page navi -->
<div class="pagenavi">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi('', '', '', '', 4, false);}
$wp_query = null; $wp_query = $temp; ?>
</div>
<!-- page navi end -->
</div>
</div>
<div class="sidebarwrapper">
<?php include (TEMPLATEPATH . '/left.php'); ?>
<?php include (TEMPLATEPATH . '/right.php'); ?>
</div>
</div>
<?php include (TEMPLATEPATH . '/ancillary.php'); ?>
<?php get_footer(); ?>
Here I see you have use get_header() function two time.

Is it possible to split "Custom Post Types" in WordPress?

Why does <!--nextpage--> work on pages, but not on Custom Post Types?
Here is the code of the single-custom_type.php file.. I added the "<?php wp_link_pages(); ?>" by myself. I hoped that would work, but it doesn't. There is nothing more to say actually.
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<div id="main" class="eightcol first clearfix" role="main">
<?php include(TEMPLATEPATH . '/template-logo.php'); ?>
<div class="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
<header class="article-header">
<h2 class="h2"><?php the_title(); ?></h2>
</header> <!-- end article header -->
<section class="entry-content clearfix">
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title(); ?>">
<?php the_post_thumbnail(array(200,200), array("class" => "alignleft post_thumbnail")); ?>
</a>
<?php } ?>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<hr>
</section> <!-- end article section -->
<footer class="article-footer">
<p class="tags"><?php the_tags('<span class="tags-title">Tags:</span> ', ', ', ''); ?></p>
</footer> <!-- end article footer -->
<?php // comments_template(); // uncomment if you want to use them ?>
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found" class="hentry clearfix">
<header class="article-header">
<h1><?php _e("Oops, Post Not Found!", "bonestheme"); ?></h1>
</header>
<section class="entry-content">
<p><?php _e("Uh Oh. Something is missing. Try double checking things.", "bonestheme"); ?></p>
</section>
<footer class="article-footer">
<p><?php _e("This is the error message in the single-custom_type.php template.", "bonestheme"); ?></p>
</footer>
</article>
<?php endif; ?>
[...]

Simplify while loop containing posts code in wordpress

The code below should display the content of the page followed by certain page content.
<!-- Section -->
<section>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- Article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- Posts for homepage -->
<?php
if ( is_front_page() ) { ?>
<?php the_content(); ?>
<!-- Show page content according to page ID -->
<div class="title-home clearfix">
<div class="four title-home-text">Services Spotlight</div>
<div class="four title-home-text" style="margin-left: 115px;">Industry Expertise</div>
<div class="four title-home-text" style="margin-left: 125px;">Features & Benefits</div>
</div>
<div class="four-wrapper clearfix">
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=40');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=41');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php
query_posts('page_id=42');
while (have_posts()): the_post();
the_content();
endwhile;
?>
</div>
read more
</div>
<div class="four-container">
<div class="four-col line">
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-3')) ?>
</div>
</div>
</div>
<?php
}
else {
?>
<h1><?php the_title(); ?> </h1>
<?php the_content(); ?>
<?php } ?>
<!-- end post homepage -->
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /Article -->
<?php endwhile; ?>
<?php else: ?>
<!-- Article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /Article -->
<?php endif; ?>
</section>
<!-- /Section -->
<?php get_footer(); ?>
However, it displays the last query as loop.
Output Code:
<article id="post-6" class="post-6 page type-page status-publish hentry">
<article id="post-42" class="post-42 page type-page status-publish hentry">
post-42 should not be displayed in the article.
Also, I know the code is not simplified for using while loop. I want to fix the article problem and simplify this code.
The codex advises against using query_posts for secondary loops as per Codex Query Posts Page
It looks like you are stomping on the main loop (article) since query_posts alters the main loop. If you want to use query_posts it is recommended that you call wp_reset_query() when done. The preferred method is to use WP_query().

Wordpress - jetpack infinite scroll not working

So I've added them support for infinite scroll in my functions.php like so
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'footer' => 'page',
'posts_per_page' => 4
) );
Here's my template and loop, I added an arbitrary div with the id of 'content' just because jetpack apparently needs the containing div of your posts to be an ID, yet the infinite scroll still doesn't work.
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<div class="main-content">
<div class="content-left">
<div id="content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=&paged=' . $paged);
?>
<?php if (have_posts()) : while ( have_posts()) : the_post(); ?>
<div <?php post_class('clearfix') ?> id="post-<?php the_ID(); ?>">
<div class="entrywrapper">
<div class="entry">
<div class="bordertop">
<h2><?php the_title(); ?></h2>
</div> <!-- end div bordertop -->
<div class="aligncenter grey">
<?php the_time('M jS, Y') ?>
</div>
<div class="meta">
<span>Posted in :<?php the_category($separator = ' / '); ?></span>
<div class="clearfix"></div>
</div> <!-- end div meta -->
<?php global $more; $more = 0; ?>
<div class="figure">
<?php the_post_thumbnail(); ?>
</div> <!-- end div figure //centers thumbnail -->
<p class="firstparaph"> <?php the_field('main_post_meta'); ?></p>
<?php the_content('Continue Reading >'); ?>
<div class="centerm">
<?php comments_popup_link('No Comments', '1 Comment', '% Comments', 'comments-link', ''); ?>
</div>
<div class="postbreaker">* * *</div> <!-- end div entrybreaker -->
</div> <!-- end div entry -->
<div style="clear:both"></div>
</div> <!-- end div entrywrapper -->
<div style="clear:both"></div>
</div> <!-- end div post -->
<?php endwhile; endif; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('Older Posts') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Posts') ?></div>
</div>
</div> <!-- end div ID content -->
</div> <!-- end div content-left -->
<div class="content-right">
<?php get_sidebar(); ?>
</div> <!-- end div content-right -->
<div style="clear:both;"></div>
</div> <!-- end div main-content -->
<?php get_footer(); ?>
Maybe try this:
In functions.php
function get_post_content() {
?>
<div <?php post_class('clearfix') ?> id="post-<?php the_ID(); ?>">
<div class="entrywrapper">
<div class="entry">
<div class="bordertop">
<h2><?php the_title(); ?></h2>
</div> <!-- end div bordertop -->
<div class="aligncenter grey">
<?php the_time('M jS, Y') ?>
</div>
<div class="meta">
<span>Posted in :<?php the_category($separator = ' / '); ?></span>
<div class="clearfix"></div>
</div> <!-- end div meta -->
<?php global $more; $more = 0; ?>
<div class="figure">
<?php the_post_thumbnail(); ?>
</div> <!-- end div figure //centers thumbnail -->
<p class="firstparaph"> <?php the_field('main_post_meta'); ?></p>
<?php the_content('Continue Reading >'); ?>
<div class="centerm">
<?php comments_popup_link('No Comments', '1 Comment', '% Comments', 'comments-link', ''); ?>
</div>
<div class="postbreaker">* * *</div> <!-- end div entrybreaker -->
</div> <!-- end div entry -->
<div style="clear:both"></div>
</div> <!-- end div entrywrapper -->
<div style="clear:both"></div>
</div> <!-- end div post -->
<?php
}
Then in your blog loop file:
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<div class="main-content">
<div class="content-left">
<div id="content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=&paged=' . $paged);
?>
<?php if (have_posts()) : while ( have_posts()) : the_post(); ?>
<!-- MY EDIT IS HERE -->
get_post_content();
<?php endwhile; endif; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('Older Posts') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Posts') ?></div>
</div>
</div> <!-- end div ID content -->
</div> <!-- end div content-left -->
<div class="content-right">
<?php get_sidebar(); ?>
</div> <!-- end div content-right -->
<div style="clear:both;"></div>
</div> <!-- end div main-content -->
<?php get_footer(); ?>

Setting content for multiple pages in wordpress

Hi What i'm trying to do is in the page.php file set up a bunch of if statements for each page for example if page == aboutus display the about us content and so on. at the moment no matter what page i'm on it's displaying everything in the page.php file i'm sure its just something with the way i have written it. does anyone know what i'm doing wrong?
heres what i have so far
<?php get_head(); ?>
<?php is_page($page); ?>
<?php is_page('about-us'); ?> {
<div id="container">
<?php get_header(); ?>
<?php get_banner(); ?>
<div class=" center content" role="main">
<div id="posts">
<span class="title">About Us</span>
<div class="msghead">
<?php query_posts('cat=7&showposts=1&orderby=date'); while (have_posts()) : the_post(); the_content();
endwhile;?>
</div>
</div>
<div id="sidebardiv">
<?php get_sidebar(); ?> </div>
<div class="clear"> </div>
</div>
</div>
<?php get_footer(); ?>
</div>
}
<?php is_page('classes'); ?> {
<div id="container">
<?php get_header(); ?>
<?php get_banner(); ?>
<div class=" center content" role="main">
<div id="posts">
<span class="title">Classes</span>
<div class="msghead">
<?php query_posts('cat=7&showposts=1&orderby=date'); while (have_posts()) : the_post(); the_content();
endwhile;?>
</div>
</div>
<div id="sidebardiv">
<?php get_sidebar(); ?> </div>
<div class="clear"> </div>
</div>
</div>
<?php get_footer(); ?>
</div>
}
You are not actually checking the page, you are just running the is_page() function, then displaying the content.
Additionally, when you use The Loop, you should first check that there are posts to display, to avoid errors.
And just as a tip - if the only difference in the pages is the posts that are shown, you can set your arguments before the loop, that way you can cut out quite a lot of your code. Here is a link to a Pastebin with an example of that method, taking the below. Furthermore, if the template is page.php, then the Page that you are viewing is already in the Loop, so you can make use of that to show the Page title. This is untested, but should get you started.
<?php get_head(); ?>
<?php if(is_page('about-us')) : ?>
<div id="container">
<?php get_header(); ?>
<?php get_banner(); ?>
<div class=" center content" role="main">
<div id="posts">
<span class="title">About Us</span>
<div class="msghead">
<?php
query_posts('cat=7&showposts=1&orderby=date');
if(have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile;
endif;
?>
</div>
</div>
<div id="sidebardiv">
<?php get_sidebar(); ?> </div>
<div class="clear"> </div>
</div>
</div>
<?php get_footer(); ?>
</div>
<?php elseif(is_page('classes')) : ?>
<div id="container">
<?php get_header(); ?>
<?php get_banner(); ?>
<div class=" center content" role="main">
<div id="posts">
<span class="title">Classes</span>
<div class="msghead">
<?php
query_posts('cat=7&showposts=1&orderby=date');
if(have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile;
endif;
?>
</div>
</div>
<div id="sidebardiv">
<?php get_sidebar(); ?> </div>
<div class="clear"> </div>
</div>
</div>
<?php get_footer(); ?>
</div>
<?php endif; ?>
An easier approach will be to use is_page('about-us') to check your current page.
Codex: http://codex.wordpress.org/Function_Reference/is_page
You're missing an if statement.
e.g.
<?php if( is_page('about-us') ): ?>
<p>about-us page here</p>
<?php elseif( is_page('classes') ): ?>
<p>classes page here</p>
<?php endif; ?>
A more straightforward way is to create new templates for page-about-us.php and page-classes.php

Resources