Single post template not working in WordPress - wordpress

page-webinars.php:
<?php
/*
Template Name: Webinars
*/
?>
<?php
$loop = new WP_Query(array('post_type' => array('webinars')));
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post();
?>
<?php get_template_part('loop-webinars'); ?>
<?php endwhile; ?>
<?php endif;
wp_reset_postdata(); ?>
loop-webinars.php:
<?php the_title(); ?>
single-webinars.php:
<h1><?php the_title(); ?></h1>
<div>
<?php
the_post();
the_content();
?>
</div>
Looks like everything's correct. Page displays necessary template, but single not working.

You forget to use WordPress loop.
Try with this code in your single-webinars.php file.
<?php
// Start the loop.
while ( have_posts() ) : the_post();
?>
<?php the_title('<h1>', '</h1>'); ?>
<div>
<?php the_content(); ?>
</div>
<?php // End of the loop.
endwhile;
?>

It had just to "reactivate" theme...

Related

ACF Group field not displaying on the front end

I have created a group field in ACF to display on posts, pages and custom post type. Please see below screenshots.
And here's the code I'm trying for front-end.
<?php $footerCTA = get_field('footer_cta');
echo $footerCTA['title']; ?>
The code above doesn't output anything on the front-end. Am I missing here something?
Thanks.
try this:
if( have_rows('footer_cta') ):
while( have_rows('footer_cta') ) : the_row();
?>
<p><?php the_sub_field('title'); ?></p>
<?php
endwhile;
endif;
?>
Try using.
echo the_field('footer_cta');
Other Way.
You can do this by adding a second parameter to the get_field or the_field functions. This second parameter will contain the correct ID which can be found using get_option('page_for_posts') like so
<h1><?php the_field('footer_cta', get_option('page_for_posts')); ?></h1>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->

Multiple Wordpress Loops different categories

I'm really confused about how this works, I have looked in the Wordpress documentation but I can never find anything simple there anyway. I need 3 loops in my main index page, each loop will be based on one category and will need to grab just the latest post from that category.
I've got it working fine, but I'm just wondering if it is the right way of doing it? Obviously it works, but is it going to cause me any problems doing it this way? Is there a proper way of doing it?
//loop 1
<div class="large-4 columns">
<?php query_posts( 'category_name=stories&posts_per_page=1' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
//loop 2
<div class="large-4 columns">
<?php query_posts( 'category_name=pictures&posts_per_page=1' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
//loop 3
<div class="large-4 columns">
<?php query_posts( 'category_name=videos&posts_per_page=1' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
Ignore the HTML as I haven't formatted it yet. Any help please? Thanks
Yes there are possible problems with this.. You are modifying the original wordpress query. You should ignore using query_posts. You better use one of the following.
1.) get_posts ref
2.) custom wp query ref
Change
<?php query_posts( 'category_name=stories&posts_per_page=1' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
TO
<div class="large-4 columns">
<?php
$the_query = new WP_Query( 'category_name=stories&posts_per_page=1' );
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_title();
the_content();
}
/* Restore original Post Data */
wp_reset_postdata();
/* Added */
?>
</div>

Pagination is not working properly in Wordpress

I am currently using wordpress in creating my websites. And i really find a problem regarding pagination. So basically to be able for you to understand what is really my problem, I will post two codes:
This is the first code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH.'/inc/meta.php'); ?>
<div class="entry">
<?php
the_excerpt();
?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php
endwhile;
?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
In this lines of code, I used the regular loop in querying a post. Actually I did not modify the code. I also installed a plugin WP-PageNavi. There is no problem, pagination is working properly.
But when i put this line of code, about the regular loop. Pagination is not working properly. I put this line of code " " because I want only to show post in this said category.
2nd code:
Line of code
<?php query_posts('cat=8'); ?>
End line of code
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
My question is: What should I do in order for the pagination to worked properly? I really need some help with this.
I think the problem is the because of the two The Loop(i.e while and endwhile loop) in a page.
instead of while use foreach loop. below is the example
<?php
$args = array('category' => '8');
$postArr = get_posts($args);
if($postArr){
foreach($postArr as $details){
?>
div <?php post_class() ?> id="post-<?php echo $details->ID; ?>">
<h2><?php echo $details->post_title; ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php echo $details->post_excerpt(); ?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php
}
}else{
?>
<h2>Not Found</h2>
<?php
}
?>
Note Code not tested...

Getting Post Author in Wordpress

I'm building a Wordpress template from an HTML page.
I currently have
<?php $queried_post = get_post( $_GET['id'], $output ); ?>
Then I use ...
<?php echo $queried_post->post_title; ?>
Which works fine for echoing the post title.
Then I try to echo the author with...
<?php echo $queried_post->post_author; ?>
I get back '1' which is not the author name. How is this done correctly?
Try this code:
<?php the_author($_GET['id']); ?>
Codex entry: http://codex.wordpress.org/Function_Reference/the_author
My single.php file:
<?php get_header(); ?>
<?php if (have_posts()): ?>
<?php while (have_posts()): the_post(); ?>
<div class="post post-single">
<h1 class="post-title">
<?php the_title(); ?>
<?php edit_post_link('Edit', '', ''); ?>
</h1>
<div class="content"><?php the_content(); ?></div>
</div>
<?php endwhile; else: ?>
There are no posts to display.
<?php endif; ?>
<?php get_footer(); ?>

wp_query help with retrieveing posts via tag

s it possible to retrieve post entry for a custom post type by tag, I have been trying with the following code, however it just locks me into a infinte loop.
<aside class="supporting_images">
<?php /*<?php if($post->ID == 241) : echo apply_filters('the_content', '[slideshow=3]'); endif; ?>
<?php the_post_thumbnail(); ?>*/?>
<?php if($post->ID == 241) : ?>
<?php
$query = new WP_Query();
$query->query('tag=branding');
?>
<?php while ($query->have_posts()) : ?>
hello
<?php endwhile; ?>
<?php endif;?>
First try changing your loop to:
<?php while ($query->have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
The have_posts() function just returns true if there is another post but does not increment the loop counter, so the loop will never end.

Resources