Wordpress: Post has no formatting - wordpress

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?

Related

Pagination don't work in custom page template

I created a custom page template like category.php but I can't get the pagination working.
I just filter post from one category.
Here is my code:
<?php
/* Template Name: News */
?>
<?php get_header(); ?>
<div class="col-lg-9 col-md-8 content">
<div class="box">
<h1 class="title"><?php the_title(); ?></h1>
<div class="box-int">
<article>
<?php // Display blog posts on any page # http://m0n.co/l
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=5' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<br><br>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Old'); ?></div>
<div class="next"><?php previous_posts_link('Newx »'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Old'); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
</article>
</div>
</div>
</div>
<div class="col-lg-3 col-md-4">
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
What's wrong here? I click in Page 2, but the post are always the same.
Your query is a bit of a mess here with some syntax errors as well.showposts died with the dinosaurs, it is long time depreciated. You should use posts_per_page. 'showposts=5' . '&paged='.$paged is also a mess. You query shouls simplify look like this
$args = array(
'posts_per_page' => 5,
'paged' => $paged
);
$query = new WP_Query( $args );
while ($query->have_posts()) : $query->the_post(); ?>
When querying the loop with WP_Query, you need to assign $max_pages parameter to the next_posts_link().
So you would need to change <?php next_posts_link('« Old'); ?> to <?php next_posts_link('« Old', $the_query->max_num_pages ); ?>
Also go and read this question on this subject. If I missed something, this question will most certainly help you out a lot.

WP-PageNavi Issues, Url changes but the posts remain the same?

The issue I am having is I have created a new blog page on its own page template page being called blog.php, I have pulled 5 posts into each page and the first page work great and link to the single posts that they are attached too.
When I try to add wp-pagenavi into my nav-below I run into an issue. What happens is I will click to go the next page and it changes the url, but the posts remain the same as before, when it should be switching them to the next set.
I don't know if you can use wp-pagenavi outside of index.php, but if anyone can let me know what I am doing wrong here and why I continue to get the same posts that would be awesome and greatly appreciated. I have one of my blogs on blog.php and that is the file I am trying to get to work. I have posted the code for it below.
<?php
/**
* Template Name: Blog Page <?php query_posts("posts_per_page=8"); ?>
*/
get_header(); ?>
<div id="content">
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5' ) ); ?>
<?php
//THE LOOP.
if( have_posts() ):
while( have_posts() ):
the_post(); ?>
<article id="post-1" <?php post_class( 'clearfix' ); ?>>
<h2 class="entry-title"> <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<div class="postmeta">
<span class="author"> Posted by: <?php the_author(); ?> </span>
<span class="date"> <?php the_date(); ?> </span>
<span class="num-comments">
<?php comments_number('No comments yet', 'One comment', '% comments'); ?></span>
<span class="categories">
<?php the_category(); ?>
</span>
<span class="tags">
<?php the_tags(); ?>
</span>
</div><!-- end postmeta -->
<?php if( has_post_thumbnail() ): ?>
<div class="thumb">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php
if( is_single() OR is_page() ):
the_content();
else:
the_excerpt();
endif;
?>
</div>
<?php comments_template(); ?>
</article><!-- end post -->
<?php
endwhile;
else: ?>
<h2>Sorry, no posts found</h2>
<?php endif; //END OF LOOP. ?>
<div id="nav-below" class="pagination">
<?php if( function_exists('wp_pagenavi') ):
wp_pagenavi();
else:
?>
<?php next_posts_link( '← Older Posts' ); ?>
<?php previous_posts_link( 'Newer Posts →' ); ?>
<?php endif; ?>
</div><!-- end #nav-below -->
</div><!-- end content -->
<?php get_footer(); ?>
After <div id="content"> have this code:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5', 'paged' => $paged ) ); ?>

Wordpress Pagination

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

404 page errors with custom post type pagination in wordpress

This is my events template page in wordpress that displays 2 events at a time, but when you click on the previous posts link to show older event posts I keep getting this 404 page error in my custom post type. Any help would be appreciated. Here's my complete code on my template page:
<?php
/*
Template Name: Events Page
*/
?>
<?php get_header(); ?>
<div id="wrapper">
<section id="main-content">
<div class="signup">
Sign up for our mailing list
</div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article>
<?php the_content(); ?>
</article>
<?php endwhile; endif; ?>
<section id="event-listings">
<?php
$args = array(
'post_type' => 'events',
'posts_per_page' => 2,
'paged' => get_query_var('paged')
);
$global_posts_query = new WP_Query($args);
?>
<?php if ($global_posts_query->have_posts()) : while ($global_posts_query->have_posts()) : $global_posts_query->the_post(); ?>
<article class="post">
<div class="date">
<p><?php the_field('date'); ?><br><span class="year"><?php the_field('year'); ?></span></p>
</div>
<h2><?php the_field('headline'); ?></h2>
<p class="location"><?php the_field('location'); ?> ♥ <?php the_field('time'); ?></p>
<p class="coordinator">Created by: <span class="name"><?php the_field('author'); ?> on <time datetime="<?php echo date(DATE_W3C); ?>" pubdate class="updated"><?php the_time('F jS, Y') ?></time></span></p>
<p class="about-content"><?php the_field('about'); ?></p>
</article>
<?php endwhile; else: ?>
<p>No events posted at this time.</p>
<?php endif; ?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries', $global_posts_query->max_num_pages) ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »', $global_posts_query->max_num_pages) ?></div>
</div>
</section>
</section><!--End Main Content-->
</div><!--End Wrapper-->
<?php get_footer(); ?>

Getting pagenavi to work with a custom loop

<?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.

Resources