I'm trying to use the Infinite Scroll plugin for Wordpress. I set it up and it doesn't work.
Screen of settings:
Template file
<div id="posts-wrapper" class="row main">
<?php $counter = 1; ?>
<?php if ( have_posts() ){ while ( have_posts() ){ the_post(); ?>
<?php $url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' ); ?>
<div class="single-post <?php if( $counter == 5 ) { echo "col-xs-12 col-sm-12 col-md-8 col-lg-8"; } else { echo "col-xs-12 col-sm-6 col-md-4 col-lg-4";} ?>">
<div class="thumbnail">
<div class="category-wrapper"><?php the_category(', ');?></div>
<a class="href-overlay" href="<?php the_permalink(); ?>"><div class="wrapper">
<div class="<?php if( has_term( 'hot', 'hot', $post->ID ) ){ echo "inside inside-hot"; } else { echo "inside";} ?>"><div class="image-cover" style="background-image: url(<?php echo $url[0]; ?>)"></div></div>
</div></a>
<div class="post-wrapper">
<p class="post-created-by">Napisane przez <strong><span class="special"><?php echo get_the_author(); ?></span></strong> | <i class="glyphicon glyphicon-comment"></i> <?php comments_number( '0' , '1' , '%' ); ?></p>
<h2 class="post-title"><?php the_title(); ?></h2>
</div>
</div>
</div>
<?php $counter++ ; ?>
<?php }else{ ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php } ?>
</div>
<div id="paginacja">
<?php next_posts_link('wczytaj więcej »')?>
</div>
What am I doing wrong?
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 trying 3 columns layout of related articles, but if the number of related articles is less than 3 to be different layout. If the number of related articles is 2 the first column to have class col-sm-offset-2, and if the columns is 1 - to have class col-sm-offset-4.
$category = get_post_category();
$relatedArticles = get_posts( [
'exclude' => $post->ID,
'category' => $category->term_id,
'posts_per_page' => 3
] );
?>
<?php if ( count( $relatedArticles ) > 0 ): ?>
<section class="related-articles">
<div class="container">
<div class="row">
<h2 class="text-center"><?php echo __( 'Related Articles' ) ?></h2>
<?php foreach ( $relatedArticles as $relatedArticle ): ?>
<div class="col-sm-4">
<article id="" class="post">
<div class="post-image">
<a href="<?php echo get_permalink( $relatedArticle ) ?>">
<?php echo get_the_post_thumbnail( $relatedArticle, 'post-category' ) ?>
</a>
</div>
<h3 class="post-title">
<a href="<?php echo get_permalink( $relatedArticle ); ?>">
<?php echo get_post_title($relatedArticle) ?>
</a>
</h3>
<div class="post-summary">
<p><?php echo get_summery($relatedArticle);?></p>
</div>
</article>
</div>
<?php endforeach; ?>
</div>
</div>
</section>
<?php endif ?>
You can add an if/else clause for the opening tag of the div which contains the article, adding the desired classes (applied only to the first article - I added a counter for that) in the different versions:
$category = get_post_category(); $relatedArticles = get_posts( [ 'exclude' => $post->ID, 'category' => $category->term_id, 'posts_per_page' => 3 ] ); ?>
<?php if ( count( $relatedArticles ) > 0 ): ?>
<section class="related-articles">
<div class="container">
<div class="row">
<h2 class="text-center">
<?php echo __( 'Related Articles' ) ?>
</h2>
<?php $counter = 1; ?>
<?php foreach ( $relatedArticles as $relatedArticle ): ?>
<?php if ( count( $relatedArticles ) >= 3 ) { ?>
<div class="col-sm-4">
<?php } elseif (( count( $relatedArticles ) == 2) && ($counter == 1)) { ?>
<div class="col-sm-4 col-sm-offset-2">
<?php } elseif (( count( $relatedArticles ) == 1) && ($counter == 1)) { ?>
<div class="col-sm-4 col-sm-offset-4">
<?php } ?>
<article id="" class="post">
<div class="post-image">
<a href="<?php echo get_permalink( $relatedArticle ) ?>">
<?php echo get_the_post_thumbnail( $relatedArticle, 'post-category' ) ?>
</a>
</div>
<h3 class="post-title">
<a href="<?php echo get_permalink( $relatedArticle ); ?>">
<?php echo get_post_title($relatedArticle) ?>
</a>
</h3>
<div class="post-summary">
<p>
<?php echo get_summery($relatedArticle);?>
</p>
</div>
</article>
</div>
<?php $counter++; ?>
<?php endforeach; ?>
</div>
</div>
</section>
<?php endif ?>
I'm trying to get the list of the images attach in a post to build a slider, but it's happen that the images that has being grab are the first two images in the media library and not the images add it to the post
content-gallery.php
<article id="post-<?php the_ID(); ?>" <?php post_class( 'advanceplr-format-gallery' ); ?>>
<header class="entry-header text-center">
<?php if( advanceplr_get_attachment() ):
$attachments = advanceplr_get_attachment(7);
var_dump($attachments);
?>
<div id="post-gallery-<?php the_ID(); ?>" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<?php
$i = 0;
foreach( $attachments as $attachment ):
$active = ( $i == 0 ? ' active' : '' );
?>
<div class="item<?php echo $active; ?> background-image standard-featured" style="background-image: url( <?php echo wp_get_attachment_url( $attachment->ID ); ?> );"></div>
<?php $i++; endforeach; ?>
</div><!-- .carousel-inner -->
<a class="left carousel-control" href="#post-gallery-<?php the_ID(); ?>" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#post-gallery-<?php the_ID(); ?>" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- .carousel -->
<?php endif; ?>
<?php the_title( '<h1 class="entry-title">', '</h1>'); ?>
<div class="entry-meta">
<?php echo advanceplr_posted_meta(); ?>
</div>
</header>
<div class="entry-content">
<div class="entry-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="button-container text-center">
<?php _e( 'Read More' ); ?>
</div>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php echo advanceplr_posted_footer(); ?>
</footer>
theme-support.php
function advanceplr_get_attachment( $num = 1 ){
$output = '';
if( has_post_thumbnail() && $num == 1 ):
$output = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
else:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => $num,
'post_parent' => get_the_ID()
) );
if( $attachments && $num == 1 ):
foreach ( $attachments as $attachment ):
$output = wp_get_attachment_url( $attachment->ID );
endforeach;
elseif( $attachments && $num > 1 ):
$output = $attachments;
endif;
wp_reset_postdata();
endif;
return $output; }
I also have a post format for the image that use the same code and it working,
content-image.php
<article id="post-<?php the_ID(); ?>" <?php post_class( 'advanceplr-format-image' ); ?> >
<header class="entry-header text-center background-image" style="background-image: url(<?php echo advanceplr_get_attachment(); ?>);">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<div class="entry-meta">
<?php echo advanceplr_posted_meta(); ?>
</div>
<div class="entry-excerpt image-caption">
<?php the_excerpt(); ?>
</div>
</header>
<footer class="entry-footer">
<?php echo advanceplr_posted_footer(); ?>
</footer>
due to some reason I'm getting the search bar in duplicate.
I suspect I have a double function command somewhere...but I can not find it. Can someone look at the code with "fresh eyes" and try to find my mistake?
as wordpress keeps giving me 2 search bars instead of one
I am using Notepad++, Bootstrap v 3.0 and Wordpress 4.7.8
Here is the code
<?php get_header(); ?>
<div class="row">
<div class="col-xs-12 col-sm-8">
<div class="row text-center no-margin">
<?php
$currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage);
new WP_Query($args);
if( have_posts() ): $i = 0;
while( have_posts() ): the_post(); ?>
<?php
if($i==0): $column = 12; $class = '';
elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding';
elseif($i > 2): $column = 4; $class = ' third-row-padding';
endif;
?>
<?php the_content(); ?>
<div class="col-xs-<?php echo $column; echo $class; ?> blog-item">
<?php if( has_post_thumbnail() ):
$urlImg = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
endif; ?>
<div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);">
<!--<?php the_title( sprintf('<h1 class="entry-title">', esc_url( get_permalink() ) ),'</h1>' ); ?> -->
<h1 class="entry-title"><?php the_title(); ?></h1>
<small><?php the_category(' '); ?></small>
</div>
</div>
<?php $i++; endwhile; ?>
<div class="col-xs-6 text-left">
<?php next_posts_link('« Older Posts'); ?>
</div>
<div class="col-xs-6 text-right">
<?php previous_posts_link('Newer Posts »'); ?>
</div>
<?php endif;
wp_reset_query();
?>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
Try this code.
I have disabled the //get_sidebar();
<?php get_header(); ?>
<div class="row">
<div class="col-xs-12 col-sm-8">
<div class="row text-center no-margin">
<?php
$currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage);
new WP_Query($args);
if( have_posts() ): $i = 0;
while( have_posts() ): the_post(); ?>
<?php
if($i==0): $column = 12; $class = '';
elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding';
elseif($i > 2): $column = 4; $class = ' third-row-padding';
endif;
?>
<div class="col-xs-<?php echo $column; echo $class; ?> blog-item">
<?php if( has_post_thumbnail() ):
$urlImg = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
endif; ?>
<div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);">
<!--<?php the_title( sprintf('<h1 class="entry-title">', esc_url( get_permalink() ) ),'</h1>' ); ?> -->
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php the_content(); ?>
<small><?php the_category(' '); ?></small>
</div>
</div>
<?php $i++; endwhile; ?>
<div class="col-xs-6 text-left">
<?php next_posts_link('« Older Posts'); ?>
</div>
<div class="col-xs-6 text-right">
<?php previous_posts_link('Newer Posts »'); ?>
</div>
<?php endif;
wp_reset_query();
?>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<?php //get_sidebar(); ?>
</div>
</div>
I have a category.php with script inside:
<?php $categories = get_the_category(); ?>
<?php $category_id = $categories[0]->cat_ID; ?>
<?php query_posts('cat='.$category_id); ?>
<?php while (have_posts()) : ;?>
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div class="article">
<div class="article_image" style="background-image: url('<?php echo $image[0]; ?>')">
<i class="fa article_favourite"><?php wpfp_link() ?></i>
</div>
<h3><?php the_title(); ?></h3>
<div class="article_subheading_wrapper">
<p>
<!--Cut the long text -->
<?php
$string = substr(get_field("subheading"), 0, 100);
echo $string."… ";
?>
</p>
</div>
<div class="bottom">
<ul>
<li><p id="views"><img id="eye" src="<?php bloginfo('template_directory'); ?>/icons/watched_icon.svg"> <span><?php if(function_exists('the_views')) { the_views(); } ?></span></p></li>
<li><p id="likes"><i class="fa"></i><?php if(function_exists('like_counter_p')) { like_counter_p(''); }
?></p></li>
<li><p id="comments"><i class="fa fa-comment"></i> <?php comments_number( '0', '1', '%' ); ?></p></li>
</ul>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
It supposed to be displaying all the posts that belong to this category. I does, but it displays only recent one and infinite number of times.
What do I do wrong?
PLEASE PLEASE PLEASE, don't use query_posts, it is evil. Rather use WP_Query
Try either of this,
get_posts('cat=3&posts_per_page=-1');
or
query_posts( array ( 'cat' => cat_id, 'posts_per_page' => -1 ) );
Hope this helps you