Wordpress : Most populars posts of the Week or Month - wordpress

I'm using a theme that shows popular posts with the code below, and I need
someone to help me edit this code to make it show popular posts on the last week or
month.
<?php
$args = array();
$args['posts_per_page'] = $number_posts;
$args['orderby'] = 'comment_count';
$args['order'] = 'DESC';
$query = new WP_Query($args);
while($query->have_posts() ) : $query->the_post(); global $post; ?>
<li>
<a title="<?php the_title();?>" href="<?php the_permalink();?>">
<figure>
<?php if(has_post_thumbnail() ) { ?>
<a href="<?php the_permalink();?>">
<img src="<?php echo aq_resize(wp_get_attachment_url( get_post_thumbnail_id($post->ID) ), 42, 42, true); ?>" alt="<?php the_title();?>" />
</a>
<?php } else { ?>
<a href="<?php the_permalink();?>">
<img src="<?php echo get_template_directory_uri() . '/img/missing_56.png';?>" alt="<?php the_title();?>" />
</a>
<?php } ?>
</figure>
<p>
<?php the_title();?> <br />
<span> <?php _e('Le ', 'Voxis'); the_time("F d, Y");?>, <?php comments_popup_link(esc_html__('0 commentaires','Voxis'), esc_html__('1 commentaire','Voxis'), '% '.esc_html__('commentaires','Voxis')); ?> </span>
</p>
</a>
</li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>

I have not yet tested below code but will assure that this will work for you.
<?php
$weekday=date("d m Y",strtotime('-7days'));
while($query->have_posts() ) : $query->the_post(); global $post;
$currentdate=date('d m Y',strtotime($post->post_date));
if($weekday < $currentdate) { ?>
<li>
...
body of code in <li> tag
...
</li>
<?php } ?>
...
rest of the code
?>

replace your code to this(get most recent last month post)
<?php
$today = getdate();
$args=array(
'post_type' => 'post',
'year'=>$today["year"],
'monthnum'=>$today["mon"]-1,
'orderby'=>'comment_count',
'order'=>'DESC',
'posts_per_page' =>$number_posts
);
$query = new WP_Query($args);
while($query->have_posts() ) : $query->the_post(); global $post; ?>
<li>
<a title="<?php the_title();?>" href="<?php the_permalink();?>">
<figure>
<?php if(has_post_thumbnail() ) { ?>
<a href="<?php the_permalink();?>">
<img src="<?php echo aq_resize(wp_get_attachment_url( get_post_thumbnail_id($post->ID) ), 42, 42, true); ?>" alt="<?php the_title();?>" />
</a>
<?php } else { ?>
<a href="<?php the_permalink();?>">
<img src="<?php echo get_template_directory_uri() . '/img/missing_56.png';?>" alt="<?php the_title();?>" />
</a>
<?php } ?>
</figure>
<p>
<?php the_title();?> <br />
<span> <?php _e('Le ', 'Voxis'); the_time("F d, Y");?>, <?php comments_popup_link(esc_html__('0 commentaires','Voxis'), esc_html__('1 commentaire','Voxis'), '% '.esc_html__('commentaires','Voxis')); ?> </span>
</p>
</a>
</li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
____________________________________________________________________________
for last 7 days post use this code:
<?php
function filter_where($where = '') {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts('post_type=post&posts_per_page='.$number_posts.'&orderby=comment_count&order=DESC');
?>
<?php while (have_posts() ) : the_post(); ?>
<li>
<a title="<?php the_title();?>" href="<?php the_permalink();?>">
<figure>
<?php if(has_post_thumbnail() ) { ?>
<a href="<?php the_permalink();?>">
<img src="<?php echo aq_resize(wp_get_attachment_url( get_post_thumbnail_id($post->ID) ), 42, 42, true); ?>" alt="<?php the_title();?>" />
</a>
<?php } else { ?>
<a href="<?php the_permalink();?>">
<img src="<?php echo get_template_directory_uri() . '/img/missing_56.png';?>" alt="<?php the_title();?>" />
</a>
<?php } ?>
</figure>
<p>
<?php the_title();?> <br />
<span> <?php _e('Le ', 'Voxis'); the_time("F d, Y");?>, <?php comments_popup_link(esc_html__('0 commentaires','Voxis'), esc_html__('1 commentaire','Voxis'), '% '.esc_html__('commentaires','Voxis')); ?> </span>
</p>
</a>
</li>
<?php endwhile;
wp_reset_query();
?>

Related

Query related posts, Wrap in Row every 3 posts

I'm trying to query some related posts and wrap them in a row div every 3 posts. I've checked all the questions regarding this but still my query renders a mess.
This is what I have so far:
<?php
$related = get_posts( array(
'category__in' => wp_get_post_categories($post->ID),
'numberposts' => 6,
'post__not_in' => array($post->ID) ) );
$counter=0;
if( $related ) foreach( $related as $post ) {
setup_postdata($post); $counter++;
?>
<div class="row">
<article class="third-width">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<?php the_post_thumbnail('post-parrilla'); ?>
</a>
<?php exclude_post_categories("8"); ?>
<div class="clear"></div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<div class="post-title">
<span><?php the_title(); ?></span>
</div>
</a>
</article>
<?php if ($counter%3==0):?>
</div><div class="row">
<?php endif;?>
<?php } wp_reset_postdata(); ?>
Thank you in advance
Use below code
<?php
$related = get_posts( array(
'category__in' => wp_get_post_categories($post->ID),
'numberposts' => 6,
'post__not_in' => array($post->ID) ) );
if( $related )
{
$counter = 0;
?>
<div class="row">
<?php
foreach( $related as $post ) {
setup_postdata($post);
if ($counter%3==0){
?>
</div><div class="row">
<?php
}
?>
<article class="third-width">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<?php the_post_thumbnail('post-parrilla'); ?>
</a>
<?php exclude_post_categories("8"); ?>
<div class="clear"></div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<div class="post-title">
<span><?php the_title(); ?></span>
</div>
</a>
</article>
<?php
$counter++;
}
?>
</div>
<?php
}
wp_reset_postdata();
?>

Want to show image caotion or title above portfolio image

For a recently developed wordpress website http://stc.co.in, I'm using Huge-IT portfolio to show the projects in each sectors. On clicking on projects a popup is showing with multiple images. Now I want to show image caption or title above the big image which was added while uploading image through WordPress. Please guide how to achieve this.
Thanks in advance.
Regards, Sanjay
If the plugin cant let you do it simply with text editor, in wordpress you need to search the specific section you want and work on php file.
When you have founded it you can put an html section with your title.
you need to made changes in plugin file..
follow path :
wordpress-sitename/wp-content/plugins/portfolio-gallery/Front_end/portfolio_front_end_view.php
modify line :
<ul id="huge_it_portfolio_popup_list_<?php echo $portfolioID; ?>">
<?php
foreach($images as $key=>$row)
{
$imgurl=explode(";",$row->image_url);
array_pop($imgurl);
$link = $row->sl_url;
$descnohtml=strip_tags($row->description);
$result = substr($descnohtml, 0, 50);
?>
<li class="pupup-element" id="huge_it_portfolio_pupup_element_<?php echo $row->id; ?>">
<div class="heading-navigation_<?php echo $portfolioID; ?>">
<div style="clear:both;"></div>
</div>
<div class="popup-wrapper_<?php echo $portfolioID; ?>">
<div class="image-block_<?php echo $portfolioID; ?>">
<?php if($paramssld["ht_view2_show_popup_title"]=='on'){?><h3 class="title"><?php echo $row->name; ?></h3><?php } ?>
<?php if($row->image_url != ';'){ ?>
<img alt="<?php echo $row->name; ?>" id="wd-cl-img<?php echo $key; ?>" src="<?php echo $imgurl[0]; ?>" />
<?php
global $wpdb;
$cimg_url = $imgurl[0];
$attachment = $wpdb->get_results("SELECT ID FROM wp_posts WHERE guid='".$cimg_url."'",'ARRAY_A');
$attachment_title = get_the_title($attachment[0]['ID']);
?>
<div class="cls_img_ttl" id="main_img_ttl"><?php echo $attachment_title; ?></div>
<?php } else { ?>
<img alt="<?php echo $row->name; ?>" id="wd-cl-img<?php echo $key; ?>" src="images/noimage.jpg" />
<?php
} ?>
</div>
<div class="right-block">
<?php if($paramssld["ht_view2_show_popup_title"]=='on'){?><h3 class="title"><?php echo $row->name; ?></h3><?php } ?>
<?php if($paramssld["ht_view2_thumbs_position"]=='before' and $paramssld["ht_view2_show_thumbs"] == 'on'){?>
<div><ul class="thumbs-list_<?php echo $portfolioID; ?>">
<?php
global $wpdb;
foreach($imgurl as $key=>$img){
$cimg_url = $img;
$attachment = $wpdb->get_results("SELECT ID FROM wp_posts WHERE guid='".$cimg_url."'",'ARRAY_A');
$attachment_title = get_the_title($attachment[0]['ID']);
?>
<li><a href="<?php echo $row->sl_url; ?>" class="group1" data-ttl="<?php echo $attachment_title; ?>" >
<img src="<?php echo $img; ?>">
</a></li>
<?php } ?>
</ul></div>
<?php } ?>
<?php if($paramssld["ht_view2_show_description"]=='on'){?><div class="description"><?php echo $row->description; ?></div><?php } ?>
<?php if($paramssld["ht_view2_thumbs_position"]=='after' and $paramssld["ht_view2_show_thumbs"] == 'on'){?>
<div><ul class="thumbs-list_<?php echo $portfolioID; ?>">
<?php $imgurl=explode(";",$row->image_url);array_pop($imgurl);
foreach($imgurl as $key=>$img){?>
<li><img src="<?php echo $img; ?>"></li>
<?php } ?>
</ul></div>
<?php } ?>
<?php if($paramssld["ht_view2_show_popup_linkbutton"]=='on'){?>
<div class="button-block">
<a href="<?php echo $link; ?>" <?php if ($row->link_target=="on"){echo 'target="_blank"';}?>><?php echo $paramssld["ht_view2_popup_linkbutton_text"]; ?></a>
</div>
<?php } ?>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
</div>
</li>
<?php
}?>
</ul>
JS:
jQuery('#huge_it_portfolio_popup_list_<?php echo $portfolioID; ?> .popup-wrapper_<?php echo $portfolioID; ?> .right-block ul.thumbs-list_<?php echo $portfolioID; ?> li a').click(function(){
var width=jQuery(window).width();
if(width<=767){
jQuery('body').scrollTop(0);
}
jQuery(this).parent().parent().find('li.active').removeClass('active');
jQuery(this).parent().addClass('active');
var main_img_ttl = jQuery(this).attr('data-ttl');
alert(main_img_ttl);
jQuery(this).parents('.right-block').prev().find('.cls_img_ttl').html(main_img_ttl);
jQuery(this).parents('.right-block').prev().find('img').attr('src',jQuery(this).find('img').attr('src'));
return false;
});
you can download file here : LINK

Custom post type pagination not working

I know this has been asked a thousand times, and I have tried to replicate almost all the solutions I found either here, or into the Wordpress forums (where I posted a question too) but nothing seems to solve my problem.
I have created a theme from scratch, I downloaded a blank theme template from _underscores and created everything else from there.
The final goal would be to create an infinite scroll, but I cannot even make pagination work. If anyone could help me, it would be greatly appreciated.
This is the code I have:
<?php
/*
Template Name: zvideos
*/
/**
* #package zseventyfour
*/
get_header(); ?>
<?php
$temp = $zvideos;
$zvideos = null;
$zvideos = new WP_Query();
$zvideos ->query( 'showposts=2&post_type=zvideo' . '&paged=' . $paged );
if( $zvideos->have_posts() ) {
while( $zvideos->have_posts() ) {
$zvideos->the_post();
$zvideo_date = get_post_meta($post->ID, 'zvideo_date', true);
$zvideo_client = get_post_meta($post->ID, 'zvideo_client', true);
$zvideo_location = get_post_meta($post->ID, 'zvideo_location', true);
$zvideo_vimeo = get_post_meta($post->ID, 'zvideo_vimeo', true);
$zvideo_screenshot01 = get_post_meta($post->ID, 'zvideo_screenshot01');
$zvideo_job01 = get_post_meta($post->ID, 'zvideo_job01', true);
$zvideo_job02 = get_post_meta($post->ID, 'zvideo_job02', true);
$zvideo_job03 = get_post_meta($post->ID, 'zvideo_job03', true);
$zvideo_name01 = get_post_meta($post->ID, 'zvideo_name01', true);
$zvideo_name02 = get_post_meta($post->ID, 'zvideo_name02', true);
$zvideo_name03 = get_post_meta($post->ID, 'zvideo_name03', true);
?>
<section id="content">
<div class="wrapper">
<article>
<div class="vimeo">
<h1><?php the_title(); ?></h1>
<ul class="details">
<li><?php echo $zvideo_date?></li>
<li><?php echo $zvideo_client?></li>
<li><?php echo $zvideo_location?></li>
</ul>
<div class="vimeo-wrapper">
<iframe src="//player.vimeo.com/video/<?php echo $zvideo_vimeo?>" width="100%" height="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
<div class="footage">
<ul class="images">
<li><img src="<?php echo $zvideo_screenshot01[0]?>" alt="<?php the_title(); ?>_01"/></li>
<li><img src="<?php echo $zvideo_screenshot01[1]?>" alt="<?php the_title(); ?>_02"/></li>
<li><img src="<?php echo $zvideo_screenshot01[2]?>" alt="<?php the_title(); ?>_03"/></li>
<li><img src="<?php echo $zvideo_screenshot01[3]?>" alt="<?php the_title(); ?>_04"/></li>
<li><img src="<?php echo $zvideo_screenshot01[4]?>" alt="<?php the_title(); ?>_05"/></li>
<li><img src="<?php echo $zvideo_screenshot01[5]?>" alt="<?php the_title(); ?>_06"/></li>
</ul>
</div>
<div class="clearfix"></div>
<div class="info">
<ul class="credits">
<li><p class="title"><?php echo $zvideo_job01?></p><p class="name"><?php echo $zvideo_name01?></p></li>
<li><p class="title"><?php echo $zvideo_job02?></p><p class="name"><?php echo $zvideo_name02?></p></li>
<li><p class="title"><?php echo $zvideo_job03?></p><p class="name"><?php echo $zvideo_name03?></p></li>
<li><p class="title"><?php echo $zvideo_job?></p><p class="name"><?php echo $zvideo_name?></p></li>
<li><p class="title"><?php echo $zvideo_job?></p><p class="name"><?php echo $zvideo_name?></p></li>
<li><p class="title"><?php echo $zvideo_job?></p><p class="name"><?php echo $zvideo_name?></p></li>
</ul>
</div>
</article>
</div><!-- END O WRAPPER -->
</section>
<?php
}
}
else {
echo '<div style="width=100%;text-align:center;font-size:180%;">Ooops! Something went <strong>terribly</strong> wrong...</br> Or there are no videos to show. Who knows, this is obscure stuff.</div>';
}
?>
<section>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
</section>
<?php get_footer(); ?>
I don't know how to solve this problem.
Thanks in advance.
Edit: problem fixed with the below code -
<?php
if (get_query_var('paged')) {
$paged = get_query_var('paged');
} elseif (get_query_var('page')) {
$paged = get_query_var('page'); // Display posts from current page on a static front page
} else {
$paged = 1;
}
$args = array(
'paged' => $paged,
'posts_per_page' => 1,
'post_type' => 'zvideos'
);
query_posts($args);
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<nav>
<?php previous_posts_link(); ?>
<?php next_posts_link(); ?>
</nav>
<?php endif; ?>
<?php wp_reset_query(); ?>
Try this:
<?php echo paginate_links(array('base' => str_replace(999999999,'%#%', esc_url(get_pagenum_link(999999999))), 'format'=>'?paged=%#%', 'current'=>max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages, 'type' => 'list')); ?>
Put this code where you want to display the navigation bar.

Show WordPress gallery on home like a post with easy FancyBOX

I try to show an WordPress Gallery on home page, but with the same effect present in a post page. Basically is show the gallery post on homepage when you clicking a post-thumb. I explain the problem:
When I click on post_thumb, show in the home I like this show me, a Gallery attatch in this post. This my code:
<ul id="rb-grid" class="list rb-grid">
<?php $number = 0; query_posts('category_name=atracciones-home'); if(have_posts()): ?>
<?php while(have_posts()): the_post(); ?>
<li>
<!-- <a data-fancybox-group="gallery" class="item fancybox" href="<?php the_permalink(); ?>"> -->
<a data-fancybox-group="gallery" class="item fancybox iframe" href="<?php get_attachment_link(); ?>">
<?php
if ( has_post_thumbnail() )
the_post_thumbnail('home-atracciones');
else
echo '<img src="' . trailingslashit( get_template_directory_uri() ) . 'img/default-thumbnail.png' . '" alt="" />';
?>
<div class="over" id="gallery-atracciones">
<h2 class="page-title" title="<?php the_title(); ?>"><?php the_title(); ?><span class="border"></span></h2>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</ul>
Need to check is_home() For More Details about is_home() function Click Here
<?php
if ( is_home() ) {
// This is the blog posts index
<ul id="rb-grid" class="list rb-grid">
<?php $number = 0; query_posts('category_name=atracciones-home'); if(have_posts()): ?>
<?php while(have_posts()): the_post(); ?>
<li>
<!-- <a data-fancybox-group="gallery" class="item fancybox" href="<?php the_permalink(); ?>"> -->
<a data-fancybox-group="gallery" class="item fancybox iframe" href="<?php get_attachment_link(); ?>">
<?php
if ( has_post_thumbnail() )
the_post_thumbnail('home-atracciones');
else
echo '<img src="' . trailingslashit( get_template_directory_uri() ) . 'img/default-thumbnail.png' . '" alt="" />';
?>
<div class="over" id="gallery-atracciones">
<h2 class="page-title" title="<?php the_title(); ?>"><?php the_title(); ?><span class="border"></span></h2>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</ul>
} else {
// This is not the blog posts index
get_sidebar();
}
?>

Drupal - Current page, other language

i've found this code :
<?php global $language; ?>
<?php global $theme_path; ?>
<ul class="language-switcher-locale-url">
<?php $languages = language_list() ?>
<?php foreach($languages as $lang): ?>
<?php $active = $language->language == $lang->language ? " active" : ""; ?>
<li class="<?php echo $lang->language ?><?php echo $active ?>">
<a href="/<?php echo $lang->prefix ?>">
<img src="/<?php echo $theme_path ?>/images/flags/<?php echo $lang->language ?>.png" alt="<?php echo $lang->language ?>"/>
</a>
</li>
<?php endforeach ?>
</ul>
This redirects me from mywebsite.com/de/current_page to the selected language ex. mywebsite.com/en
what can i do for my code to redirects me to mywebsite.com/en/current_page
You should try using the url() and request_path() function that Drupal provides, perhaps something like this would work:
<?php global $language; global $theme_path; $languages = language_list() ?>
<ul class="language-switcher-locale-url">
<?php foreach($languages as $lang): ?>
<?php $active = $language->language == $lang->language ? " active" : ""; ?>
<li class="<?php echo $lang->language ?><?php echo $active ?>">
<a href="<?php echo url(request_path(), array('language' => $lang)); ?>">
<img src="/<?php echo $theme_path ?>/images/flags/<?php echo $lang->language ?>.png" alt="<?php echo $lang->language ?>"/>
</a>
</li>
<?php endforeach ?>
</ul>

Resources