Alternating Wordpress Posts - wordpress

I am using the JointsWP for a Wordpress site that I am creating for a client.
They want the posts to alternate when the posts are looping.
For example, POST1: feature image on the left and title/excerpt on the right; POST2: title/excerpt on the left, feature image on the right. Etc etc.
Has anyone found any luck with this?
<?php
$args = array( 'posts_per_page' => 2, 'offset' => 2, );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<div class="row">
<div class="large-6 columns">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<div class="large-6 columns">
<?php the_date(); ?>
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<?php the_excerpt(); ?>
</div>
<div class="large-12 columns">
<hr>
</div>
</div>
<?php endforeach; wp_reset_postdata();?>

Never mind people, I found that Zurb has a functionality to accomplish this goal with a simple class.
Just going to create a counter to count the posts and make it a different class.
http://foundation.zurb.com/sites/docs/v/5.5.3/components/grid.html#source-ordering

Related

open the wordpress custom post type permalink in modal window

Normally in wordpress permalink will open to a single page. but this time the goal is to open the custom post type permalink in modal window. I have lots of custom post type, and I only like to apply the modal in the doctor custom post type .
how could I achieve this? here is my code:
<div class="slider-wrapper">
<div class="center-doc">
<!--start connect to db-->
<?php $args = array(
'post_type' => 'doctor',
'posts_per_page' => -1,
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish',
);
$posts = get_posts( $args );
foreach ( $posts as $post ): setup_postdata( $post );
?>
<!--end connect to db-->
<div class="slider-box">
<a href="<?php the_permalink(); ?>"> <!-- PERMALINK TO OPEN MODAL-->
<div class="feature-img"> <?php if (has_post_thumbnail()) : ?> <?php the_post_thumbnail(); ?>
<?php else : ?> <img src="<?php echo get_template_directory_uri(); ?>/img/default-img.png" alt="<?php the_title(); ?>">
<?php endif; ?><!--/pro pic-->
</div>
<h6><?php the_title(); ?></h6>
<div class="content"><?php the_excerpt(); ?></div>
</a>
</div>
<!-- MODAL WINDOW TO OPEN WHEN PERMALINK CLICKED-->
<div id="modal" class="modal-window">
<div>
<i class="fa fa-times-circle" aria-hidden="true"></i>
<div class="detail-wraper">
<div class="detail-info">
<h3><?php the_title(); ?></h3>
<div class="details">
<?php the_content(); ?>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
I am using Wordpress 5.9.3 version.

Can't display custom post type categories on the page

I have a custom post type called "case_studies" and it has 3 categories: "seo", "website-design" and "facebook-advertising".
I have several posts in the main page, and for each post I want to output what categories the post has.
For example, the latest post has a category of "seo" and "facebook-advertising", and I want it to be displayed in the page.
I have tried the get_the_terms(); function but I think I am using it incorrectly.
Here is the code of the page:
<div class="container">
<!--
<div class="category_container">
<p class="category_item" id="all">All</p>
<p class="category_item" id="website">Websites</p>
<p class="category_item" id="facebook">Facebook Ads</p>
<p class="category_item" id="seo">SEO</p>
</div>
-->
<div class="row d-flex">
<?php
$args1 = array( 'post_type' => array('case_studies'), 'order' => 'DESC', 'posts_per_page' => 30, 'orderby' => 'date' );
$loop = new WP_Query( $args1 );
while ( $loop->have_posts() ) {
$loop->the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop->ID));
?>
<div class="col-sm-4">
<div class="case-study-content">
<a href="<?php the_permalink() ?>" class="blog_blocks">
<div class="b_image">
<img src="<?php echo get_the_post_thumbnail_url(); ?>"/>
</div>
<div class="b_h_sec">
<h2><?php the_title(); ?></h2>
<p><?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?></p>
<span class="r_m">Read More</span>
</div>
</a>
</div>
</div>
<?php } ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
Here is how the output looks right now and where I want categories to be displayed.

Chrome issue with wordpress posts

I have an issue with my site on Chrome. On firefox everything is ok, but when I open my page with chrome I don't see the first post on page, there is a blank space there when it should be, I can see that this post is in the code when I inspect this page. I'm searching for an answer for few days and don't know why is this happening. Anyone had a problem like that? please help me.
I'm loading my posts with wp query from category, im using also a clip path in css (but I tried to comment in and check page and same issue was there).
<div class="container">
<div class="row">
<div class="col-12">
<h1 class="home-title text-center">Aktualności</h1>
<?php
$query = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'aktualnosci',
'posts_per_page'=> -1 ) ); ?>
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<div class="post-short">
<div class="row">
<div class="col-md-6 col-sm-12">
<a href="<?php the_permalink(); ?>">
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>" class="project_pics">
</a>
</div>
<div class="col-md-6 col-sm-12">
<h3 class="post-short_title text-center"><?php the_title(); ?></h3>
<?php the_date('d.m.Y', '<p class="text-center post-date">', '</p>'); ?>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; endif; wp_reset_postdata(); ?>
</div>
</div>
This is my code for displaying posts.
and page is szkola.webwitch.pl if anyone can check it
Thanks.

Wordpress loop only showing one record in query post

I have a Wordpress Site or its Blog section I did a WP_Query post.
The loop is within a custom template its showing only one record while I have few post entries.
I think I have done correctly...
Please do let me why it is not looping the records.
<?php get_header();
?>
<div id="body">
<div class="container">
<div class="row-fluid">
<div class="span9">
<?php
$arr = array(
'post_type' => 'post',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish'
);
$query = new WP_Query($arr);
if(count($query->posts) > 0):
$i = 0;
?>
<?php while($query->have_posts()): $i++;?>
<?php $query->the_post();
if(has_post_thumbnail(get_the_ID())){
$url_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumb_700x260', array('alt' => trim(get_the_title())));
$url_thumbnail_news = get_the_post_thumbnail(get_the_ID(), 'thumb_700x260', array('alt' => trim(get_the_title())));
} else {
$url_thumbnail = '<image src="'.get_template_directory_uri().'/images/no-thumbnail.jpg" title="No Thumbnail" alt="Free Nile Theme - Wordpress Theme from ThemeLead" />';
$url_thumbnail_news = '<image src="'.get_template_directory_uri().'/images/no-thumbnail-news.jpg" title="No Thumbnail" alt="Free Nile Theme - Wordpress Theme from ThemeLead" />';
}
?>
<?php if($i==1):?>
<div class="drop-shadow lifted"> <a class="nile-thumnail" href="<?php echo get_permalink(get_the_ID())?>" title="<?php the_title()?>"><?php echo $url_thumbnail;?></a> </div>
<div class="the_post">
<h2 class="bj-title"><a href="<?php echo get_permalink(get_the_ID())?>" title="<?php the_title()?>">
<?php the_title();?>
</a></h2>
<div class="bj-date">
<?php the_date();?>
<?php the_time();?>
</div>
<div class="bj-des">
<?php the_excerpt();?>
</div>
<a href="<?php the_permalink();?>" title="<?php the_title()?>" class="read-more">
<?php _e('Read more', APP_TD);?>
</a> </div>
<?php endif;?>
<?php endwhile;?>
<?php endif;?>
<?php // Reset Query
wp_reset_query(); ?>
<div class="navigation">
<div class="alignleft">
<?php previous_posts_link('« Previous') ?>
</div>
<div class="alignright">
<?php next_posts_link('More »') ?>
</div>
</div>
</div>
<div class="span3"> <?php echo get_default_sidebar();?> </div>
</div>
</div>
</div>
<?php get_footer();?>
Try removing the 'if($i==1)' and corresponding 'endif;' line

How do I display the second and third most recent posts from a category in WordPress

I am displaying previews of the three most recent news articles on my homepage. The most recent post will be displayed in a different format to the second and third most recent posts.
I am currently displaying all three the same with the following code
<?php query_posts('cat=2 && showposts=3');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-xs-12 col-sm-4">
<div class="column">
<div class="news-article">
<p class="news-date"><?php the_time( get_option( 'date_format' ) ); ?></p>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('full', array( 'class' => 'img-responsive img-rounded news-img' )); } ?>
<p class="news-headline"><?php the_title(); ?></p>
</a>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">
<p class="pull-right">Read more...</p>
</a>
<span class="clearfix"></span>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
How can I add another loop which will separate the second and third most recent posts from the most recent post?
I did not want to use postID as the posts will change.
The two arguments in the WP_Query function below combine to retrieve the second most recent post, then the HTML below displays that post.
<div class="video-message">
<p>
<ul>
<!-- // Define our WP Query Parameters -->
<?php
$the_query = new WP_Query( array( 'posts_per_page' => 1,'offset' => 1 ) );
?>
<!-- // Start our WP Query -->
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<!-- // Display the Post Title with Hyperlink -->
<p><?php the_title(); ?></p>
<?php
endwhile;
wp_reset_postdata();
?>
</ul>
</p>
</div>
</div>
To display the third most recent post would require changing the offset value to 2, so that the program skips over the two most recent posts.
$the_query = new WP_Query( array( 'posts_per_page' => 1,'offset' => 2 ) );
This method is discussed in the Pagination Parameters section of the WordPress Code Reference.
Untested but you could try:
<?php
$count = 0;
query_posts('cat=2 && showposts=3');
if (have_posts()) : while (have_posts()) : the_post();
if($count == 0)
{
?>
<div class="col-xs-12 col-sm-4">
<div class="column">
<div class="news-article">
<p class="news-date"><?php the_time( get_option( 'date_format' ) ); ?></p>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('full', array( 'class' => 'img-responsive img-rounded news-img' )); } ?>
<p class="news-headline"><?php the_title(); ?></p>
</a>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">
<p class="pull-right">Read more...</p>
</a>
<span class="clearfix"></span>
</div>
</div>
</div>
<?php
$count = 1;
}
else
{
//Some other layout here
}
endwhile;
endif;
?>
The above will check if $count is 0 and if it is, then do the layout and the count will then equal to 1. So the next time around $count won't be 0, so it will run what is in the else (which will be your layout).
I use WP_Query like this to show all posts from the fourth most recent one:
<?php
$query4 = new WP_Query( 'posts_per_page=4&offset=3' );
?>

Resources