Here is, index.php file from my template.
<?php get_header(); ?>
<div id="content">
<div id="content_inside">
<?php
wp_reset_query();
$get_blog_id = '-' . get_category_id('blog');
if(get_category_id('blog') != '') {
$args = array(
'post_type' => 'post',
'cat' => $get_blog_id,
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
);
} else {
$args = array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
);
}
query_posts($args);
$x = 0;
while (have_posts()) : the_post(); ?>
<?php if($x % 2 == 0) { ?>
<div class="post_box">
<?php } else { ?>
<div class="post_box post_box_right">
<?php } ?>
<?php if ($x == 0) { ?>
<h1><?php the_title(); ?></h1>
<?php } elseif ($x == 1 || $x == 2 || $x == 3) { ?>
<h2><?php the_title(); ?></h2>
<?php } elseif ($x == 4 || $x == 5) { ?>
<h3><?php the_title(); ?></h3>
<?php } else { ?>
<h3><?php the_title(); ?></h3>
<?php } ?>
<div class="post_meta"><?php the_author(); ?> / <?php the_time('d m , Y') ?> - <?php the_time('H:i'); ?> / <?php comments_popup_link('Yorum Yok', '1 Yorum', '% Yorum'); ?></div>
<div class="img_link">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('featured-home'); ?>
<?php
//$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'featured-home' );$url = $thumb['0'];
//$titleGet = get_the_title($post->ID);
//echo '<img src="'.CDN.'/assets/images/_load.png" alt="'.$titleGet.'" data-modafesto="'.$url.'" width="301" height="398" />';
?>
</a>
</div>
<div class="post_cat">
<?php
$category = get_the_category();
echo ''.$category[0]->cat_name.'';
?> konu başlığı ile yayınlandı.
</div>
</div><!--//post_box-->
<?php if($x % 2 == 1) { ?>
<div class="clear"></div>
<?php } ?>
<?php $x++; ?>
<?php endwhile; ?>
<div class="clear"></div>
</div><!--//content_inside-->
<div class="clear"></div>
<div class="load_more_cont">
<div style="margin:0px auto;"><div class="load_more_text"><?php next_posts_link('DİĞER YAZILARI YÜKLE') ?></div></div>
</div><!--//load_more_cont-->
<?php wp_reset_query(); ?>
</div><!--//content-->
<script type="text/javascript">$(".load_more_cont a").live("click",function(a){a.preventDefault();$(".load_more_text a").html("Yazılar Yükleniyor...");$.ajax({type:"GET",url:$(this).attr("href")+"#content",dataType:"html",success:function(b){result=$(b).find("#content_inside .post_box");nextlink=$(b).find(".load_more_cont a").attr("href");$("#content_inside").append(result);$(".load_more_text a").html("Daha fazla yazı yükle");if(nextlink!=undefined){$(".load_more_cont a").attr("href",nextlink)}else{$(".load_more_cont").remove();$("#content_inside").append('<div class="clear"></div>')}}})});</script>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I have tried to use, lazy load script for my images. Because it is a great choice for SEO Engines. That lines,
<div class="img_link">
<a href="<?php the_permalink(); ?>">
<?php
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'featured-home' );$url = $thumb['0'];
$titleGet = get_the_title($post->ID);
echo '<img src="'.CDN.'/assets/images/_load.png" alt="'.$titleGet.'" data-modafesto="'.$url.'" width="301" height="398" />';
?>
</a>
</div>
Also, here is my preloader script http://j.mp/12QkkTW .
When you load the page, first posts comes corectly with lazyload / preload but if you click load more posts button, when you get more posts the preloader doesnt work.
Can anyone help me ? Thank you.
try to add
$("XXXXXXX img").lazyload();
in ajax success callback funcion, after append html,
XXXXX is append html DOM, eq: class name or id
Related
So I have a php page in wordpress and when I add a part of the code it doesn't work. So to explain a bit more. I have a php template and most of it works, but when I add some additional code at the bottom that doesn't show up.
<?php get_header(); ?>
<div class="main_color container_wrap_first container_wrap">
<menu id="nav">
<ul><?php
$category_id = 2;
while( $category_id < 7 ) { ?>
<li>
<a href="<?php echo get_category_link( $category_id ); ?>">
<?php
$cat_id = $category_id;
echo get_cat_name( $cat_id );
$category_id++;
?>
</a>
</li>
<?php } ?>
</ul>
</menu>
<?php
$args = array(
'post_type' => 'projekti',
'posts_per_page' => -1,
'category' => '4',
);
$posts = get_posts($args);
if( $posts ):
$i = 1; ?>
<div class="custom-posts-grid">
<?php foreach($posts as $post): setup_postdata( $post ); ?>
<?php if( have_rows('logotipi') ): ?>
<?php while( have_rows('logotipi') ): the_row();
// vars
$image = get_sub_field('thumbnail_for_logotipi');
$content = get_sub_field('project_name');
$link = get_sub_field('url_logotipi');
$count = count($posts);
?>
<div class="post-grid-logotipi">
<a href="<?php echo $link; ?>">
<div class="post-title-hover"><?php echo $content ?></div>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" class="image-overlay-post" />
</a>
</div>
<?php
$i++;
if( $i == 6 ):
$i++;
?>
<div class="sodelujmo-post-grid"><div class="sodelujmo-post"><p class="sodelujmo-text">Vam je všeč,<br>kar vidite?<br>...<p><div class="button-bg"><a class="sodelujmo-link" href="../u3nek/sodelujmo/">Sodelujmo</a>
</div></div></div>
<?php
endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<!-- after this nothing I add can be shown -->
</div>
</div>
I have no idea what is wrong. So if anyone encountered anything similar before do let me know.
I have set up a query to query 80 posts per page on a day date basis but it doesn't load page 2 for me. It always says 404 error. I don't really know where I have gone wrong. This is the code.
<div class="mainvideoscon">
<div class="videosallcenter">
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => array('post','video', 'featured', 'spotlight'),
'paged' => $paged
);
$wp_query = new WP_Query($args);
if (have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
if ($current_date != get_the_date('d-m-Y')) {
echo '<div class="datetitlecon"><header class="datetitleh"><span class="datetitlehb"><i class="fa fa-clock-o"></i> ' . get_the_date('l ') . '</span>';
echo '' . get_the_date('dS M Y') . '</header></div>';
$current_date = get_the_date('d-m-Y');
}
?>
<div class="mvideocontv">
<a href="<?php the_permalink() ?>"><div class="mvideocontvfi">
<div class="gopostitem">
<?php
$posttype = get_post_type(get_the_ID());
if ($posttype == "post") {
echo '<img src="/wp-content/themes/justlooktv/images/gonews.png">';
}
if ($posttype == "video") {
echo '<img src="/wp-content/themes/justlooktv/images/play.png">';
}
if ($posttype == "spotlight") {
echo '<img src="/wp-content/themes/justlooktv/images/play.png">';
}
if ($posttype == "featured") {
echo '<img src="/wp-content/themes/justlooktv/images/play.png">';
}
?>
</div>
<div class="featuredimgblg"><?php the_post_thumbnail( 'ftimg-home' ); ?></div>
<?php if ('in_stock' == get_field('show_youtube_video')) { ?>
<img src="https://i.ytimg.com/vi/<?php the_field('youtube_video_id'); ?>/mqdefault.jpg" >
<?php } ?>
</div></a>
<div class="mvideodesccontv">
<div class="ppw"></div>
<?php short_title('...', 58); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="paginationcon">
<div class="paginationfocus">
<?php wp_pagenavi(); ?>
</div>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
Thanks for the help in advance
Try Replacing your $arg variable with this one.
$args = array (
'post_type' => array('post','video', 'featured', 'spotlight'),,
'post_status' => 'publish',
'pagination' => true,
'posts_per_page' => '80',
);
I have written a neat responsive slider for my Wordpress featured articles (feel free to use it):
<?php
$responsive = 'on' != get_option('henrik_responsive_layout') ? false : true;
$featured_auto_class = '';
if ( 'on' == get_option('henrik_slider_auto') ) $featured_auto_class .= ' et_slider_auto et_slider_speed_' . get_option('henrik_slider_autospeed');
?>
<div id="featured" class="<?php if ( $responsive ) echo 'flexslider' . $featured_auto_class; else echo 'et_cycle'; ?>">
<a id="left-arrow" href="#"><?php esc_html_e('Previous','henrik'); ?></a>
<a id="right-arrow" href="#"><?php esc_html_e('Next','henrik'); ?></a>
<?php if ( $responsive ) { ?>
<ul class="slides">
<?php } else { ?>
<div id="slides">
<?php } ?>
<?php global $ids;
$ids = array();
$arr = array();
$i=0;
$featured_cat = get_option('henrik_feat_cat');
$featured_num = (int) get_option('henrik_featured_num');
if (get_option('henrik_use_pages') == 'false') query_posts("showposts=$featured_num&cat=".get_cat_ID($featured_cat));
else {
global $pages_number;
if (get_option('henrik_feat_pages') <> '') $featured_num = count(get_option('henrik_feat_pages'));
else $featured_num = $pages_number;
query_posts(array
('post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => (array) get_option('henrik_feat_pages'),
'showposts' => (int) $featured_num
));
} ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
global $post; ?>
<?php if ( $responsive ) { ?>
<li class="slide">
<?php } else { ?>
<div class="slide">
<?php } ?>
<?php
$width = $responsive ? 960 : 958;
$height = 340;
$small_width = 95;
$small_height = 54;
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured');
$arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small');
$arr[$i]['titletext'] = $titletext;
$thumb = $thumbnail["thumb"];
print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?>
<div class="featured-top-shadow"></div>
<div class="featured-bottom-shadow"></div>
<div class="featured-description">
<div class="feat_desc">
<p class="meta-info"><?php esc_html_e('Posted','henrik'); ?> <?php esc_html_e('by','henrik'); ?> <?php the_author_posts_link(); ?> <?php esc_html_e('on','henrik'); ?> <?php the_time(esc_attr(get_option('henrik_date_format'))) ?></p>
<h2 class="featured-title"><?php the_title(); ?></h2>
<p><?php truncate_post(410); ?></p>
</div>
<?php esc_html_e('Read More', 'henrik'); ?>
</div> <!-- end .description -->
<?php if ( $responsive ) { ?>
</li> <!-- end .slide -->
<?php } else { ?>
</div> <!-- end .slide -->
<?php } ?>
<?php $ids[] = $post->ID; $i++; endwhile; endif; wp_reset_query(); ?>
<?php if ( $responsive ) { ?>
</ul> <!-- end .slides -->
<?php } else { ?>
</div> <!-- end #slides -->
<?php } ?>
</div> <!-- end #featured -->
<div id="controllers" class="clearfix">
<ul>
<?php for ($i = 0; $i < $featured_num; $i++) { ?>
<li>
<div class="controller">
<a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
<?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
<span class="overlay"></span>
</a>
</div>
</li>
<?php } ?>
</ul>
<div id="active_item"></div>
</div> <!-- end #controllers -->
It selects a custom category and returns a custom amount of posts. The problem is that it will display the posts in the order of which they were created. I want to choose my own order, so that I can select which posts displays first and so on.
So, is it possible to select which order the returned posts are displayed? Maybe by targeting specific IDs?
It looks like you're already doing this by using 'orderby' => 'menu_order'. All you need to do now is set the menu order in the WordPress interface -- all new posts default to 0. Or you change the orderby argument to something else.
I am trying to alter my Wordpress theme to display the latest posts from a specific tag. It currently lists the latest posts overall.
Here is part of the code that it uses:
<?php
if ( is_home() ) {
$args=array(
'showposts'=> (int) get_option('aggregate_homepage_posts'),
'paged'=>$paged,
'category__not_in' => (array) get_option('aggregate_exlcats_recent')
);
if (get_option('aggregate_duplicate') == 'false') {
global $ids;
$args['post__not_in'] = $ids;
}
query_posts($args);
global $paged;
}
$i = 0;
?>
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$i++;
$et_is_latest_post = ( $paged == 0 && ( is_home() && $i <= 2 ) ) || !is_home();
?>
<div class="post entry clearfix<?php if ( $et_is_latest_post ) echo ' latest'; ?>">
<?php
$thumb = '';
$width = $et_is_latest_post ? 170 : 67;
$height = $et_is_latest_post ? 110 : 67;
$classtext = 'post-thumb';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if($thumb <> '' && get_option('aggregate_thumbnails_index') == 'on') { ?>
<div class="thumb thumbcont">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span class="overlay"></span>
</a>
<a class="thumb<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" href="<?php bloginfo('url'); ?>/<?php echo $category[0]->category_nicename; ?>"><?php echo $category[0]->cat_name; ?></a>
</div> <!-- end .post-thumbnail -->
<?php } ?>
<h3 class="title"><?php the_title(); ?></h3>
<?php get_template_part('includes/postinfo'); ?>
<p class="postsummery">
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,20);
?>
</p>
<span><?php esc_html_e('Read More','Aggregate'); ?></span>
</div> <!-- end .post-->
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation','entry'); ?>
<?php } ?>
<?php else : ?>
<?php get_template_part('includes/no-results','entry'); ?>
<?php endif; wp_reset_query(); ?>
While doing some research, I found some details of how to do this:
http://codex.wordpress.org/Template_Tags/get_posts
However, my very limited knowledge of PHP coding and lack of understanding how my current code works with the examples provided, I cannot find a way to do it. Can you guide me?
You simple add 'tag'=>the tag u wanted listed, after array( at line3
why well cause that's the array containing the arguments that then will be passed to the get posts function that makes a call to the database, the arguments that you got to choose from can be find here http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
And the full code would look like so
<?php
if ( is_home() ) {
$args=array(
'showposts'=> (int) get_option('aggregate_homepage_posts'),
'paged'=>$paged,
'tag'=>"the tag u want shown",
'category__not_in' => (array) get_option('aggregate_exlcats_recent')
);
if (get_option('aggregate_duplicate') == 'false') {
global $ids;
$args['post__not_in'] = $ids;
}
query_posts($args);
global $paged;
}
$i = 0;
?>
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$i++;
$et_is_latest_post = ( $paged == 0 && ( is_home() && $i <= 2 ) ) || !is_home();
?>
<div class="post entry clearfix<?php if ( $et_is_latest_post ) echo ' latest'; ?>">
<?php
$thumb = '';
$width = $et_is_latest_post ? 170 : 67;
$height = $et_is_latest_post ? 110 : 67;
$classtext = 'post-thumb';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if($thumb <> '' && get_option('aggregate_thumbnails_index') == 'on') { ?>
<div class="thumb thumbcont">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span class="overlay"></span>
</a>
<a class="thumb<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" href="<?php bloginfo('url'); ?>/<?php echo $category[0]->category_nicename; ?>"><?php echo $category[0]->cat_name; ?></a>
</div> <!-- end .post-thumbnail -->
<?php } ?>
<h3 class="title"><?php the_title(); ?></h3>
<?php get_template_part('includes/postinfo'); ?>
<p class="postsummery">
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,20);
?>
</p>
<span><?php esc_html_e('Read More','Aggregate'); ?></span>
</div> <!-- end .post-->
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation','entry'); ?>
<?php } ?>
<?php else : ?>
<?php get_template_part('includes/no-results','entry'); ?>
<?php endif; wp_reset_query(); ?>
I am creating a wordpress template to query my custom post type posts by using tax_query. It works fine and I get the correct posts in page #1, but I see the same posts as seen at page #1 when I click page #2. What did i missing here? Thanks in advance.
<?php
get_header();
?>
<h1><?php
the_title();
?></h1> <hr> <br>
<div id="content" class="three_fourth <?php
echo of_get_option('blog_sidebar_pos');
?>">
<?php
?>
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'tax_query' => array(
array(
"taxonomy" => "wpdic-category",
"field" => "slug",
"terms" => "featured-charities",
"numberposts" => 5,
"paged" => $paged
)
)
);
$wp_query = new WP_Query($args);
?>
<?php
if ($wp_query->have_posts()):
while ($wp_query->have_posts()):
$wp_query->the_post();
?>
<article id="post-<?php
the_ID();
?>" <?php
post_class();
?>>
<header>
<h2><a href="<?php
the_permalink();
?>" title="<?php
the_title();
?>" rel="bookmark"><?php
the_title();
?></a></h2>
<?php
$post_meta = of_get_option('post_meta');
?>
<?php
if ($post_meta == 'true' || $post_meta == '')
{
?>
<div class="post-meta">
<div class="fleft"></div>
<div class="fright"></div>
</div><!--.post-meta-->
<?php
}
?>
</header>
<?php
$post_image_size = of_get_option('post_image_size');
?>
<?php
if ($post_image_size == '' || $post_image_size == 'normal')
{
?>
<?php
if (has_post_thumbnail())
{
echo '<a href="';
the_permalink();
echo '">';
echo '<div class="featured-thumbnail"><div class="img-wrap">';
the_post_thumbnail();
echo '</div></div>';
echo '</a>';
}
?>
<?php
}
else
{
?>
<?php
if (has_post_thumbnail())
{
echo '<a href="';
the_permalink();
echo '">';
echo '<div class="featured-thumbnail large"><div class="img-wrap"><div class="f-thumb-wrap">';
the_post_thumbnail('post-thumbnail-xl');
echo '</div></div></div>';
echo '</a>';
}
?>
<?php
}
?>
<div class="post-content">
<?php
$post_excerpt = of_get_option('post_excerpt');
?>
<?php
if ($post_excerpt == 'true' || $post_excerpt == '')
{
?>
<div class="excerpt"><?php
$excerpt = get_the_excerpt();
echo my_string_limit_words($excerpt, 52);
?></div>
<?php
}
?>
<div id="widget_my_contentwidget"><ul><li><a class="link" href="<?php
the_permalink();
?>"> read more</a></li></ul></div>
<hr>
</div>
</article>
<?php
endwhile;
else:
?>
<div class="no-results">
<p><strong>There has been an error.</strong></p>
<p>We apologize for any inconvenience, please <a href="<?php
bloginfo('url');
?>/" title="<?php
bloginfo('description');
?>">return to the home page</a> or use the search form below.</p>
<?php
get_search_form();
?> <!-- outputs the default Wordpress search form-->
</div><!--noResults-->
<?php
endif;
?>
<?php
if (function_exists('wp_pagenavi')):
?>
<?php
wp_pagenavi();
?>
<?php
else:
?>
<?php
if ($wp_query->max_num_pages > 1):
?>
<nav class="oldernewer">
<div class="older">
<?php
next_posts_link('« Older Entries');
?>
</div><!--.older-->
<div class="newer">
<?php
previous_posts_link('Newer Entries »');
?>
</div><!--.newer-->
</nav><!--.oldernewer-->
<?php
endif;
?>
<?php
endif;
?>
<!-- Page navigation -->
<?php
$wp_query = null;
$wp_query = $temp;
?>
<div id="footer">
<div class="clearfix">
<?php
if (!dynamic_sidebar('Footer Content')):
?>
<?php
endif;
?></div></div>
</div><!--#content-->
<?php
get_footer();
?>
wp_pagenavi() will work with the global $wp_query by default; if you want to paginate some custom query you need to pass it as a parameter, like:
wp_pagenavi( array( 'query' => $mycustomquery ) );
I have encountered the same problem before. For some reasons i cannot make WP query to work, but instead i used query_posts. Here is the code
<?php
/**
* #author MESMERiZE
* #copyright 2012
*/
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'tax_query' => array(
array(
"taxonomy" => "wpdic-category",
"field" => "slug",
"terms" => "featured-charities",
"numberposts" => 5,
"paged" => $paged
)
)
);
query_posts($args);
while(have_posts()): the_post();
endwhile;
?>
Then i added the wp pagenavi function after the endwhile keyword.
if (function_exists('wp_pagenavi')) {
wp_pagenavi();}