I have a set_gallery function and I pass the set_args array to her. The set_args array always changes. I'm looking for a solution for deleting posts posted and so that the loop outputs posts with new parameters. How can this be realized? Thanks...
function set_gallery($set_args = '') { ?>
<?php if ($set_args == '') {
$args = array (
'post_type' => 'gallerys',
'posts_per_page' => '-1'
);
} else {
$args = $set_args;
} ?>
<?php $gallerys_posts = new WP_Query($args);
wp_reset_query();
if( $gallerys_posts->have_posts() ) :
while ( $gallerys_posts->have_posts() ) :
$gallerys_posts->the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 shuffle-item filtered">
<div class="portfolio-item">
<a href="<?php echo get_permalink(get_the_id());?>">
<?php if ( get_the_post_thumbnail(get_the_id()) ) { ?>
<?php echo get_the_post_thumbnail( get_the_id(), array(620, 423 )); ?>
<?php } ?>
<div class="portfolio-overlay">
<div class="caption">
<?php the_title(); ?>
<span>
<?php echo get_the_content(); ?>
</span>
</div>
</div>
</a>
</div>
</div>
<?php endwhile; endif; wp_reset_query();?>
<?php }
Related
I have a loop for a custom post type. I'm bringing back a block of title, image and content for each post. I want to apply slick slider to the results to create a slick carousel, but I don;t want to include the first two results of the loop - so I'd need to create a parent div to the results but only start that div after the first two results.
I've trialed ways of querying the results on a loop count to apply a class to only the first two results, but this doesn't really achieve what I'm after.
<div class="wrapper_for_news_items">
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'news',
'order' => 'DESC'
));
if( $posts ): ?>
<?php $post = $posts[0]; $c=0; ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<div class="treatment_block news_block <?php $c++; if($c == 1) { echo ' featured'; } elseif($c == 2) { echo ' featured'; } ?>">
<h2 class="block_title above"> <?php the_title( '' ); ?></h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below"> <?php the_title( '' ); ?></h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div> <!-- treatment news block wrapper -->
You could just create 2 loops.
Use the first for the featured output and the second for the carousel.
<div class="wrapper_for_news_items">
<?php
$args_with_two_posts = array(
'posts_per_page' => 2,
'post_type' => 'news',
'order' => 'DESC'
);
$query_with_two_posts = new WP_Query( $args_with_two_posts );
if( $query_with_two_posts->have_posts ) :
while ( $query_with_two_posts->have_posts ) : $query_with_two_posts->the_posts; ?>
<div class="treatment_block news_block featured">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of 2 post initial news loop -->
</div>
<!-- treatment news block wrapper -->
<?php
// Start your second loop containing the slickslider content
?>
<div class="wrapper_for_news_carousel_items">
<?php
$args_with_all_posts = array(
'posts_per_page' => -1,
'offset' => 2 // Offset the 2 initial posts
'post_type' => 'news',
'order' => 'DESC'
);
$query_with_two_posts = new WP_Query( $args_with_all_posts );
if( $args_with_all_posts->have_posts ) :
while ( $args_with_all_posts->have_posts ) : $args_with_all_posts->the_posts; ?>
<div class="treatment_block news_block">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div>
<!-- treatment news carousel items -->
Or you could count the posts in the loop and asign a wrapper before the third post and after the last post to create the carousel.
<div class="wrapper_for_news_items">
<?php
$args_with_two_posts = array(
'posts_per_page' => 2,
'post_type' => 'news',
'order' => 'DESC'
);
$query = new WP_Query( $args_with_two_posts );
$counter = 1; // Set the counter
if( $query->have_posts ) :
while ( $query->have_posts ) : $query->the_posts;
if ( $count == 3 ) { echo '<div class="slick-slider">'; };
?>
<div class="treatment_block news_block">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php
$counter++; // Add +1 every loop
if (($query->current_post +1) == ($query->post_count)) {
echo '</div>'; // This is the last post
}
endwhile;
?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div>
<!-- treatment news block wrapper -->
I am fetching data through custom post type and category. I have added 12 category Jan to Dec and Jan has 1 posts Feb have 2 post
What I am struggling to do on January post the 2 circle is showing on the left I want only one January Circle rest of the January post under the circle.
Can you please how can i put check on category?
here is the site http://novartis.portlandvault.com/timeline/
Thanks
<div id="timeline">
<?php
//Define your custom post type name in the arguments
$args = array('post_type' => 'timeline', 'order' => 'asc' );
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
$category = get_the_terms($id, 'timeline_categories');
?>
<div class="timeline-item">
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $category[0]->name;?>
</div>
</div>
<div class="timeline-content right">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php echo the_content(); ?>
</p>
<div class="timeline_img">
<img src="<?php echo $thumb; ?>" class="img-responsive">
</div>
</div>
</div>
<?php endwhile;?>
</div>
<!-- Timeline ends here -->
I am not sure using categories is the best way to do this. You are limiting yourself to one years worth of data. I would suggest actually using the post date to separate the posts, then your code could look something like this.
<div id="timeline">
<?php
//Define your custom post type name in the arguments
$args = array('post_type' => 'timeline', 'order' => 'asc' );
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
$category = get_the_terms($post->ID, 'timeline_categories');
?>
<section id="<?php echo $post->ID; ?>">
<?php
if( $loop->current_post === 0 ) {
$current_quarter = $category[0]->name; ?>
<div class="quarterlyheading">
<?php echo $current_quarter; ?>
<div class="quarterlinebreak"><hr></div>
</div>
<?php } else {
$post_quarter = $category[0]->name;
if($current_quarter != $post_quarter) { ?>
<div class="quarterlyheading">
<?php echo $post_quarter; ?>
<div class="quarterlinebreak"><hr></div>
</div>
<?php }
}
$current_quarter = $post_quarter;
?>
<div class="timeline-item">
<?php
if( $loop->current_post === 0 ) {
$current_month = get_the_time('M'); ?>
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $current_month; ?>
</div>
</div>
<?php } else {
$post_month = get_the_time('M');
if($current_month != $post_month) { ?>
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $post_month; ?>
</div>
</div>
<?php }
}
$current_month = $post_month;
?>
<div class="timeline-content right">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php echo the_content(); ?>
</p>
<div class="timeline_img">
<img src="<?php echo $thumb; ?>" class="img-responsive">
</div>
</div>
</div>
</section>
<?php endwhile;?>
</div>
I want to create blog page with recent posts and pagination. Code below shows recent posts but pagination doesn't want to work.
<?php get_header(); ?>
<div class="container clearfix">
<div id="content" class="clearfix">
<?php
$postslist = get_posts('numberposts=-1&posts_per_page=5&order=DESC&orderby=date');
foreach ($postslist as $post) :
setup_postdata($post);
?>
<div class="entry">
<div class="recent-post-thumbnail">
<?php echo the_post_thumbnail($recent->ID, 'thumbnail'); ?>
</div>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<h4>More ></h4>
</div>
<?php endforeach; ?>
</div> <!-- end content -->
<div class="kreska-pion"></div>
<div class="sidebar">
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
numberposts=6 replace this with post_per_page and let me know if It worked .
<?php
$postlist = get_posts( 'numberposts=-1&posts_per_page=5' );
$posts = array();
foreach ( $postlist as $post ) {
$posts[] += $post->ID;
}
$current = array_search( get_the_ID(), $posts );
$prevID = $posts[$current-1];
$nextID = $posts[$current+1];
?>
<?php
foreach ( $posts as $post ) : setup_postdata( $post ); ?>
<li>
<?php the_title(); ?>
</li>
<?php endforeach;
wp_reset_postdata();?>
<div class="navigation">
<?php if ( !empty( $prevID ) ): ?>
<div class="alignleft">
<a href="<?php echo get_permalink( $prevID ); ?>"
title="<?php echo get_the_title( $prevID ); ?>">Previous</a>
</div>
<?php endif;
if ( !empty( $nextID ) ): ?>
<div class="alignright">
<a href="<?php echo get_permalink( $nextID ); ?>"
title="<?php echo get_the_title( $nextID ); ?>">Next</a>
</div>
<?php endif; ?>
</div><!-- .navigation -->
I tried
<?php get_header(); ?>
<div class="container clearfix">
<div id="content" class="clearfix">
<?php
$args = array( 'post_per_page' = -1 );
$query= new WP_Query( $args );
var_dump( $query );
// The 2nd Loop
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title( $query->post->ID ) . '</li>';
}
// Restore original Post Data
wp_reset_postdata();
?>
<div class="vertical"></div>
<div class="sidebar">
<?php get_sidebar(); ?>
</div>
</div>
<?php wp_pagenavi(); ?>
<?php get_footer(); ?>
But it shows a blank page.
EDIT:
Here's what I did:
<?php get_header(); ?>
<div class="container clearfix">
<div id="content" class="clearfix">
<?php
$args = array( 'post_per_page' = -1 );
$query= new WP_Query( $args );
var_dump( $query );
wp_reset_postdata();
?>
<div class="vertical"></div>
<div class="sidebar">
<?php get_sidebar(); ?></div>
</div>
<?php wp_pagenavi(); ?>
<?php get_footer(); ?>
And it shows a blank page.
I'm trying to style the first post differently than the rest. It's for a "featured" section on index.php
<?php
$count = 0;
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
$count++;
if ( $count == 1 ) : ?>
<div class="big">
<div class="details">
<a class="cat" href="#">nike</a>
<p><?php the_title(); ?></p>
<ul class="stats">
<li class="icon-calendar"><?php the_time('m.d.Y') ?></li>
<li class="icon-eye"><?php if(function_exists('the_views')) { the_views(); } ?></li>
</ul>
</div>
<?php echo get_first_inserted_image(); ?>
</div>
<?php else : ?>
<div class="small">
<div class="holder">
<?php echo get_first_inserted_image(); ?>
<p><?php the_title(); ?></p>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
the above code does not seem to work as nothing is showing up. I would also like to expand on this to show only 4 random posts from the last 7 days. Any guidance is appreciate it! Thanks!
this got it done
<?php
// WP_Query arguments
$args = array (
'orderby' => 'rand',
'showposts' => 5,
'date_query' => array(
array(
'after' => '1 week ago'
)
)
);
$count = 0;
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
$count++;
if ( $count == 1 ) : ?>
<div class="big">
<div class="details">
<a class="cat" href="#">nike</a>
<p><?php the_title(); ?></p>
<ul class="stats">
<li class="icon-calendar"><?php the_time('m.d.Y') ?></li>
<li class="icon-eye"><?php if(function_exists('the_views')) { the_views(); } ?></li>
</ul>
</div>
<?php echo get_first_inserted_image(); ?>
</div>
<?php else : ?>
<div class="small">
<div class="holder">
<?php echo get_first_inserted_image(); ?>
<p><?php the_title(); ?></p>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
I have this code and all the vars pull in but the latest news is not showing up. any ideas?
<div class="content">
<?php get_sidebar('field'); ?>
<?php
global $current_user;
get_currentuserinfo();
$user_info = get_userdata($current_user->ID);
if ( have_posts() && $user_info->user_level != 0) : while ( have_posts() ) : the_post(); ?>
<?php // get custom fields
$wt_email = get_post_meta($post->ID, 'wt_email', true);
$wt_feed = get_post_meta($post->ID, 'wt_website', true);
$wt_facebook = get_post_meta($post->ID, 'wt_facebook', true);
$wt_twitter = get_post_meta($post->ID, 'wt_twitter', true);
$wt_linkedin = get_post_meta($post->ID, 'wt_linkedin', true);
?>
<div class="entry">
<h1><?php the_title(); ?></h1>
<div class="body">
<?php the_content(); ?>
</div>
<div class="share">
<div class="links">
<h3>Links</h3>
<ul>
<?php if($wt_twitter) { ?><li>Twitter</li><?php } ?>
<?php if($wt_facebook) { ?><li>Facebook</li><?php } ?>
<?php if($wt_email) { ?><li>Email</li><?php } ?>
<?php if($wt_linkedin) { ?><li>Website</li><?php } ?>
</ul>
</div>
<?php endwhile; // End the loop. Whew. ?>
<div class="news">
<h3>Latest News</h3>
<ul>
<?php
// The Query
$loop = new WP_Query( array(
'category_name' => $wt_feed,
'order' => 'ASC',
'posts_per_page'=> 5
) );
// The Loop
if( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
echo '<li><a href="' . the_permalink() . '">';
the_title();
echo '</a></li>';
endwhile;
endif;
// Reset Query
wp_reset_query();
?>
</ul>
<?php
$args=array(
'category_name' => $wt_feed,
'type' => 'post'
);
$categories=get_categories($args);
if($wt_feed) { ?>Subscribe<?php } ?>
</div>
</div>
</div>
<?php else : ?>
<div class="entry">
<h1>Listing Private</h1>
<div class="body">
<p>You need to have a Member account view the details of this list. Request an account membership.</p>
</div>
</div>
<?php endif; ?>
<div class="clearfix"></div>
</div>
Whilst not an exact answer, have you tried adding:
error_reporting(E_ALL);
ini_set('display_errors', '1');
At the top of the page, to display any errors that might be occurring?