I've created a custom field with Advanced Custom Fields plugin called 'colaboradores' with fields logo (image), direccion (string) and mapa (image);
In archive-colaboradores.php, I call the WP_Quer. In short, code is:
<?php
$args = array(
'post_type' => 'colaboradores',
'pagination' => false
); ?>
<?php $the_query = new WP_Query( $args ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'colaboradores' ); ?>
<?php endwhile; // end of the loop. ?>
So in content-colaboradores.php I show my custom fields with the_field():
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php $image = get_field( 'logo' ); ?>
<?php echo '<img src="' . $image['url'] . '" >'; ?>
<?php echo '<p>' . the_field('direccion') . '</p>'; ?>
<?php $image = get_field( 'mapa' ); ?>
<?php echo '<img src="' . $image['url'] . '" >'; ?>
</article><!-- #post-## -->
Everything is fine except direccion, which is always outside the tag checking with Google Chrome:
I've removed all the code previous to ' . the_field('direccion') . ''; ?> but the problem persists.
Do you know why is it hapening? Thanks.
I cant be certain as dev tools doesnt show anything out of the ordinary but maybe try wrapping the_field in some tags to make sure nothing out of the ordinary is coming through.
<?php echo '<p>' . strip_tags(trim(the_field('direccion'))) . '</p>'; ?>
I put the strip tags in there because thats normally why chrome and other browsers would put content outside of an inline tag like a p tag
Other than that, maybe try letting wordpress format the paragraph tags, and see if it runs then
<?php echo apply_filters("the_content",get_field('direccion')); ?>
See if either of them work?
Related
OK, so I need to display ACF custom field inside my posts loop in my custom category.php file. Here is the loop:
<div class="container">
<div class="row">
<?php
if ( have_posts() ) : ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
?>
<div class="col-xs-12 col-sm-4">
<?php the_title( '<h2>', '</h2>' ); ?>
<div><?php MY_ACF_FIELD_GOES_HERE ?></div>
</div>
<?php
/* End the Loop */
endwhile;
?>
</div><!-- .row -->
</div><!-- .container -->
As you can see loop displays pages from category (titles), but I need also display short description. I know I could use:
<?php the_excerpt(); ?>
But not in this case because excerpt contains text that I do not need inside loop. So I need to create my own short description field for every page. How can I display it in category.php template? Custom field (my own short desc) is on all pages.
You can retrieve the ACF field value using get_field('field_name'). Example-
<?php
$args = array( 'post_type' => 'speakers', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="entry-content">';
echo '<h2 class="speaker-name">';
the_title();
echo '</h2>';
echo '<img src="' . get_field('field_name') . '" alt="" />';
echo '<span class="speaker-title">';
the_field('title'); echo ' / '; the_field('company_name');
echo '</p>';
the_content();
echo '</div>';
endwhile;
?>
I have a Wordpress site built with a theme in which the slider dissappears when you open on phone or Tablet. I've tried several different slider plugins, I tried deactivating all plugins and installing all of them one by one, but the problem persists, so I think that it is a PHP problem with the theme, but I can't seem to find a solution for it. When opening on phones or tablet the slider seems to load but it suddenly dissapears but the rest of the page is still there, I think it might take users to a new page when they open it from phones. Anyone could help me out, please?
Thank you!
http://www.lapinatasd.com
Thank you so much!
<?php /* Template Name: Home Page */ ?>
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- BEGIN HOME SLIDER SECTION -->
<section id="home-slider">
<?php putRevSlider( 'home' ); ?>
</section>
<!-- END HOME SLIDER SECTION -->
<?php endwhile; ?>
<?php $back = $post //backup post data?>
<?php $child_sections = new WP_Query(array('post_type' => 'page', 'post_parent' => $post->ID, 'orderby' => 'menu_order', 'order' =>'ASC', 'posts_per_page' => -1)); ?>
<?php while ($child_sections->have_posts() ) : $child_sections->the_post(); ?>
<?php $bg = rwmb_meta( '_jellythemes_section_bg', 'type=image', get_the_ID() ); foreach ($bg as $bg_image) : $bg_url = $bg_image['full_url']; endforeach; ?>
<?php $bg2 = rwmb_meta( '_jellythemes_section_bg2', 'type=image', get_the_ID() ); foreach ($bg2 as $bg_image2) : $bg_url2 = $bg_image2['full_url']; endforeach; ?>
<?php $video = get_post_meta( $post->ID, '_jellythemes_parallax_video', true ); ?>
<?php if (empty($video)): ?>
<section id="<?php echo esc_attr($post->post_name); ?>" class="section <?php echo get_post_meta( $post->ID, '_jellythemes_section_type', true ); ?> <?php echo get_post_meta( $post->ID, '_jellythemes_section_color', true ); ?>" style="background-color:<?php echo get_post_meta( $post->ID, '_jellythemes_bg_color', true ); ?>; <?php echo (!empty($bg_url) ? 'background-image: url(' . $bg_url . ')' . (!empty($bg_url2) ? ', url(' . $bg_url2 . ')' : '') . ';' : ''); ?>">
<div class="<?php echo get_post_meta( $post->ID, '_jellythemes_section_width', true ); ?>">
<?php the_content(); ?>
</div>
</section>
<?php else: ?>
<section id="<?php echo esc_attr($post->post_name); ?>" class="player section" data-property="{videoURL:'<?php echo esc_js($video); ?>',containment:'self',autoPlay:true, mute:true, startAt:0,opacity:1,ratio:'4/3', addRaster:true}">
<div class="overlay"></div>
<?php $logos = rwmb_meta('_jellythemes_bg_logo', 'type=image', $post->ID ); ?>
<?php foreach ($logos as $logo) : ?>
<img class="video-img" src="<?php echo esc_url($logo['full_url']); ?>" alt="video">
<?php endforeach; ?>
</section>
<?php endif ?>
<?php $bg_url=''; ?>
<?php endwhile; ?>
<?php $post = $back //restore post data?>
<?php get_footer(); ?>
</body>
</html>
I think you are using some responsive theme and the area you are using is configured to be hidden on small screen devices. For example, when using bootstrap, there is class hidden-sm-down. Check if this class is applied to the container you are working in. This will make the div invisible in small and xtra-small devices. Refer to enter link description here
For better help us understand the issue, attach the HTML of the page as well.
I'm trying to add another class to <div class="postthumbnail">. I wanted to style one post different. Therefore, after researching, I found that the best method is to use custom field to add class to the post.
This tutorial, How to style WP posts different, especially this section at bottom, explained how I can add class to the post using the custom field. I did so by giving the custom field a name "en_proceso_class" and the value, "en_proceso" which is an css class. But I'm confused by the last two codes I need to add. The tutorial wasn't clear on where I need to add them.
My original code is:
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// the query
$the_query = new WP_Query( 'cat=9&posts_per_page=9&paged=' . $paged );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="proyectpost">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="innerpost">
<div class="postthumbnail">
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" width="100%" />';
} ?>
</div>
<div class="posttitle">
<h2><?php the_title(); ?></h2>
<span><?php echo get_post_meta($post->ID, 'location', true); ?></span>
</div><!-- .entry-header -->
<div class="postsubtitle">
<div class="datepanel">
</div>
</div>
</div>
</article><!-- #post-## -->
</div>
<?php endwhile; ?>
<div class="paginationbar">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages,
'show_all' => True,
'prev_next' => False
) );
?>
</div>
<?php
// clean up after the query and pagination
wp_reset_postdata();
?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
This is section of the code that I'm trying to add the new code to:
<div class="innerpost">
<?php $custom_values = get_post_meta($post->ID, 'en_proceso_class'); ?>
<div class="postthumbnail <?php en_proceso_class('class-1 class-2 ' . $custom_variable); ?>">
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" width="100%" />';
} ?>
</div>
What do I need to do to get it working?
The last part isn't 100% clear but I'll try to answer as best I can.
This piece of code:
$custom_values = get_post_meta($post->ID, 'en_proceso_class');
Gets the value of a post meta field name: 'en_proceso_class'. You actually need to set that first in order for this to work. And you need to add 'true' as another parameter to that function. See here for more info: https://developer.wordpress.org/reference/functions/get_post_meta/
Then there's this:
div class="postthumbnail <?php en_proceso_class('class-1 class-2 ' . $custom_variable); ?>">
Which calls a function named 'en_proceso_class' -- I don't think this is what you want to do. Unless you declared that function beforehand you'll to do something like:
div class="postthumbnail <?php echo 'class-1 class-2 ' . $custom_variable; ?>">
So the whole code put together would look like this:
<div class="innerpost">
<?php
// Get post meta that is already set
$custom_values = get_post_meta($post->ID, 'en_proceso_class', true);
?>
<div class="postthumbnail <?php echo 'class-1 class-2 ' . $custom_values; ?>">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
echo '<img src="' . $image_src[0] . '" width="100%" />';
}
?>
</div>
Cheers
I'm working on a Wordpress index page that only shows posts if they have a featured image. This is my content.php code:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-sm-4">
<?php
if (has_post_thumbnail()) {
echo '<div class="small-index-thumbnail clear">';
echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '" rel="bookmark">';
echo the_post_thumbnail('index-thumb');
echo '</a>';
echo '</div>';
}
?>
</div>
</article><!-- #post-## -->
I'm just wondering if this is enough code for someone to tell me why it's still showing the posts, despite the posts not having a featured image. Thank you!
Actually, it looks right but there is a note about this on Codex, which is something like this:
// Must be inside a loop.
if ( has_post_thumbnail() ) {
// ...
}
Note The above code apparently fails in some instances and the below code is "recommended"
if ( '' != get_the_post_thumbnail() ) {
// some code
} else {
// some code
}
Check get_the_post_thumbnail if needed.
I have a post loop (index.php) which shows three post links as headers and above them there's a slideshow based on the slug of the post.
<div class="nuotraukos">
<?php if (have_posts()) : ?>
<?php $nuotraukos = new WP_Query('category_name=nuotraukos&showposts=3');
while ($nuotraukos->have_posts()) : $nuotraukos->the_post();
$do_not_duplicate = $post->ID; ?>
<div class="post" id="post-<?php the_ID(); ?>">
<p class="postmetadata"><?php edit_post_link(__('Edit')); ?></p>
<div class="entry">
<?php
if ( function_exists( 'meteor_slideshow' ) ) {
$slug = basename(get_permalink());
meteor_slideshow('' . $slug. '');
}
the_content('<h2>' . get_the_title() . '</h2>');
?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Meteor slideshow has a loop itself and I assume that it cancels the post loop after the first query. That's why it prints out only one title (but displays it three times) you can see it in http://studioglamour.co.uk.
The thing is i need three different links displayed below slideshows, but don't know how to fix this.
Try
$slug = basename(get_permalink($nuotraukos->post->ID));
...
the_content('<h2>' . get_the_title($nuotraukos->post->ID) . '</h2>');