In the code bellow Im displaying one Case using get_field(); on my startpage.
Know I wanna be able to random two fields(), using get_field('promoted_case') and get_field('promoted_case_two'); on the startpage.
When a person updates the webpage Its supposed to random the two fields...
How can I do that in my code?
<?php if ( $case = get_field( 'promoted_case') ) : ?>
<?php $link = get_permalink( $case->ID ); ?>
<section class="content row">
<header class="dotted">
<h2 class="centered uc feat-case-header"><?php _e( 'Featured case', 'vvt' ) ?></h2>
</header>
<article class="promoted_case">
<div class="row case-header">
<div class="twelve columns">
<h2 class="single-case-header"><?php echo esc_html( $case->post_title ); ?></h2>
</div>
</div>
<div class="row case-content">
<div class="columns six push_six">
<div class="frontpage_case_image">
<?php vvt_post_thumbnail( 'contact_images', $case->ID ); ?>
</div>
</div>
<div class="columns six pull_six entry-content">
<?php echo vvt_trim_words( $case->post_content ); ?>
<div class="frontpage_case_btn">
<a class="button" href="<?php echo home_url( '/cases/' ); ?>"><?php _e( 'Show all Cases', 'vvt' ); ?> <i class="icon-arrow-right"></i></a>
</div>
</div>
</div>
</article>
</section>
<?php endif; ?>
$fields = array('promoted_case', 'promoted_case_two');
$field = $fields[rand(0, count($fields) - 1)];
if ( $case = get_field( $field) )
Related
I have this code to display custom ACF fields on a page. When the subfields are empty, i would like to hide the div containers (class= price-container and ikon-container) completely, as it takes space in the column for another div container which is supposed to fill out the space instead.
How to solve this?
Thanks
<?php if ( have_rows( 'menuer_layout') ) : ?>
<div class="col-sm-12 col-md-12 col-lg-4" style="padding:0">
<div class="sticky-top">
<div class="price-container">
<div id="pricebox-content" class="slick-slide-pricebox">
<div class="pricebox-container">
<div class="pricebox-top">
<h4 class="pricebox-header">One</br>Two</h3>
<span class="price-subtitle">Here goes..</span>
</div>
<?php while ( have_rows( 'menuer_layout' ) ) : the_row(); ?>
<div class="menucard-container">
<h5 style="margin:0"><?php the_sub_field( 'menu_overskrift' ); ?></h5>
<span><?php the_sub_field( 'menu_tekst' ); ?></span>
<?php $menu_knap_url = get_sub_field( 'menu_knap_url' ); ?>
<?php if ( $menu_knap_url ) { ?>
<div class="pricebox-link-container" style="padding-top: 5px">
<a class="knap-2" href="<?php echo $menu_knap_url['url']; ?>" target="<?php echo $menu_knap_url['target']; ?>"><?php the_sub_field( 'menu_knap_tekst' ); ?></a>
</div>
<?php } ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
</div>
</div>
</div>
<?php $hotel_ikoner_images = get_field( 'hotel_ikoner', 'option' ); ?>
<?php if ( $hotel_ikoner_images ) : ?>
<div class="ikon-container">
<ul class="ikon-liste">
<?php foreach ( $hotel_ikoner_images as $hotel_ikoner_image ): ?>
<li class="hotel-ikon-spec">
<img class="hotel-ikon-small" src="<?php echo esc_url( $hotel_ikoner_image['sizes']['thumbnail'] ); ?>" alt="<?php echo esc_attr( $hotel_ikoner_image['alt'] ); ?>" /> <span class="hotel-ikon-text"><?php echo esc_html( $hotel_ikoner_image['caption'] ); ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
You Can Use get_sub_field
https://www.advancedcustomfields.com/resources/get_sub_field/
<?php if(!get_sub_field('field_name')){ ?>
<div>
Hide This Content If Field Empty
</div>
<?php } ?>
I'm currently working on a website for a client and I want to change the search results page. I tried a lot of things but when I search for something on the website I get search results, but without a image or description. My client want the website to show a image and a description.
Here is my search.php code:
/**
* The search template file.
*
* #package Betheme
* #author Muffin group
* #link https://muffingroup.com
*/
get_header();
$translate['search-title'] = mfn_opts_get('translate') ? mfn_opts_get('translate-search-title','Ooops...') : __('Ooops...','betheme');
$translate['search-subtitle'] = mfn_opts_get('translate') ? mfn_opts_get('translate-search-subtitle','No results found for:') : __('No results found for:','betheme');
$translate['published'] = mfn_opts_get('translate') ? mfn_opts_get('translate-published','Published by') : __('Published by','betheme');
$translate['at'] = mfn_opts_get('translate') ? mfn_opts_get('translate-at','at') : __('at','betheme');
$translate['readmore'] = mfn_opts_get('translate') ? mfn_opts_get('translate-readmore','Read more') : __('Read more','betheme');
?>
<div id="Content">
<div class="content_wrapper clearfix">
<div class="sections_group">
<div class="section">
<div class="section_wrapper clearfix">
<?php if( have_posts() && trim( $_GET['s'] ) ): ?>
<div class="column one column_blog">
<div class="blog_wrapper isotope_wrapper">
<div class="posts_group classic">
<?php
while ( have_posts() ):
the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class( array('post-item', 'clearfix', 'no-img') ); ?>>
<div class="post-desc-wrapper">
<div class="post-desc">
<?php if( mfn_opts_get( 'blog-meta' ) ): ?>
<div class="post-meta clearfix">
<div class="author-date">
<span class="author"><span><?php echo esc_html($translate['published']); ?> </span><i class="icon-user"></i> <?php the_author_meta('display_name'); ?></span>
<span class="date"><span><?php echo esc_html($translate['at']); ?> </span><i class="icon-clock"></i> <?php echo esc_html(get_the_date()); ?></span>
</div>
</div>
<?php endif; ?>
<div class="post-title">
<h2><?php the_title(); ?></h2>
</div>
<div class="post-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="post-footer">
<div class="post-links">
<i class="icon-doc-text"></i> <?php echo esc_html($translate['readmore']); ?>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
<?php
if(function_exists( 'mfn_pagination' )):
echo mfn_pagination();
else:
?>
<div class="nav-next"><?php next_posts_link(esc_html__('← Older Entries', 'betheme')) ?></div>
<div class="nav-previous"><?php previous_posts_link(esc_html__('Newer Entries →', 'betheme')) ?></div>
<?php
endif;
?>
</div>
</div>
<?php else: ?>
<div class="column one search-not-found">
<div class="snf-pic">
<i class="themecolor <?php echo esc_attr(mfn_opts_get('error404-icon', 'icon-traffic-cone')); ?>"></i>
</div>
<div class="snf-desc">
<h2><?php echo esc_html($translate['search-title']); ?></h2>
<h4><?php echo esc_html($translate['search-subtitle']) .' '. esc_html($_GET['s']); ?></h4>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php if( is_active_sidebar( 'mfn-search' ) ): ?>
<div class="sidebar four columns">
<div class="widget-area clearfix <?php echo esc_attr(mfn_opts_get('sidebar-lines')); ?>">
<?php dynamic_sidebar( 'mfn-search' ); ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php get_footer();
<?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>
<div class="post-img">
<img src="<?php echo $featured_img_url; ?>"/>
</div>
use above code in while loop to show image by using post id.
The PHP code seems to be blocking or interfering with my advanced custom fields as it doesn't display unless I remove the PHP code then it does. I can't figure out where the issue is.
Any help is much appreciated.
PHP
<?php if(strpos($_SERVER['REQUEST_URI'], 'gaeilge') !== false) {
$newsCat = 'cat=5,7&showposts=3';
} else {
$newsCat = 'cat=6,8&showposts=3';
}; ?>
Advanced Custom Fields
<div class="carousel-item active">
<div class="row py-5">
<?php if( have_rows('block') ): ?>
<?php while( have_rows('block') ): the_row();
// vars
$content = get_sub_field('content');
?>
<div class="col-lg-4 col-md-4">
<?php if(strpos($_SERVER['REQUEST_URI'], 'gaeilge') !== false) { ?> <!--Check if url contains the word "items" -->
<h2 class="fw-b c-blue mt-0">Ár bhFís</h2>
<?php } else { ?>
<h2 class="fw-b c-blue mt-0">Our Vision</h2>
<?php } ?>
</div>
<div class="col-lg-8 col-md-8">
<p class="c-blue mb-0"><?php echo $content; ?></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
Fixed it by just changing how News articles where added.
<div class="row pt-4 pb-3">
<?php
// args
$args = array(
'posts_per_page' => -1,
'post_type' => 'post'
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="col-lg-4 col-md-4 col-sm-6 mb-5">
<div class="w-100 mb-2 px-2">
<img class="w-100" src="<?php $featimage = the_post_thumbnail_url('news-image'); ?>" alt="">
<p class="text-muted mt-4 mb-2"><?php echo get_the_date('dS M, Y'); ?></p>
<h3 class="c-blue"><?php the_title(); ?></h3>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div>
I'm developing a child theme of Onepress. I need all posts displayed inside a container div that is inside the main tag. I did it in my code, but, some posts are rendered outside the main tag in the browser. It breaks the layout. Any help will be deeply apprecciated!
Here's the code in my file:
<div id="content" class="site-content">
<?php onepress_breadcrumb(); ?>
<div id="content-inside" class="container">
<div id="primary" class="content-area">
<main class="site-main" role="main">
<div class="container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<div class="container">
<?php get_template_part( 'template-parts/content', 'custom' ); ?>
</div>
<?php endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</div>
</main><!-- #main -->
</div><!-- #primary -->
</div><!--#content-inside -->
</div><!-- #content -->
The code in custom template file:
<article class="row entry-article col-sm-12 col-md-12 w-100" id="post-<?php the_ID(); ?>" <?php post_class( array('list-article', 'clearfix') ); ?>>
<div class="col-sm-12 col-md-3 thumb-custom-container">
<a href="<?php echo esc_url( get_permalink() ); ?>">
<?php
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'onepress-blog-medium' );
} else {
echo '<img class="thumb-custom" alt="" src="'. get_template_directory_uri() . '/assets/images/placholder2.png' .'">';
}
?>
</a>
</div>
<div class="col-sm-12 col-md-6">
<div class="row">
<div class="col-sm-12">
<header class="entry-header col-sm-12">
<?php /* the_title( sprintf( '<p>', esc_url( get_permalink() ) ), '</p>' ); */ ?>
<?php
$post_id = get_the_ID();
echo '<h2 class="entry-price">R$ ' . get_post_meta($post_id, 'real_state_price', true) . '</h2>';
$post_id = get_the_ID();
echo '<small class="entry-features">'
. get_post_meta($post_id, 'real_state_size', true) . ' m², Square '
. get_post_meta($post_id, 'real_state_square', true) . ', Number '
. get_post_meta($post_id, 'real_state_number', true)
. '</small>';
?>
</header><!-- .entry-header -->
<div class="col-sm-12 entry-excerpt">
<?php
the_excerpt();
?>
</div>
</div>
<div class="col-sm-12 entry-link">
<button class="btn entry-btn-details" href="<?php echo esc_url( get_permalink($post_id) ); ?>">+</button>
<span><a class="entry-read-more" href="<?php echo esc_url( get_permalink($post_id) ); ?>">
Read More
</a></span>
</div>
</div>
</div>
<!-- PICTURE FROM CATEGORIE IMAGES PLUGIN -->
<div class="col-sm-12 col-md-3">
<div class="col-sm-12 entry-residencial">
<a href="<?php echo esc_url( get_permalink() ); ?>">
<?php
$residencial_terms = get_the_terms($post_id, 'residencials');
foreach ($residencial_terms as $term) : ?>
<img src="<?php echo z_taxonomy_image_url($term->term_id); ?>" />
<?php endforeach; ?>
</a>
</div>
<div class="col-sm-12">
<?php
// Teste para identificar a cidade e chamar o modal de contato correspondente
$cities_terms = get_the_terms($post_id, 'city');
if (!empty($cities_terms)) :
if (is_array($cities_terms)) :
foreach ($cities_terms as $term) :
$term_name = $term->name;
$city = $term_name == 'City01' ? 'firstModal' : 'secondModal';
endforeach;
else :
$city = $term;
endif;
else :
$city = 'generalModal';
endif;
?>
<button type="button" class="btn entry-btn" data-toggle="modal" data-target="#<?php echo $city; ?>">
Contact
</button>
</div>
</div>
</div><!-- entry content -->
And this is the code rendered in the browser:
<div id="content" class="site-content">
<?php onepress_breadcrumb(); ?>
<div id="content-inside" class="container">
<div id="primary" class="content-area">
<main class="site-main search-page" role="main">
<div class="container">
SOME POSTS HERE
</div>
</main><!-- #main -->
<!-- OTHER POSTS ARE INCORRECTLY HERE -->
<div class="container">
INCORRECTLY PLACED POSTS
</div><!-- incorrectly placed posts -->
</div><!-- #primary -->
</div><!--#content-inside -->
</div><!-- #content -->
So, anyone have a clue about how to fix this bug?
Thank you, guys!
it looks like you have some invalid HTML in your code.
So far I could find this inconsistency:
<div class="col-sm-12 entry-excerpt">
<?php
the_excerpt();
?>
</div>
</div>
I am using crowdfunding by astoundify to ceate custom post type download(which is campaign actually). I have created a signle-download.php page as a template but post pages do not seem to use this template. Is there anything else I have to do?
code for single-download.php
<?php
global $wp_embed;
get_header();
?>
<div class="bigcontainer4">
<div class="container">
<div id="content">
<div class="clearfix">
<?php while ( have_posts() ) : the_post(); $campaign = new ATCF_Campaign( $post->ID ); ?>
<div class="project_content_line">
<div class="blog_post">
<div class="project_image_bg">
<div class="project_image">
<?php if ( $campaign->video() ) : ?>
<div class="project_video">
<div class="project_videobox">
<?php echo $wp_embed->run_shortcode( '[embed]' . $campaign->video() . '[/embed]' ); ?>
</div>
</div>
<?php else :
the_post_thumbnail('blog-single-image');
endif; ?>
</div>
<h1>
<?php the_title() ;?>
</h1>
</div>
</div>
<div class="blog_sidebar">
<div class="project_sb_date">
<?php printf( __( '%s'), get_the_date('') ); ?>
-
<?php printf( __( '%s'), $campaign->end_date('') ); ?></div>
<div class="project_sb_date_rem">
<?php echo $campaign->
days_remaining(); ?>
<?php echo _n( $campaign->days_remaining(), 'day left', 'days left' ); ?></div>
<div class="project_small_excerpt">
<?php //echo excerpt(26); ?>
<div class="project_list_box_loader">
<div class="project_list_box_loaderbar">
<span style="width: <?php echo $campaign->percent_completed(); ?>"></span>
</div>
</div>
</div>
<div class="project_money_data">
<div class="project_money_data1">
<p>
<?php echo $campaign->current_amount(); ?></p>
<span>Raised</span>
</div>
<div class="project_money_data2">
<p></p>
<span>
of
<?php printf( __( '%s'), $campaign->goal() ); ?></span>
</div>
<?php if ( $campaign->is_active() )
echo edd_get_purchase_link( array(
'download_id' => $post->ID,
'class' => '',
'price' => false,
'text' => __( 'Contribute Now', 'fundler' )
) );
?>
</div>
</div>
<div class="project_content_line">
<div class="blog_post">
<div class="project_content">
<?php the_content(); ?>
<div class="project_content_updates">
<div class="project_sb_title">
<p>Latest</p>
<span>Updates</span>
</div>
<?php echo $campaign->updates() ?>
</div>
<?php comments_template(); ?>
</div>
</div>
<div class="blog_sidebar">
<div class="project_author_box">
<div class="project_sb_title">
<p>About</p>
<span>The Author</span>
</div>
<div class="project_author_image">
<?php
$author_email = get_the_author_meta('email');
echo get_avatar($author_email, '512');
?>
<div class="project_author_image_data">
<p>
<?php if ( '' != $campaign->author() ) :
printf( __( '%s', 'fundler' ), esc_attr( $campaign->author() ) );
endif; ?>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php get_footer(); ?>
According to Wordpress documentation:
WordPress looks for template files with specific names in the current
Theme's directory and uses the first matching template file listed
under the appropriate query section below.
So, I guess, you have another template matching condition. And wordpress uses it to display your page.
Added from comment: May be you are using just another theme, not the one, your file resides in?