Blog only showing one post why even though all are published, - php

Why is my WordPress blog.php only showing one blog entry while I have two entries in the blog at present? I have verified that both are published. And I do have my reading setup to my blog page. Any ideas?.
http://kvalixhu.digitalthinkersni.co.uk/blog/
<?php /* Template Name: BlogPosts */ ?>
<?php get_header(); ?>
<div id="contentWrap" class="group">
<?php get_sidebar(); ?>
<div id="article">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=5'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<?php $wp_query = null; $wp_query = $temp;?>
<h2><?php the_title(); ?></h2>
<p> Posted By <?php the_author(); ?></p>
<div id="entryItem">
<?php the_content(); ?>
</div><!--entryItem-->
</div><!--article-->
<?php endwhile; ?>
</div><!--contentWrap-->
</div><!--mainWrapper-->
<?php get_footer(); ?>

Put article opening tag inside the loop
I assume, that you want to wrap each posts with a article div. Since more than one container with the same is not allow, you should change this to a class.
Remove $temp
Why are you using $temp? Just remove this, and don't set $wp_query to null.
<?php /* Template Name: BlogPosts */ ?>
<?php get_header(); ?>
<div id="contentWrap" class="group">
<?php get_sidebar(); ?>
<?php
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=5'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="article">
<h2><?php the_title(); ?></h2>
<p> Posted By <?php the_author(); ?></p>
<div id="entryItem">
<?php the_content(); ?>
</div><!--entryItem-->
</div><!--article-->
<?php endwhile; ?>
</div><!--contentWrap-->
<?php get_footer(); ?>

Related

WordPress One page site (page on front-page)

I'm designing a theme from scratch. It's an One page site and my CMS is WordPress.
My folder structure is :
front-page.php
page-about.php
page-work.php
page-contact.php
I can display all my pages on the front-page.php as section but I lose all my custom classes (and specific styles). Here the loop in my front-page.php :
<?php get_header(); ?>
<?php query_posts('post_type=page&order=ASC'); ?>
<?php
if (have_posts()):
while (have_posts()) : the_post(); ?>
<section id="page-<?php the_ID(); ?>">
<div class="container">
<h2><?php the_title(); ?></h2>
<article>
<p><?php the_content(); ?></p>
</article>
</div>
</section>
<?php endwhile;
endif; ?>
<?php get_footer(); ?>
How can I keep the style (therefore, their classes/id's) of the page-xxx.php as section in my front-page.php ?
Thank you
you can add a custom class to specific page id, example :
add_filter('body_class', 'your_body_class');
function your_body_class($classes) {
if (is_page(xxx))
$classes[] = 'new-class';
return $classes;
}
you can use this plugin Custom Body Class
I did this (in the front-page.php) :
<?php get_header(); ?>
<?php
$args = array(
'post_type' => 'page',
'order' => 'ASC'
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ( $query->have_posts()) {
$query->the_post();
$tn = get_page_template_slug($post_id);
$word = array("page-", ".php",' ');
$template = str_replace($word,'',$tn);
get_template_part('page', $template);
}
}
?>
<?php get_footer(); ?>
Look like it works, I have three sections with my three pages and their classes. But now, I have no content.
My page-about.php :
<?php get_header();
/* Template Name: About */ ?>
<section id="about" class="section section-about">
<div class="container">
<h2 class="title-2"><?php the_title(); ?></h2>
<div class="col-md-6 col-lg-12"></div>
<article class="article-about">
<?php
if (have_posts()):
while (have_posts()): the_post(); ?>
<p><?php the_content(); ?></p>
<?php endwhile;
endif;
?>
</article>
</div>
</section>
<?php get_footer(); ?>

Post content not showing

I have this code that works perfect:
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('posts_per_page=5' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<span><?php the_date('m/d/y'); ?></span>
<button>Read More</button>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
I want to display an excerpt of the post content between the date and button. So I added <p><?php the_content(); ?></p>. Didn't work. I tried <p><?php get_the_content(); ?></p>. Still nothing.
I tried putting the <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> loop around all of the HTML and just the paragraph. Both yielded nothing.
How do I get the excerpt to display?

Cannot get post_content in customize page?

I've created a customize page show all posts with template:
<?php
/*
Template Name: All posts
*/
get_header();
?>
</header>
<div role="main" id="content" class="content-warp">
<div class="container">
<div id="primary" class="content-area col-md-8 post-list">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<div class="entry">
<?php the_content(); ?>
<?php
$current_date = "";
$count_posts = wp_count_posts();
$nextpost = 0;
$published_posts = $count_posts->publish;
$myposts = get_posts(array('posts_per_page' => $published_posts));
foreach ($myposts as $post) :
get_template_part('content', 'content-single');
?>
<?php endforeach; ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_sidebar('page'); ?>
<div style="clear:both"></div>
</div>
</div>
<?php get_footer(); ?>
But it not show post_content of Posts (all remain data are normal).
By the way, with default UI Categories (content.php), i just call below code and everything Ok: the same UI with new template but have post_content).
<?php get_template_part( 'content', 'single' ); ?>
I don't know why post_content is null in new my template. I'm using Llorix One LiteVersion: 0.1.7
Any help, thanks.
I try read document again and realize the_content not set data yet.
So, just add setup post data, look like:
...
foreach($myposts as $post) : setup_postdata( $post );
...
Also You can use new WP Query
$myposts = new WP_QUery(array(
'posts_per_page' => $published_posts
));
if ($myposts->have_posts()): ?>
<?php while ($myposts->have_posts()) {
$myposts->the_post();
get_template_part('content', 'content-single');
} ?>
<?php endif ?>
<?php wp_reset_query(); ?>

How to make a second loop in single.php work?

-simple blog
-twenty twelve child theme
I need: a second loop in single.php that shows the selected post and all the other posts below.
What I have so far in single.php (results in a blank page) :
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
<?php wp_reset_postdata(); // reset the post data so we can run another query ?>
<?php get_sidebar(); ?>
<?php
// The Second Query
$the_query = new WP_Query();
// The Loop
if ( $the_query->have_posts() ):
while ( $the_query->have_posts() ):
$the_query->the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); // Restore original Post ?>
</div><!-- #content -->
</div><!-- #primary -->
This should do the trick:
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
<?php wp_reset_postdata(); // reset the post data so we can run another query ?>
<?php
$args_second = array(
'posts_per_page' => -1,
);
// The Second Query
$second_query = new WP_Query( $args_second );
// The Loop
if ( $second_query->have_posts() ):
while ( $second_query->have_posts() ):
$second_query->the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); // Restore original Post ?>
</div><!-- #content -->
</div><!-- #primary -->
Notes:
You need to properly show the title and content using the_title() and the_content() inside the single loop.
To show other posts, you need to query them, you'll quickly understand by looking at the code above.
I'll leave the styling for you.
It is tested and working.

Wordpress Page Template Not Rendering

Our blog page is supposed to look something like this: http://livedemo00.template-help.com/wordpress_33821/?page_id=174
However it ends up looking like this - completely empty!
This is despite the fact that the page theme is set correctly and the template file contains the following code:
<?php
/**
* Template Name: Blog
*/
get_header(); ?>
<div class="box clearfix color2">
<div id="content" class="three_fourth">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=5'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<h2><?php the_title(); ?></h2>
<div class="post-meta">
<div class="fleft">Posted in: <?php the_category(', ') ?> | <time datetime="<?php the_time('Y-m-d\TH:i'); ?>"><?php the_time('F j, Y'); ?> at <?php the_time() ?></time> , by <?php the_author_posts_link() ?></div>
<div class="fright"><?php comments_popup_link('No comments', 'One comment', '% comments', 'comments-link', 'Comments are closed'); ?></div>
</div><!--.post-meta-->
</header>
<?php echo '<div class="featured-thumbnail">'; the_post_thumbnail(); echo '</div>'; ?>
<div class="post-content">
<div class="excerpt"><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,50);?>Read more</div>
</div>
</article>
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<nav class="oldernewer">
<div class="older">
<?php next_posts_link('« Older Entries') ?>
</div><!--.older-->
<div class="newer">
<?php previous_posts_link('Newer Entries »') ?>
</div><!--.newer-->
</nav><!--.oldernewer-->
<?php endif; ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div><!--#content-->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Unfortunately this theme doesn't have any documentation so I'm forced to find my own solution.
Actually I already faced this situation in WordPress.
Its not fault of your code. Might be WordPress Bug.
Try to change your page name once.
Like
<?php
/**
* Template Name: Blog_new
*/
?>
And login again and check if it is showing new custom page option or not.

Categories