<?php
/*
Template Name: Projects
*/
?>
<?php get_header();?>
<section id="content">
<section id="main">
<?php
$loop = new WP_Query(array('post_type' => 'projects', 'posts_per_page' => 4));
$i=1;
while ( $loop->have_posts() ) : $loop->the_post();
?>
<article class="post<?php if($i%2 == 0) { echo ' right'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<section class="entry">
<?php the_excerpt(); ?>
</section>
</article>
<?php
endwhile;
wp_pagenavi();
?>
<section id="map">
<img src="<?php bloginfo('template_url') ?>/images/interactive-map.jpg" alt="Interactive Map" />
</section>
</section>
<?php get_sidebar(); ?>
</section>
<?php get_footer(); ?>
I have pagenavi set up right after the endwhile. It's not working, though. It doesn't even show up in the source. Does anybody know how I can get this to work?
I was having this same problem. If you take out the posts_per_page parameter, the pagenavi will work. You will have to control the posts per page via Settings > Reading instead. I have not found any other work-arounds.
Related
I'm trying to have two things on a Wordpress page: a list of Custom Posts as well as the content of the custom posts. I would like the titles of the Custom Posts to link to the section of the page with the posts' content.
For example:
Item One
Item Two
Item Three
ITEM ONE HEADING
Item One content...
ITEM TWO HEADING
Item two content...
ITEM THREE HEADING
Item three content...
So "Item One" would link to "ITEM ONE HEADING". Here's the code I'm using which shows the Custom Post List as well as the content, but the list items link out to the Custom Post's page.
<ul>
<?php
$query = new WP_Query( array( 'post_type' => array( 'drilling' ) ) );
while ( $query->have_posts() ) : $query->the_post();
echo '<li><a href="';
the_permalink();
echo '">';
the_title();
echo '</a></li>';
endwhile;
?>
</ul>
<?php wp_reset_query(); ?>
and
<?php query_posts( 'post_type=drilling'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<section class="service-middle">
<div class="container">
<div class="service-middle-content sixteen columns">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php echo get_the_title($ID); ?> </h2>
<?php the_content(); ?>
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /article -->
</div> <!--end service-middle-content-->
</div> <!--end container-->
</section> <!--end service-middle-->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
Thanks so much for any help!
-Dan
You want to use HTML Anchors
http://www.w3schools.com/html/html_links.asp
It is worth mentioning that you don't actually need to query the posts twice. You could you the WP get_posts function (https://codex.wordpress.org/Template_Tags/get_posts) to get the posts as an array and then loop through this array to generate a nav and your post contents.
Hope this helps!
<ul>
<?php
$query = new WP_Query( array( 'post_type' => array( 'drilling' ) ) );
while ( $query->have_posts() ) :
$query->the_post();
?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php wp_reset_query(); ?>
<?php query_posts( 'post_type=drilling'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<section class="service-middle">
<div class="container">
<div class="service-middle-content sixteen columns">
<!-- Anchor Tag -->
<a name="post-<?php the_ID(); ?>"></a>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php echo the_title(); ?> </h2>
<?php the_content(); ?>
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /article -->
</div> <!--end service-middle-content-->
</div> <!--end container-->
</section> <!--end service-middle-->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
I have a wordpress site : There is a problem with the pagination.. When I click on 2'nd page it shows up the first one(index page). The other pages are working. Can you help me?
I looked up for errors in the loop but i didn't found anything!
this my index.php code
<?php get_header(); ?>
<div id="content">
<?php if(get_option('freshlife_featured_content_enable') == 'on') { ?>
<div id="featured-content">
<div class="heading">
<span class="heading-text"><?php _e('Featured Articles', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<ul>
<?php
$counter = 1;
query_posts( array(
'showposts' => get_option('freshlife_featured_post_num'),
'tag' => get_option('freshlife_featured_post_tags')
) );
if( have_posts() ) : while( have_posts() ) : the_post();
?>
<li class="featured-<?php echo $counter; ?>"><?php the_post_thumbnail('featured-thumb', array('class' => 'entry-thumb')); ?><span class="entry-date"><abbr title="<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'themejunkie'); ?></abbr></span><h2 class="entry-title"><?php the_title(); ?></h2></li>
<?php $counter++; endwhile; endif; wp_reset_query(); ?>
</ul>
</div> <!-- end #featured-content -->
<?php } ?>
<div class="heading">
<span class="heading-text"><?php _e('All Stories', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include(TEMPLATEPATH. '/includes/templates/loop.php'); ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
<div class="pagination">
<div class="left"><?php previous_posts_link(__('Newer Entries', 'themejunkie')) ?></div>
<div class="right"><?php next_posts_link(__('Older Entries', 'themejunkie')) ?></div>
<div class="clear"></div>
</div> <!-- end .pagination -->
<?php } ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It's hard to say without looking at the WP_Query generated by the requests.
But I do see something that might be causing problems, query_posts alters the main query, that could be messing with the pagination.
Try to use get_posts instead query_posts, so the main loop is not affected.
A more detailed explanation can be found here
I've just begun learning to develop WordPress themes, and I'm developing my first theme, but I have an issue, where the formatting set in the Visual Editor isn't used when displaying a post...
So, my code is as follows:
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<div id="contentWrap">
<div id="content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = array (
'posts_per_page' => 3,
'paged' => $paged,
'cat' => 4
);
query_posts ($query); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="meta">
<em>Posted on:</em> <?php the_time('F jS, Y') ?>
</div>
<div class="entry">
<?php the_content(); ?>
</div>
</article>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2>Not found</h2>
<?php endif; ?>
</div><!-- end content -->
</div><!-- end contentWrap -->
<?php get_footer(); ?>
So the issue is, if I create a post and set some formatting (bold, italics, etc.), the post is still shown as plain text with no formatting except line breaks... I'm guessing the issue is related to how I get the post, but as I'm completely new in WordPress, I haven't been able to find the solution...
What am I missing?
I want to call custom field in single.php template to complete a short code and thus show a menu.
I places the below code but it is not working
<?php echo do_shortcode("[custommenu menu=<?php echo get_post_meta($post->ID, ‘tabmenu’, true); ?>]?>")
Please help
Here's my template file
I saved this as single-default.php and calling it category wise from single.php file
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="content">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="tab-menu"><?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>
</div>
<div class="entry-content">
<?php if(get_option('resizable_integrate_singletop_enable') == 'on') echo (get_option('resizable_integration_single_top')); ?>
<?php the_content(''); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'themejunkie' ), 'after' => '</div>' ) ); ?>
<?php if(get_option('resizable_integrate_singlebottom_enable') == 'on') echo (get_option('resizable_integration_single_bottom')); ?>
<div class="clear"></div>
<?php printf(the_tags(__('<div class="entry-tags"><span>Tags:</span> ','themejunkie'),', ','</div>')); ?>
<?php edit_post_link('('.__('Edit', 'themejunkie').')', '<span class="entry-edit">', '</span>'); ?>
</div><!-- .entry-content -->
</div><!-- #post-<?php the_ID(); ?> -->
<div class="clear"></div>
<div class="entry-bottom">
<div class="clear"></div>
</div><!-- .entry-bottom -->
</div><!-- #content -->
<?php endwhile; else: ?>
<?php endif; ?>
You need to concatenate the inner echo in the shortcode
<?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>
I have the following code on a WordPress page. It basically just grabs 3 posts and displays them as well as the page content itself up top. What I want to add is pagination so that a user can flick through all the posts, how do I get this working with custom loops like this?
<?PHP
get_header();
/* Template Name: News */
?>
<div style="padding: 0 20px;">
<div class="box clearfix side" style="margin:10px 0;">
<div style="float:left;width:628px;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?><?php edit_post_link('Edit', ' <small>[', ']</small>'); ?></h2>
<?php the_content('<p>Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<hr />
</div>
<?php endwhile; endif; ?>
<hr />
<?php $blog_query = new WP_Query('posts_per_page=3'); while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if ($blog_query->have_posts()) : ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php else: ?>
<h2>oooops!!!</h2>
<?php endif; ?>
</div>
</div>
</div>
<?PHP
get_footer();
?>
Are you sure you're not re-inventing the wheel a little here? Why not set the number of posts to display in the admin, then use WP's native paging for the blog?
Turns out you have to do something like this:
<?php $temp = $wp_query; $wp_query= null; ?>
<?php $wp_query = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged)); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php $wp_query = null; $wp_query = $temp; ?>