my situation: I have a frontpage which filters 12 thumbnails out of 24 (each thumbnail represents a post's featured image), and displays them. The user has the ability to hide whichever post he wants from the frontpage.
Let's say the user chooses to hide thumb #4, that means we now have thumb 1,2,3,5,6,7,8,9,10,11,12. That is, we have 11 thumbnails. So we are missing the last 'thumbnail space', which should be filled with the upcoming post; in this case, thumb #13.
In short, the frontpage should query the posts so that when one or more thumbnails are hidden - resulting in one or more blank spaces - it automatically 'refills' the blank spaces by pushing in the upcoming thumbnails.
My front-page has this query:
<?php
global $wp_query;
// First row of images
if(!empty($options['home_thumbs'])) {
$page_items = $options['home_thumbs'];
} else {
$page_items = 18;
}
$portCat = get_category_id($options['portfoliocat']);
// get the desired sort order of portfolio items
if($options['homepage_sort'] == 'DESC') { $order = 'DESC'; } else { $order = 'ASC'; }
$hideFromHome = get_post_meta($wp_query->post->ID, 'pr_hidehome', true);
query_posts('posts_per_page=' . $page_items . '&orderby=title&order=' . $order . '&cat=' . $portCat . '&meta_key=' . $hideFromHome .'&meta_value=' . true);
// arrays to detect first and last columns
$firsts = array(6,12,18,24,30,36);
$lasts = array(5,11,17,23,29,35);
if (have_posts()) :
$count = 0;
echo '<ul class="imageRows rowOne">';
while (have_posts()) : the_post();
$custom_meta = get_post_custom($post->ID);
if (has_post_thumbnail() && $custom_meta['pr_hidehome'][0] != true) { ?>
<li class="<?php if (in_array($count, $firsts) ) { echo ' columnFirst'; } if (in_array($count, $lasts) ) { echo ' columnLast'; } ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php
$atts = array(
'class' => "attachment-$size imageBlock",
'alt' => get_the_title(),
);
the_post_thumbnail('portfolioSmall', $atts);
?>
</a>
</li>
<?php
$count++;
}
endwhile;
echo '</ul> <!-- First row -->';
else :
echo '<h3>Oops, something went wrong.</h3>';
endif;
?>
pr_hidehome is the option that, when enabled, hides the respective post (but leaves that empty space I'd need to be filled in with one or more of the upcoming thumbnails). You can also see how I am trying to query the posts. However, on this article, I read that the best way to query posts by custom fields is using an array with 'meta_query' in it. So here's what I tried it:
<?php
global $wp_query;
// First row of images
if(!empty($options['home_thumbs'])) {
$page_items = $options['home_thumbs'];
} else {
$page_items = 18;
}
$portCat = get_category_id($options['portfoliocat']);
// get the desired sort order of portfolio items
if($options['homepage_sort'] == 'DESC') { $order = 'DESC'; } else { $order = 'ASC'; }
$args = array(
'posts_per_page' => $page_items,
'orderby' => 'title',
'order' => $order,
'cat' => $portCat,
'meta_query' => array(
array(
'key' => 'pr_hidehome',
'value' => 'the_value_you_want',
'compare' => 'LIKE'
)
)
);
query_posts($args);
// arrays to detect first and last columns
$firsts = array(6,12,18,24,30,36);
$lasts = array(5,11,17,23,29,35);
if (have_posts()) :
$count = 0;
echo '<ul class="imageRows rowOne">';
while (have_posts()) : the_post();
$custom_meta = get_post_custom($post->ID);
if (has_post_thumbnail() && $custom_meta['pr_hidehome'][0] != true) { ?>
<li class="<?php if (in_array($count, $firsts) ) { echo ' columnFirst'; } if (in_array($count, $lasts) ) { echo ' columnLast'; } ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php
$atts = array(
'class' => "attachment-$size imageBlock",
'alt' => get_the_title(),
);
the_post_thumbnail('portfolioSmall', $atts);
?>
</a>
</li>
<?php
$count++;
}
endwhile;
echo '</ul> <!-- First row -->';
else :
echo '<h3>Oops, something went wrong.</h3>';
endif;
?>
Sadly this gave me the fallback error 'Oops, something went wrong'.
That's it. I hope I explained myself well enough. If not, I'll try and rephrase everything so that you can help me out!
Thank you very much. All help is greatly appreciated ;)