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 -->
Related
I need to style the first post in the loop differently from the rest in a wordpress theme template. Is there a specific wordpress function to check for this or do I just need to set a "first" flag like the below?
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php if ( $first = !isset( $first ) ) : ?>
<!-- First Post HTML -->
<?php else : ?>
<!-- Every other posts HTML -->
<?php endif; ?>
<?php endwhile; ?>
The function I'm looking for would replace the $first = ! isset( $first) check. Does this function exist in WordPress?
Try this
<?php $Inc=0; ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php if ( $Inc==0 ) : ?>
<!-- First Post HTML -->
<?php else : ?>
<!-- Every other posts HTML -->
<?php endif; ?>
<?php $Inc++; ?>
<?php endwhile; ?>
I'm convering a html one page to wordpress but I can't seem to get the title for each section to return the right vaule.
This code is form page.php which displays the one page:
<?php
// Template Name: One Page Layout
get_header();
?>
<?php
// Main Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// GET HEADER
get_template_part( 'front-header');
// PROMOTION SECTION
get_template_part( 'front');
// LATEST WORK
get_template_part( 'lwork');
// LATEST POSTS
get_template_part( 'lpost');
// ABOUT ME
get_template_part( 'about');
// CONTACT
get_template_part( 'contact');
endwhile; endif; wp_reset_query();
get_footer();
?>
Here is the title I want to show (lpost.php):
<!-- section heading -->
<section class="section-heading">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</section>
What am I missing out on??
You need to put loop above the section
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="section-heading">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</section>
<?php endwhile; endif; wp_reset_query(); ?>
Your code should be:
<?php
query_posts(array('post_type' => 'post'));
// Main Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
you can use this code : get_title()
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="section-heading">
<h2><?php get_title(); ?></h2>
<?php the_content(); ?>
</section>
<?php endwhile; endif; wp_reset_query(); ?>
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...
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>
I have some categories like about-us, services etc and want to show different templates for these categories. I have read from wp site to make files name like category-slug.php where slug may be about-us or services. I made these files but they didn't worked for me. Instead of these templates the index file displays the posts. I want to display posts from these categories in custom files.
Can any one tell me how to do this?
Are you looking for something like this?
<?php /*
Template Name: ListPostsInCategoryThatHasSameNameAsPage
*/ ?>
<?php get_header(); ?>
<div id="content">
<div id="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
</div>
</div>
<?php get_footer(); ?>