Ajax Load More and conditional loop - php

I am trying to set up a wordpress. For my blog page, I displayed items differently depending on the position of the article (first line) and content (quote or article with image). It does the job.
<?php $post_counter = 0; // START COUNTDOWN ?>
<?php if ( have_posts() ) : ?>
<?php query_posts('category_name=blog'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_counter++; // COUNTDOWN FOR EACH POST ?>
<!-- IF FIRST POST -->
<?php if ( $post_counter == 1 ) : ?>
<div class="first">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div style="background-image:url('<?php echo $url; ?>')" class="fullimg">
</div>
<a href="<?php the_permalink() ?>">
<?php the_title() ?>
<?php echo get_the_date( 'd/m/Y' ); ?>
</a>
</div>
<?php endif; ?>
<!-- IF NOT FIRST POST -->
<?php if ( $post_counter != 1 ) : ?>
<!-- IF NOT FIRST POST AND IS A QUOTE -->
<?php if ( has_post_format( 'quote' )) : ?>
<div class="quote">
<?php the_content() ?>
<?php echo get_the_date( 'd/m/Y' ); ?>
</div>
<?php endif; ?>
<!-- IF NOT FIRST POST AND IS NOT A QUOTE -->
<?php if ( !has_post_format( 'quote' )) : ?>
<div class="noquote">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div style="background-image:url('<?php echo $url; ?>')" class="fullimg">
</div>
<a href="<?php the_permalink() ?>">
<?php the_title() ?>
<?php echo get_the_date( 'd/m/Y' ); ?>
</a>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
But now I want to integrate a load more, why I use the plugin "ajax load more". When I insert my hook into the template and the plugin integrates the shortcode, the button appears but nothing happens. Ideas ?

Related

How do i only display posts with a certain category?

So I'm building a website for my new business.
An I want to only run the following code if the post have a category of 'certain-category'.
How do I do this? I tried a number of things. but they do not work..``
<article id="post-<?php the_ID(); ?>" <?php post_class(''); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<a href="<?php the_permalink(); ?>" class="H1-posts" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('moesia-thumb'); ?>
</a>
</div>
<?php endif; ?>
<?php if (has_post_thumbnail()) : ?>
<?php $has_thumb = ""; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="post-content <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
<?php if ( 'post' == get_post_type() ) : ?>
<?php endif; ?>
</header><!-- .entry-header -->
<div class="entry-summary">
<?php if ( (get_theme_mod('full_content') == 1) && is_home() ) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
</div><!-- .entry-content -->
Use has_category()
if(has_category('certain-category', get_the_ID())):
// Do something
endif;
WordPress now has a native block which does this for you if you want the easy route the block is called Post and Page Grid it allows you to select what category of posts or pages it will show and you can select what information is shown e.g. Title, thumbnail, excerpt etc

How to create an image slide with php?

I am using a plugin on WordPress and I need to customise the php. This is the page: https://levels-ventures.com/buying/ and instead of one image displaying I would like this to be a slider.
This is the code I have:
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="es-property-inner">
<div class="es-property-thumbnail">
<div class="es-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php if ( ! empty( $es_property->gallery ) ) : ?>
<?php es_the_post_thumbnail( 'es-image-size-archive' ); ?>
<?php elseif ( $image = es_get_default_thumbnail( 'es-image-size-archive' ) ) : ?>
<?php echo $image; ?>
<?php else: ?>
<div class="es-thumbnail-none">
<?php if ( ! $es_property->get_labels_list() ) : ?>
<?php _e( 'No image', 'es-plugin' ); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ( $es_settings->show_labels ) : ?>
<ul class="es-property-label-wrap">
<?php foreach ( $es_property->get_labels_list() as $label ) : $value = $es_property->{$label->slug}; ?>
<?php if ( ! empty( $value ) ) : ?>
<li class="es-property-label es-property-label-<?php echo $label->slug; ?>"
style="color:<?php echo es_get_the_label_color( $label->term_id ); ?>"><?php _e( $label->name, 'es-plugin' ) ; ?></li><br>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if ( ! empty( $es_property->gallery ) && is_array( $es_property->gallery ) ) : ?>
<div class="es-thumbnail-bottom"><?php echo count( $es_property->gallery ); ?></div>
<?php endif; ?>
</a>
</div>
</div>
Does anything know how to change this so instead of displaying one image it displayes a slider of images?
Thanks for your help!!
Use Bootstrap's Carousel. Very simple to implement with slider. Please refer to their official website Carousel

How to target a specific query from functions.php in Wordpress

I'm trying to use offset on a specific WP_Query on a page that has a total of 3 Loops with the code described here.
For now, this works but I can only target all three loops. What (I think) I have to do is change this part:
//Before anything else, make sure this is the right query...
if ( ! $query->is_posts_page ) {
return;
}
To something like this:
//Before anything else, make sure this is the right query...
if ( ! $query->$THELOOPIWANTTOTARGET ) {
return;
}
Is there a way to do this?
The query:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$mainloop = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged));
?>
<div class="full padding center isotope">
<?php if ( $mainloop->have_posts() ) : while ( $mainloop->have_posts() ) : $mainloop->the_post(); ?>
<article class="post">
<?php the_post_thumbnail(); ?>
<div class="textwrap">
<h2><?php the_title(); ?></h2>
<?php if ( get_field('bron')): ?>
<?php if ( get_field('bron')): ?><a href="<?php the_field('bron_link'); ?>" target="_blank" class="source"><?php endif; ?>
<?php the_field('bron'); ?>
<?php if ( get_field('bron')): ?></a><?php endif; ?>
<?php endif; ?>
<?php the_excerpt(); ?>
</div>
<div class="readmore">
<div class="fa fa-share share" id="<?php the_ID(); ?>">
<div class="share_block"><div class="addthis_sharing_toolbox" data-url="<?php the_permalink(); ?>"></div></div>
</div>
Lees verder
</div>
</article>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>

Having trouble displaying custom post meta via a short code in a WordPress plugin

I've created a plugin that sets up a custom post type ('Programmes'), taxonomy and a short code to display the custom posts. I'm trying to display a custom post meta field (Broadcast Date) via the shortcode. These are the methods I've tried so far:
This is the method I'd have preferred as it allows me to use it for multiple meta values:
if ( $query->have_posts() ) { ?>
<div class="schedule-container">
<?php while ( $query->have_posts() ) : $query->the_post();
$programmeImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
$programmeMeta = get_post_meta($post->ID,'_meta_content',TRUE);
?>
<div id="programme-<?php the_ID(); ?>" <?php post_class(); ?> style="background-image: url( <?php echo $programmeImage ?> )">
<div class="schedule-titlebar">
<h3><?php the_title(); ?></h3>
<p><?php echo $programmeMeta['broadcast-date'] ?></p>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
</ul>
}
But that didn't work so I tried this instead:
if ( $query->have_posts() ) { ?>
<div class="schedule-container">
<?php while ( $query->have_posts() ) : $query->the_post();
$programmeImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
$programmeBroadcastDate = get_post_meta($post->ID,'broadcast-date',TRUE);
?>
<div id="programme-<?php the_ID(); ?>" <?php post_class(); ?> style="background-image: url( <?php echo $programmeImage ?> )">
<div class="schedule-titlebar">
<h3><?php the_title(); ?></h3>
<p><?php echo $programmeBroadcastDate ?></p>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
</ul>
}
and that doesn't work either!
Any ideas? Thanks

pagination custom post type with multiple WP_Query loop

after adding the function of pagination to Functions.php and recall it in template-product-listing.php
there is nothing shown in result.
I have a big problom with this...
could you find and resolve the problem?
thnx
<article class="row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="single-head" class="sixteen columns">
<h1><?php the_title(); ?></h1>
<?php if (has_excerpt()) { the_excerpt(); } ?>
</div>
<div class="row">
<nav id="portfolio-filters" class="sixteen columns">
<?php _e('Show All', 'ci_theme'); ?>
<?php
$args = array(
'hide_empty' => 0
);
$skills = get_terms('product-category', $args);
?>
<?php foreach ( $skills as $skill ) : ?>
<?php echo $skill->name; ?>
<?php endforeach; ?>
</nav><!-- /portfolio-filters -->
</div>
<div id="portfolio-items" class="row">
<?php $ci_product_query = new WP_Query('post_type=product&posts_per_page=4'); ?>
<?php if ( $ci_product_query-> have_posts() ) : while ( $ci_product_query->have_posts() ) : $ci_product_query->the_post(); ?>
<?php $item_skills = wp_get_object_terms($post->ID, 'product-category'); ?>
<article class="<?php ci_e_setting('product_columns'); ?> columns <?php foreach ( $item_skills as $item_skill ) : echo $item_skill->slug.' '; endforeach; ?> columns portfolio-item">
<a href="<?php echo get_permalink(); ?>" title="<?php echo esc_attr(get_the_title()); ?>" class="fb">
<?php the_post_thumbnail('ci_portfolio_slider', array('class'=>'scale-with-grid')); ?>
</a>
<div class="portfolio-desc">
<h3><?php the_title(); ?></h3>
<p class="desc"><?php echo mb_substr(get_the_excerpt(), 0, 70); ?>...</p>
</div>
</article><!-- /portfolio-item -->
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
</div><!-- /portfolio-items -->
<?php get_template_part('part', 'call_to_action'); ?>
<?php endwhile; endif; ?>
<div class="pagination">
<?php wp_pagination(); ?>
</div>
</article>
if your sure there is a post_type called products and there is posts in it...
try:
<div id="portfolio-items" class="row">
<?php $ci_product_query = new WP_Query(array('post_type'=>'product', 'posts_per_page'=> 4); ?>
<?php if ( $ci_product_query-> have_posts() ) : while ( $ci_product_query->have_posts() ) : $ci_product_query->the_post(); ?>
You know you are starting a new wp_query for every post in have_posts() ? you might want to rethink what you are trying to achieve!

Categories