Wordpress post grid last posts - html

how can i create a grid like image? for show last posts
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php $latest_post = get_posts( 'numberposts=4' ); ?>
<?php foreach( $latest_post as $post ) : setup_postdata( $post ); ?>
<?php the_title(); ?><br />
<?php the_content(); ?>
<?php endforeach; ?>
<?php wp_reset_query(); ?>

One option is to use PHP to swap around the position of the image based on whether or not the increment is odd or even, for instance:
$i = 0;
while ( have_posts() ) : the_post();
if ($i % 2 == 0 ) {
// Display two columns with image on left
}
else {
// Display two columns with image on right
}
$i++;
endwhile;
If you're building your theme from scratch I'd suggest using a grid framework to handle your columns, otherwise see if the theme you're using has a grid framework already.
Edit:
There are also ways of doing this without actually having to change the markup of the page. For instance:
Swapping columns (left / right) on alternate rows
In this case you'd be able to generate your post markup without the if statement and just use CSS to swap the position of the image/video.

You can use the masonry technology or you can try this plugin

In your code above you fired two WordPress content loops. I am not sure why you had to fire two loops, although they both will work. First will print the recent posts depending on the number of Posts Per Page you selected via Settings->Reading tab from your WordPress Dashboard and the second one will again print the top 4 recent posts. I am using the first loop to tell you how you can create the attached image like grid.
Below is the PHP/HTML modifications that you have to make:
<?php $count = 1; if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="one-half <?php if( $count++ % 2 == 0 ): echo 'last-col'; endif; ?>">
<?php
// the function below will print the featured image attached to the post
the_post_thumbnail( 'your-featured-image-sizename' ); ?>
</div>
<!-- one-half -->
<div class="one-half">
<span class="post_stamp"><?php the_time( 'j m Y' ); ?></span>
<span class="post_cat"><?php the_category(', '); // This will print News if you filled the post under News Category ?></span>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); // Insteading of printing the whole content this function will print exceprt only ?>
</div>
<!-- one-half -->
<div class="clearfix"><!-- --></div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
You would have to put the below given links to your style file:
<style>
.one-half{width: 50%; float: left;}
.last-col{float: right;}
.clearfix{clear: both; overflow: hidden;}
</style>
After making the above changes your posts will be displayed as the attached image. Good Luck (y)

Related

is_single() function dose not show thumbnail image

I am using get_template_part('content'); in single.php. The the_post_thumbnail('large-thumbnail'); function shows the thumbnail image perfectly before. But it does not show with is_single() function in content.php.
content.php code:
<?php
if(is_single()){
the_post_thumbnail('large-thumbnail');
the_content();
}else{
the_post_thumbnail('small-thumbnail');
echo get_the_excerpt();
?>
Read moreĀ»
<?php } ?>
single.php:
<article>
<div class="single_post_content">
<h5><?php the_title(); ?></h5>
<?php
get_template_part('content');
?>
</div>
</article>
I think you forget to write wp loop in your single.php file. follow this code,
<?php while ( have_posts() ) : the_post();
get_template_part('content');
endwhile; wp_reset_postdata(); ?>
the_post_thumbnail() do not work out of wp loop, So call your get_template_part() function between the loop. May be now its will solve your problem.

Wordpress only first post different design

I have a blog(offline making) and I have Made a wordpress loop it checks if the First post it it uses different style and rest of other posts uses different.
Problem is: It works fine but when I go to next page(2) it shows again, I only want to apply for only First latest post. Not for First post on every page.
Code:
<?php
while ( have_posts() ) : the_post();?>
<?php $count++; ?>
<?php if ($count == 1 && is_home()) :
//First post different style goes here
<?php else : ?>
//Rest Other post different style goes here
<?php endif; ?>
<?php
endwhile;
?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="page_content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
You should use get_query_var('paged'). It will return the current page number, starting from 0.
So you should add
<?php if ($count == 1 && is_home() && get_query_var('paged') == 0 ) : ?>
//First post different style goes here
<?php else : ?>
//Rest Other post different style goes here
<?php endif; ?>
Add this to your function.php to change the number of posts
add_filter( 'pre_get_posts', 'custom_pre_get_posts' );
function custom_pre_get_posts($query) {
if ( is_home() && get_query_var( 'paged' ) > 0 ) {
$query->set('posts_per_page', 12);
}
return $query;
}

Wordpress: HTML sidebar at bottom, instead of right aligned with body

I added HTML to my functions.php. After the
<?PHP get_sidebar(); ?>
and before
<?php get_footer(); ?>
while the CSS is added in my style.css Child theme. The result is my box of HTML under the main content on my home page instead of being on the right side of the main content. I am hoping someone may be able to help me?
I tried to add my HTML and CSS but it wouldn't let me post it.
I've spent about 3 hours on this by myself so far. First I tried reformatting a feature provided by the Minamaze Wordpress Theme, but I figured I may as well just right my own code as it may be easier to implement.
I fixed it! Here's how: The real problem was the fact that my front page articles were individually grouped instead of wrapped in a class. I found the index.php file (the copy from my child theme) and surrounded the homepage content in a named div class. Below is code from my index file. Put a div wrapper class between get_header and the php line below it. Close the div before the get_sidebar.
get_header(); ?>
<?php while( have_posts() ): the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('blog-article'); ?>>
<?php if ( has_post_thumbnail() ) {
$column1 = ' two_fifth';
$column2 = ' three_fifth last';
} else {
$column1 = NULL;
$column2 = NULL;
} ?>
<header class="entry-header<?php echo $column1; ?>">
<?php thinkup_input_blogimage(); ?>
</header>
<div class="entry-content<?php echo $column2; ?>">
<?php think_input_blogtitle(); ?>
<?php thinkup_input_blogmeta(); ?>
<?php thinkup_input_blogtext(); ?>
</div>
<div class="clearboth"></div>
</article><!-- #post-<?php get_the_ID(); ?> -->
<?php endwhile; ?>
<?php thinkup_input_pagination(); ?>
<?php else: ?>
<?php get_template_part( 'no-results', 'archive' ); ?>
<?php endif; ?>
?php get_sidebar(); ?>
Under get_sidebar, you can put in your HTML code for YOUR sidebar that you wish to add.
Once I wrapped them into the php into it's own class and wrapped my sidebar boxes into their own class, I used float: left and right respectively in my CSS child theme, successfully creating a sidebar. I also made their widths percentages to increase usability. You can use this same method in the content-page.php, content-single.php, if you wish to add a side bar to other pages besides just the home screen.

Advanced custom fields repeater / jcycle: unwanted random order

on my portfolio i have some projects (for example http://mathieuserruys.be/art-cinema-offoff-voorjaar-2015/ ). These images are called via a ACF Repeater field, and they are put into a jcycle 2 gallery.
this is the code i use:
<div class="info" style='-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;'
unselectable='on'
onselectstart='return false;'
onmousedown='return false;'><span id="prev">< prev</span><br>
<span id="next">next ></span><span><?php the_post(); ?><?php the_content(); ?></span></div>
<div class="slideshow"
data-cycle-fx=scrollHorz
data-cycle-timeout=0
data-cycle-center-horz=true
data-cycle-center-vert=true
data-cycle-next="img, #next"
data-cycle-prev="#prev"
data-cycle-swipe=true
data-cycle-loader="true"
data-cycle-manual-speed="1"
data-cycle-caption-template="{{slideNum}}/{{slideCount}}"
>
<div class="cycle-caption"></div>
<?php if( have_rows('images_repeat') ): ?>
<?php while( have_rows('images_repeat') ): the_row();
// vars
$image = get_sub_field('image_repeat');
?>
<img src="<?php echo $image['url']; ?>"/>
<?php endwhile; ?>
<?php endif; ?>
</div>
<script>$.fn.cycle.defaults.autoSelector = '.slideshow';</script>
I've noticed that on first load the images appear in random order. and after that, sometimes they are right, sometimes they are not. I guess it has something to do with the Jcycle loading conflicting with how the repeater works.. any tips on this?
The jquery.cycle2.js is called after the jquery.cycle2.carousel.js and jquery.cycle2.tile.js
jquery.cycle2.js has to be available before these 2 scripts.

How to wrap every 3 div's contents in a div?

I need every three divs of class "loopcontent" to be wrapped in a new div of class "threeacross". I'm new to WordPress and really not a PHP guy yet, but I'm learning as I go.
Here's my loop:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div class="loopcontent">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else {
// the current post lacks a thumbnail
}
?>
<h1><?php the_title(); ?></h1>
<?php the_excerpt(); ?>
</div>
<?php endwhile; else : ?>
<div class="loopcontent">
<h1>Page Not Found</h1>
<p>Looks like the page you're looking for isn't here anymore. Try browsing the categories, archives, or using the search box below.</p>
<?php include(TEMPLATEPATH.'/searhform.php'); ?>
</div>
<?php endif; ?>
Something like this should work. This keeps a running count and places your div wraps every three posts. Let me know if this helps. If not, let me know what it's outputting, and I can tweak it:
<?php
if(have_posts()) : for($count=0;have_posts();$count++) : the_post();
$open = !($count%3) ? '<div class="threeacross">' : ''; //Create open wrapper if count is divisible by 3
$close = !($count%3) && $count ? '</div>' : ''; //Close the previous wrapper if count is divisible by 3 and greater than 0
echo $close.$open;
?>
<div class="loopcontent">
<?php
if(has_post_thumbnail()) the_post_thumbnail();
else{
// the current post lacks a thumbnail
}
?>
<h1><?php the_title(); ?></h1>
<?php the_excerpt(); ?>
</div>
<?php endfor; else : ?>
<div class="loopcontent">
<h1>Page Not Found</h1>
<p>Looks like the page you're looking for isn't here anymore. Try browsing the categories, archives, or using the search box below.</p>
<?php include(TEMPLATEPATH.'/searhform.php'); ?>
</div>
<?php endif; ?>
<?php echo $count ? '</div>' : ''; //Close the last wrapper if post count is greater than 0 ?>