is_single() function dose not show thumbnail image - wordpress-theming

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.

Related

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 post grid last posts

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)

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.

Image Slider flashes wrong image at first

I am using a wordpress theme, Pitch Pro, and it has a built in slider. My issue is that sometimes the slider will flash the wrong image for a second. I noticed that it does not do it normally but only if I go from a page such as support to the home page. I have tried changed and setting the order. Changing the max amount of slides, currently 6, but nothing seems to fix it.
The site currently is jrummy16.com/test if anyone has any idea on a fix.
Not sure if this could relate to it anyway but the server I am using has issues and to fix it hostgator told me to add define( 'CONCATENATE_SCRIPTS', false ); to my config.php file. It fixed the issue but I do not recall the slider having this issue before adding that.
I have no idea on how to even start troubleshooting this. So any help would be greatly appreciated.
EDIT
All of the files were found inside the Theme, Pitch Pro.
I opened up my home.php file and I find this at the top for slider.
<?php
$slider_template = apply_filters('pitch_slider_template', array('slider', null));
get_template_part( $slider_template[0], $slider_template[1] );
?>
I then went and opened up slider.php in the same folder. It has this code,
<?php
$slides = new WP_Query(array(
'numberposts' => siteorigin_setting('slider_max_slides'),
'nopaging' => true,
'post_type' => 'slide',
'orderby' => 'menu_order',
'order' => 'ASC'
));
if($slides->have_posts()){
?>
<div id="slider">
<div class="container">
<div class="slides nivoSlider">
<?php while ($slides->have_posts()) : $slides->the_post(); if(has_post_thumbnail()) : ?>
<?php if(get_post_meta(get_the_ID(), 'slide_destination', true)) : $destination = get_post_meta(get_the_ID(), 'slide_destination', true) ?>
<?php echo '<a href="'.esc_url(get_permalink($destination)).'" title="'.esc_attr(get_the_title($destination)).'">' ?>
<?php elseif(get_post_meta(get_the_ID(), 'slide_destination_url', true)) : $destination = get_post_meta(get_the_ID(), 'slide_destination_url', true) ?>
<?php echo '<a href="'.esc_url($destination).'">' ?>
<?php endif; ?>
<?php echo get_the_post_thumbnail(get_the_ID(), 'slide') ?>
<?php if(!empty($destination)) echo '</a>' ?>
<?php endif; endwhile; ?>
</div>
<?php $slides->rewind_posts(); ?>
<div class="indicators-wrapper">
<ul class="indicators">
<?php while ($slides->have_posts()) : $slides->the_post(); if(has_post_thumbnail()) : ?>
<li class="indicator <?php if($slides->current_post == 0) echo 'active' ?> indicator-group-<?php echo $slides->post_count ?>">
<div class="indicator-container">
<div class="pointer"></div>
<h4><?php the_title() ?></h4>
<?php the_excerpt() ?>
</div>
</li>
<?php endif; endwhile; ?>
</ul>
</div>
</div>
</div>
<?php
wp_reset_postdata();
}
I am not sure if this will help or not but I hope that it does.
I think the reason is that before slider loads completely, the page will show last image in the list of slides and in your case it is this one:
<img width="705" height="344" src="http://jrummy16.com/test/wp-content/uploads/BA-slider.jpg" class="attachment-slide wp-post-image" alt="BA-slider">
Here is a similar problem and it has few of the solutions which you may use it as well.
UPDATE:
I found this article which suggests to modify your CSS. I would paste the code here but the article uses image to show CSS code:)

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 ?>