Load more for custom query wp - wordpress

how can i integrate load more button that loads next 10 posts from custom query ?
I've tried with bunch of plugins, css and js ways, but can't seem to load it.
How would you load more posts on load click?
Any tip is very much appreaciated
<div class="container">
<div class="row featured-akcije">
#foreach(get_field('actions') as $action)
#php($query = new WP_Query(array('post_type' => 'condo', 'p' => $action['akcions']->ID)))
#php($query->the_post())
<div class="col-md-4 col-xl-3 action">
<div class="box-shadow-posts hoverPic">
<div class="row">
<div class="col-12 col-md-12">
<div class="row">
<div class="col-4 col-md-6 col-xl-6">
<div class="action-img">
<img src="{{ get_the_post_thumbnail_url() }}" class="img-fluid">
<p class="action">action</p>
</div>
</div>
<div class="col-8 col-md-6 pl-md-0">
<div class="row info-action">
<div class="col-md-12"><h2 class="title">
{{ the_title() }}
</h2></div>
<div class="col-md-12 price-info">
<div class="divider">
</div>
<?php if( get_field('price_off') ): ?>
<p class="price">price from <?php the_field('price_from'); ?>e</p>
<?php endif; ?>
<p class="detail"><a href="{{ the_permalink() }}"><span class="nav-border"></span><span>detail <i
class="fas fa-arrow-right"></i></span></a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#php(wp_reset_postdata())
#endforeach
</div>
</div>

I implemented load more functionality for custom query like this:
Create wp ajax endpoint which is called be javascript on load more button click
Endpoint gets offset which post to load? For example from 11 to 20 and returns html with rendered posts
Javascript appends return html to html of the page in proper place
How to create endpoint? Here are examples for creating endpoint and calling it from javascript: https://codex.wordpress.org/AJAX_in_Plugins In endpoint you should call fetching posts like this: $query = new WP_Query(array('post_type' => 'condo', 'p' => $action['akcions']->ID)) with proper offset passed in params, render html template and return it.

Related

Custom taxonomy terms not printing in order

I have multiple custom taxonomies in custom post type. I am printing the custom posts with their multiple taxonomies in loop. I am able to done that. But the taxonomies are printing in random order like this:
This is what printing in loop:
As you can see some data of job type is printing in Company field, Some company is printing in Skills field. How can i print them in order.
Here is my code:
$args=array("post_per_page"=>-1,"post_type"=>"jobs");
$loop=new WP_Query($args);
if($loop->have_posts()){
while($loop->have_posts()):$loop->the_post();
$custom_terms=wp_get_object_terms(get_the_ID(),array('companies','job-type','skills'),array('orderby' => 'name', 'order'=>'ASC','fields'=>'all'));?>
<div class="col-md-12" style="box-shadow:0px 3px 5px 2px #f4f4f4;margin:10px;background:#fff;">
<div class="media col-md-3" style="margin-top:2%;">
<figure class="pull-left">
<?php the_post_thumbnail('small',array('class'=>'media-object img-rounded img-responsive'));?>
<h5 class="list-group-item-heading" style="font-weight: 400;color: #0db294;margin-bottom:3%;border-bottom:1px solid rgb(98,59,204,0.1);padding:5px;"><?php echo the_title();?> </h5>
</figure>
</div>
<div class="col-md-6" style="margin-top:3%;">
<div class="col-md-4 col-xs-12 text-center b-right"><label style="color: #0db294;">Company</label><br/><span style="text-transform:capitalize"><?php echo $custom_terms[1]->name;?></span></div>
<div class="col-md-4 col-xs-12 text-center b-right"><label style="color: #0db294;">Job Type</label><br/><?php echo $custom_terms[0]->name;?></div>
<div class="col-md-4 col-xs-12 text-center"><label style="color: #0db294;">Skills</label><br/><?php echo $custom_terms[2]->name;?></div>
</div>
<div class="col-md-3 col-xs-12 text-center"><br/>
View Details
</div>
</div>
<?php endwhile;
}
Use get_the_term_list to get all terms for specific taxonomy. You can also modify this to get first one if there are multiple ones.
Like this ID, 'companies', 'Company: ', ', ' ); ?>
You are getting all and ordering by name then getting by position. That is causing issues. Get each one like this manually.
Here is the solution as #boris suggested
$args=array("post_per_page"=>-1,"post_type"=>"jobs");
$loop=new WP_Query($args);
if($loop->have_posts()){
while($loop->have_posts()):$loop->the_post();
$comp=get_the_term_list(get_the_ID(),'companies','',',');
$jobt=get_the_term_list(get_the_ID(),'job-type','',',');
$skil=get_the_term_list(get_the_ID(),'skills','',',');
?>
<div class="col-md-12 col-xs-12" style="margin:10px;background:#fff;margin-left:0;">
<div class="media col-md-4 col-xs-12" style="margin-top:2%;">
<figure class="pull-left">
<!-- <img class="media-object img-rounded img-responsive" src="" alt="placehold.it/350x250" style="height:70px;width:auto;margin:0 auto" > -->
<h2 class="list-group-item-heading" style="font-weight: 400;font-size:19px;color: #2A5A8E;margin-bottom:3%;padding:5px;"><?php echo the_title();?> </h2>
</figure>
</div>
<div class="col-md-6" style="margin-top:3%;">
<div class="col-md-4 col-xs-12 text-center b-right"><label style="color: #0db294;">Company</label><br/><span style="text-transform:capitalize"><?php echo $comp;?></span></div>
<div class="col-md-4 col-xs-12 text-center b-right"><label style="color: #0db294;">Job Type</label><br/><?php echo $jobt;?></div>
<div class="col-md-4 col-xs-12 text-center"><label style="color: #0db294;">Skills</label><br/><?php echo $skil;?></div>
</div>
<div class="col-md-2 col-xs-12 text-center"><br/>
View Details
</div>
</div>
<?php endwhile;
}
?>

Screen goes white when setting home display to static on server site (Wordpress)

:)
I have made a Wordpress site, which I have migrated from local to a server. I have created a one pager with images in the bottom that links to the different post of my site. I have used the plugin Advanced custom fields in order to make my site editable.
After a lot of searching online, I found that it was not possible to add custom fields to your index php directly but that you could make a template in which you copied all your old code from the index.php into.
I got it to work on my local host by going to Settings - Readings in my wordpress admin panel an under set my homepage displays as static - Homepage (which is the name of my template).
But when I try to do the same thing on the server site, the screen goes white... Maybe it is something with the file structure?
I've taken a screen shot of whole the files are located in my FTP (Cyberduck). I don't know if its enough to help..
Thanks in advance
<div class="section" id="section2">
<div class="row">
<div class="col-12 col-md-6 col-lg-6" id="left">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/imgs/pen.png" id="pen" class="img-fluid animation" alt="Responsive-image"/>
<lol><h2 id="About">3 Facts</h2></lol>
</div>
<div class="col-12 col-md-6 col-lg-6" id="right">
<div class="image_field d-none d-md-block"> <!-- image field-->
<?php $post_image = get_field('avatar_image')['sizes']['large']; ?>
<img src = "<?php echo $post_image; ?> " id="avatarimage" class="img-fluid" alt="Responsive image">
</div>
<div class="col-md-12 col-lg-12">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/imgs/Onefinal.svg" id="One"/> <!-- class="img-fluid" alt="Responsive-image" -->
<div class="container" id=text>
<?php
$my_query = new WP_Query('pagename=hej');
while ($my_query->have_posts() ) : $my_query->the_post();
the_content();
endwhile;
wp_reset_postdata();
?>
</div>
</div>
Template of the static homepage should be stored in a file called front-page.php which needs to be placed in /wp-content/themes/elnino directory.
Copy code of your template (except comment with template name) and paste it inside front-page.php file.
<div class="section" id="section2">
<div class="row">
<div class="col-12 col-md-6 col-lg-6" id="left">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/imgs/pen.png" id="pen" class="img-fluid animation" alt="Responsive-image" />
<lol>
<h2 id="About">3 Facts</h2>
</lol>
</div>
<div class="col-12 col-md-6 col-lg-6" id="right">
<div class="image_field d-none d-md-block">
<!-- image field-->
<?php $post_image = get_field('avatar_image')['sizes']['large']; ?>
<img src="<?php echo $post_image; ?> " id="avatarimage" class="img-fluid" alt="Responsive image">
</div>
<div class="col-md-12 col-lg-12">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/imgs/Onefinal.svg" id="One" />
<!-- class="img-fluid" alt="Responsive-image" -->
<div class="container" id=text>
<?php
$my_query = new WP_Query('pagename=hej');
while ($my_query->have_posts() ) : $my_query->the_post();
the_content();
endwhile;
wp_reset_postdata();
?>
</div>
</div>

I want to add load more button for particular custom post type in wordPress. Post display when click on the button

Here is the code of PHP and file save as an aboutus.php. Now please tell me that I want to add load more button for particular custom post type in WordPress. Post display when clicking on the button
<div class="container">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h2>News & Announcements</h2>
</div>
<?php
$args = array('post_type' => 'news','showposts'=>6, 'order'=>'ASC');
$query = new wp_query ($args);
while( $query->have_posts() ): $query->the_post() ;
$img = wp_get_attachment_url(get_post_thumbnail_id($result->ID));
?>
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 news">
<figure><img src="<?php echo $img; ?>"></figure>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div>
<div class="container">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h4>
<a id="toggle">Show more</a>
</h4>
</div>
</div>
</div>
You will have to add an event listeren with javascript to listen to the 'click' event on the #toggle button, make an ajax request to fetch the next post(s) and append the post(s) to the post on success.
This helped me in the beginning with making ajax requests: https://premium.wpmudev.org/blog/using-ajax-with-wordpress/

how to use FOSCommentBundle

Im new to symfony3 and I need a bit of help,I have a timeline page that contains posts and every post has a comment field so in order to do that I've installed the FOSCommentBundle following all the steps in this documentation https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Resources/doc/index.md and then I integrated it with the FOSUserBundle, and I did the following changes in the async.html.twig file :
<div id="fos_comment_thread">#comments</div>
<script type="text/javascript">
// thread id
var fos_comment_thread_id = 'pub';
// api base url to use for initial requests
var fos_comment_thread_api_base_url = 'localhost/Outdoors5/web/app_dev.php/threads';
// Snippet for asynchronously loading the comments
(function() {
var fos_comment_script = document.createElement('script');
fos_comment_script.async = true;
fos_comment_script.src = '{{ asset('bundles/foscomment/js/comments.js') }}';
fos_comment_script.type = 'text/javascript';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(fos_comment_script);
})();
</script>
but in the end I got very confused on how I use this ,I passed hours trying to understand and searching for tuto, but no luck.
this is my view
<section id="timeline">
{% for publication in publications %}
<div id="result"></div>
<div class="page-content page-app page-profil " >
<div class="profil-content">
<div class="row">
<div class="row">
<div class="item item-comment">
<div class="user">
<h5 class="name">{{ publication.idProfil.nom }}</h5>
<div class="clearfix">
<p class="time">{% if publication.dateCreation %}{{ publication.dateCreation|date('Y-m-d') }}{% endif %}</p>
</div>
<div class="comment">
<p class="c-primary m-b-0"><strong>{{ publication.texte }}</strong></p>
</div>
</div>
<div class="more">
<div class="row">
<div class="col-sm-4 like">
<i class="fa fa-heart"></i> Like
</div>
<div class="col-sm-4 more-comments">
<div class="comment-number">
<i class="icon-bubble"></i> Comments<span class="pull-right badge badge-dark">3</span>
</div>
</div>
<div class="col-sm-4 more-share">
<i class="icon-share"></i> Share
</div>
</div>
<div class="row comments">
<div class="col-sm-12">
<ul>
<li class="clearfix">
<div class="clearfix">
<div class="info">
<div class="name"><strong class="primary-font"></strong></div>
<div class="date"></div>
</div>
<p>
comment 1
</p>
</div>
</li>
<li></li>
</ul>
</div>
</div>
<div class="row share">
<div class="share-facebook">
<i class="fa fa-facebook"></i>
</div>
<div class="share-twitter">
<i class="fa fa-twitter"></i>
</div>
<div class="share-google">
<i class="fa fa-google-plus"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</section>
Could you point me to the right direction?
thank you
There is no need to modify async.html.twig. You just need to add the following code in your twig view:
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
To sum up, after doing the following steps:
Step 1: Setting up the bundle
Step 2: Create your Comment and Thread classes
Step 3: Import FOSCommentBundle routing
Step 4: Enable comments on a page
For the FOSUserBundle integration you just have to extend the Comment class as explained in Step 6: Integration with FOSUserBundle

Codeception Symfony click issue

I am working on an acceptence test to see if I can go from homepage to categories however no matter what I try I does see the link but I can't click it.
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('I click category');
$I->amOnPage('/');
$I->seeLink('Categories', '/categories');
$I->click('category');
?>
The HTML:
<div class="col s12 m4">
<a href="/categories" >
<div class="card">
<div class="card-content">
<div class="teal-text center-align" name="category">
Categories
</div>
</div>
</div>
</a>
</div>
</div>
I don't know if Codeception is looking for the 'name' attribute of html tag. Rather than this, you should try other ways of use of click method: http://codeception.com/docs/03-AcceptanceTests#Click
Also you can try this:
$I->click(['name' => 'category']);

Resources