Masonry + Infintine scroll implementation problems - wordpress

I managed to implement infinite scroll with masonry in WordPress and it's working but I have a couple of bugs:
The posts are supposed to be opened in ajax, but it's not working for the added items now, only for the first few ones.
After all the posts are displayed the console outputs the error:
GET http://www.jcvergara.com/working/page/3/?_=1431138637809 404 (Not Found).
I'm not sure what it is related to. I would appreciate any ideas how to fix it.
Here is my code:
<div class="main">
<div id="content" class="container">
<div class="right-line"></div>
<!-- List of categories, only on the first page -->
<?php
$cur_url = $_SERVER['REQUEST_URI'];
if ($cur_url == '/working/') {
echo '<div class="item tags">';
echo '<div class="item-title">';
echo '<span class="tag">Tags</span>';
echo '<ul><li>All</li>';
wp_list_categories('orderby=term_group&title_li=');
echo '</ul></div></div>';
}
?>
<!-- Posts -->
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $category = get_the_category(); ?>
<div class="item <?php echo $category[0]->slug; ?>">
<a class="mask post-link" rel="<?php the_ID(); ?>" href="<?php the_permalink(); ?>"></a>
<div class="item-title">
<span class="tag">
<?php echo $category[0]->cat_name; ?>
</span>
<h4><?php the_title(); ?></h4>
</div>
<div class="item-img">
<?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="thumb" style="background-image: url('<?php echo $image[0]; ?>'); "></div>
<?php endif; ?>
</div>
<div class="item-text">
<?php the_excerpt(); ?>
<span class="more">Read more...</span>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<div class="clear"></div>
</div>
<?php the_posts_navigation(); ?>
</div>
The code for opening posts in ajax:
$(document).ready(function(){
$.ajaxSetup({cache:false});
$('.post-link').click(function(){
$('.openarticle').css('display', 'block');
var post_link = $(this).attr('href');
$('#openthis').html('<div class="title"><h2>Loading..</h2><div class="text"></div>');
$('#openthis').load(post_link);
$('<a></a>', {
text: 'Close',
class: 'close',
id: 'close',
href: '#'
})
.prependTo($('.openarticle .main'))
.click(function() {
$('.openarticle').css('display', 'none');
$('#close').remove();
});
return false;
});
});
Here is the link: http://www.jcvergara.com/working/
Thanks in advance.

You need to add the code for opening your posts in infinite-scroll's callback function. (BTW, You should actually include the specific code for infinite-scroll and your code to open the post in your question, not just give a link.)
Here is the part of the infinite-scroll code that should help:
function( newElements ) {
var $newElems = $( newElements );
$container.masonry( 'appended', $newElems );
//add this to your code
$('.post-link').click(function(){
$('.openarticle').css('display', 'block');
var post_link = $(this).attr('href');
$('#openthis').html('<div class="title"><h2>Loading..</h2><div class="text"></div>');
$('#openthis').load(post_link);
$('<a></a>', {
text: 'Close',
class: 'close',
id: 'close',
href: '#'
})
.prependTo($('.openarticle .main'))
.click(function() {
$('.openarticle').css('display', 'none');
$('#close').remove();
});
return false;
});
}
Your error message relates to there not being a page 3 to load by infinitescroll

Related

WP_Query change code

In my theme WordPress to display the post uses this (code #1):
function inner($posts, $td_column_number = '') {
$buffy = '';
if (!empty($posts)) {
foreach ($posts as $post) {
$td_module_17 = new td_module_17($post);
$buffy .= $td_module_17->render($post);
}
}
return $buffy;
}
I need to show posts using this code (code #2):
<?php
$custom_query = new WP_Query('posts_per_page= 5');
while($custom_query->have_posts()):
$custom_query->the_post();
?>
<div class="post-1">
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h3><?php the_title(); ?></h3>
<div class="float-tags">
<div class="bb-td-post-small-box clearfix">
<?php the_tags('','',''); ?>
</div>
</div>
<div class="post-2">
<?php the_content(); ?>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_postdata(); // reset the query
?>
If I insert code #2 into module 17, then the posts are output immediately all in one block, and not one at a time.
Solved a problem. The code was looped. Here is the working code.
<?php
class td_module_17 extends td_module {
function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}
function render($Post = false) {
ob_start();
?>
<div class="post-1">
<div
<?php //post_class(); ?> id="post-<?= $Post->ID; ?>">
<h3><?= $Post->post_title; ?> </h3>
<div class="float-tags">
<div class="bb-td-post-small-box clearfix">
<?php $tags = get_the_tags($Post->ID); ?>
<? foreach ($tags as $tag) : ?>
<?= $tag->name; ?>
<? endforeach; ?>
</div>
</div>
<div class="post-2">
<?= apply_filters('the_content', $Post->post_content); ?>
</div>
</div>
</div>
<?php return ob_get_clean();
}
}

Wrap every 3 divs in a divs

This show 3 image at a time and move left 3 images at a time this is my problem. I want that show 3 images at a time and move left only one at a time. For Example, 4 image add it and three show at a time and when move one image then also show three image at a time. And then move one and than also show three images like http://wmh.github.io/jquery-scrollbox/ Example No 5 and 6...*
Note: $Cat_ID is categories..
<div class="cat-box-content">
<?php if($cat_query->have_posts()): ?>
<div id="slideshow<?php echo $Cat_ID ?>" class="group_items-box">
<?php while ( $cat_query->have_posts() ) : $cat_query->the_post()?>
<div <?php tie_post_class('scroll-item'); ?>>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php //the_post_thumbnail( 'thumbnail' ); ?>
<?php tie_thumb( 'tie-large' ); ?>
<span class="overlay-icon"></span>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<h3 class="post-box-title"><?php the_title(); ?></h3>
<p class="post-meta">
<?php if( tie_get_option( 'box_meta_score' ) ) tie_get_score(); ?>
<?php if( tie_get_option( 'box_meta_date' ) ) tie_get_time() ?>
</p>
</div>
<?php endwhile;?>
<div class="clear"></div>
</div>
<div id="nav<?php echo $Cat_ID ?>" class="scroll-nav"></div>
<?php endif; ?>
</div>
JQuery Function :
<script type="text/javascript">
jQuery(document).ready(function() {
var vids = jQuery("#slideshow<?php echo $Cat_ID ?> .scroll-item");
for(var i = 0; i < vids.length; i+=3) {
vids.slice(i, i+3).wrapAll('<div class="group_items"></div>');
}
jQuery(function() {
jQuery('#slideshow<?php echo $Cat_ID ?>').cycle({
fx: 'scrollHorz',
timeout: 3000,
pager: '#nav<?php echo $Cat_ID ?>',
slideExpr: '.group_items',
speed: 1000,
pause: true
});
});
});
</script>

Wordpress Custom user Display Page

First I want to preface this with the page was working this morning and I left the page open and came back to the information of the user not displaying at all
This page is a custom written authors display page. Anyone who is a contributor of the site is listed here with a bio, Avitar and nickname, can someone please tell me what I am missing because I can't see what has been deleted.
<?php
/*
Template Name: Display Authors
*/
// Get all users order by amount of posts
$allUsers = get_users('orderby=post_count&order=DESC');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(in_array( 'contributor', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
?>
<?php get_header(); ?>
<section class="content-area" role="main">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="authors">
<?php foreach($users as $user) { ?>
<div class="page-author author-<?php echo ($curauth->ID & 1 ? 'odd' : 'even'); ?>">
<div class="author-avatar">
<?php echo get_avatar( $curauth->user_email, '200' ); ?>
</div>
<div class="author-info">
<h2 class="author-name"><?php echo $curauth->first_name . ' ' . $curauth->last_name; ?></h2>
<h3 class="author-username"><?php echo $curauth->nickname; ?></h3>
</div>
<div class="clearfix"></div>
<p class="author-descrption"><?php echo get_user_meta($curauth->ID,'description', true); ?></p>
</div>
<?php
}
?>
</div>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
UPDATE:
So here is an update in my code, and still no luck, all the user information on the page remains empty. So its not showing the Name, Nickname, Bio...nothing
<?php
/*
Template Name: Display Authors
*/
// Get all users order by amount of posts
$allUsers = get_users('orderby=post_count&order=DESC');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(in_array( 'contributor', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
?>
<?php get_header(); ?>
<section class="content-area" role="main">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="authors">
<?php foreach($users as $user): ?>
<div class="page-author author-<?php echo ($curauth->ID & 1 ? 'odd' : 'even'); ?>">
<div class="author-avatar">
<?php echo get_avatar( $curauth->user_email, '200' ); ?>
</div>
<div class="author-info">
<h2 class="author-name"><?php echo $curauth->first_name . ' ' . $curauth->last_name; ?></h2>
<h3 class="author-username"><?php echo $curauth->nickname; ?></h3>
</div>
<div class="clearfix"></div>
<p class="author-descrption"><?php echo get_user_meta($curauth->ID, 'description', true); ?></p>
</div>
<?php endforeach; ?>
</div>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Wordpress Loop target individual item hover

Have got stuck on this little problem, managed to get my Wordpress looping with the correct stuff.. and all works fine. the problem i have got is when i try to target the individual item on hover. Ive got my jquery script working but it targets them all.. I know ive got to to change the loop but not sure what im surpose to do.. heres my code anyway. Would be great if you guys could help.. Thanks
Wordpres Loop
<?php $i = 0 ?>
<?php query_posts('showposts=3'); ?>
<?php if(have_posts()) : while (have_posts()) : the_post(); ?>
<?php if( $i == 3 ) : ?>
<div class="row">
<?php endif; ?>
<div class="col-lg-4 col-md-4">
<a href="<?php the_permalink(); ?>">
<div class="miniwork">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<figcaption><?php the_title(); ?></figcaption>
</div>
</a>
</div>
<?php $i++ ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
Jquery Hover
jQuery(".miniwork" ).hover(
function() {
jQuery('.miniwork figcaption').addClass('animated tada');
jQuery('.miniwork figcaption').css('visibility', 'visible');
var filterVal = 'blur(8px)';
jQuery('.miniwork img')
.css('filter',filterVal)
.css('webkitFilter',filterVal)
.css('mozFilter',filterVal)
.css('oFilter',filterVal)
.css('msFilter',filterVal);
jQuery('.miniwork figcaption').css('opacity', '0.95')
}, function() {
jQuery('.miniwork figcaption').removeClass('animated tada');
jQuery('.miniwork figcaption').css('visibility', 'hidden');
jQuery('.miniwork figcaption').css('visibility', 'hidden');
var filterVal = 'blur(0px)';
jQuery('.miniwork img')
.css('filter',filterVal)
.css('webkitFilter',filterVal)
.css('mozFilter',filterVal)
.css('oFilter',filterVal)
.css('msFilter',filterVal);
jQuery('.miniwork figcaption').css('opacity', '0')
}
);
You are targeting class "miniwork" which is being assigned to every div .. you can assign #id to each div too like --
<div class="miniwork" id="<?php echo get_the_ID(); ?>">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<figcaption><?php the_title(); ?></figcaption>
</div>
Now in jQuery taget 'miniwork#id-of-the-post'

the_author is empty when not logged in

Is there a reason why the_author should return an empty string on the first page when the user is not logged in, but return the author name just as it should when more posts are loaded through AJAX ?
The loop is the same in both cases.
Please help me resolve this issue as I'm clueless and I need it fixed ASAP to launch my site.
Here's the whole index.php:
<?php
get_header();
get_sidebar();
?>
<!-- MAIN DIV -->
<div id='content_and_floater'>
<?php get_template_part('social_floater'); ?>
<div id='content'>
<?php get_template_part('loop'); ?>
</div>
</div>
<?php get_template_part('loader'); ?>
<!-- MAIN DIV -->
<?php
get_footer();
?>
And here's how the infinitePaginator calls the loop in functions.php (the function is called when scrolled down to the bottom or the loader link is clicked):
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
# Load the posts
query_posts(array('paged' => $paged ));
get_template_part( $loopFile );
exit;
}
You can see the behaviour at test.nowillnoskill.net.
In single posts it's not working either. My guess is that query_posts(array('paged' => $paged )); changed something in the query, but I don't know what is it.
I tried to insert setup_postdata($post); just after the_post() in loop.php as I found that worked for someone, but it doesn't for me.
I also tried to insert
query_posts(array('paged' => 1 ));
before calling the loop file in index.php, but no posts at all were shown.
Here is my loop.php:
<?php while ( have_posts() ) : the_post() ?>
<!-- POST1 -->
<article class='post'>
<header class='post_header'>
<?php
global $current_user;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$pid = get_the_id();
$uid = $current_user->ID;
$title = (is_favorite($pid, $uid)) ?
'Remove from favorites' :
'Add to favorites';
$trans = (is_favorite($pid, $uid)) ?
'' :
' transparent';
?>
<div>
<h2>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if (is_user_logged_in()) { ?>
<a title='<?php echo $title ?>' class='post_favorite' href='#' alt='fpid=<?php echo $pid ?>uid=<?php echo $uid ?>'>
<span class='symbol<?php echo $trans ?>'>R</span>
</a>
<?php } ?>
</div>
<div class='post_header_div'>
<strong class='post_category'>
<?php echo get_the_category_list(', '); ?>
</strong>
<strong class='post_author'>
<span class='symbol'>U</span>
<?php the_author(); ?>
</strong>
</div>
<div>
<span class='post_author'>
<?php edit_post_link('[edit]'); ?>
</span>
</div>
<?php } ?>
</header>
<figure class='post_image'>
<!--<img src='design/img/flashkick.png' alt='logo' />-->
<?php the_post_thumbnail(); ?>
</figure>
<div class='post_perex'>
<?php the_content('Read more'); ?>
</div>
<div class='space'></div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime="<?php the_time('Y-m-d'); ?>" pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
</footer>
<div class='space'></div>
</article>
<?php endwhile; ?>
Author informations are given by Wordpress in post informations.
Try to do a var_dump on your query_posts result, you should find where the author name is stored, to display it properly.
Can you please show your loop template ? At least the part displaying the author.

Resources