0

I could do it using a code I found, then editing it a litle bit, so i could add css classes on it. Inserted it inside "PHP Everywhere" plugin, and it worked. I made another site, with the same configurations, plugins, theme, etc... but that code is not working properly anymore. The post items (Title, text, etc) are displayed, but instead of latest Sticky Post, it brings latest post from that category. And when I mark a post as Sticky, then nothing is displayed.

<!-- Sticky Posts por categoria para área de Widgets com código PHP -->
<div class="stick-posts-fem">
<?php $sticky = get_option( 'sticky_posts' ); ?>
<?php
/* Sort the stickies with the newest ones at the top */
 rsort( $sticky ); ?>
<?php  
/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 1 ); ?>

<?php $catquery = new WP_Query( 
array( 
'post__in' => $sticky, // sticky post
'ignore_sticky_posts' => 1, // ignorar o post atual
'cat' => 5, // Use o id da categoria
'posts_per_page' => 2, // posts por coluna
) ); ?>
<?php if ( $catquery->have_posts() ); ?>

<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<div class="stick-master">
<div class="stick-head">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<p><?php the_field('descricao_curta'); ?></p>
</div>
<div class="stick-foot"> 
<p>Leia o significado de</p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</div></div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<!-- fim Sticky Posts -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.