I'm using the following code to pull the latest posts from the "Announcements" category into a slider on the homepage I'm setting up. A zero offset gets the latest post and a one gets the second latest and so on.
<?php
global $post;
$args = array( 'numberposts' => 1, 'offset' => 0, 'category' => 4 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<h3>"><?php the_title(); ?></h3>
<?php if ( has_post_thumbnail()) : ?>
" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
<?php endif; ?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
The problem is that doing it this way requires the EXEC-PHP plugin. It seems to me that something this basic would make a great shortcode to add to the Avia Framework. Just a thought.
Latest Posts In Specific Category
7 posts from 3 voices-
Posted 1 year ago #
-
For some reason, part of the code was stripped from that comment. I'll try it again.
<?php
global $post;
$args = array( 'numberposts' => 1, 'offset' => 0, 'category' => 4 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
[box type="alert"]"><?php the_title(); ?>[/box]
<?php if ( has_post_thumbnail()) : ?>
" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
<?php endif; ?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
Posted 1 year ago # -
<?php global $post; $args = array( 'numberposts' => 1, 'offset' => 0, 'category' => 4 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <?php if ( has_post_thumbnail()) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?> </a> <?php endif; ?> <?php the_excerpt(); ?> <?php endforeach; ?>You can post code between backticks.
Thanks for sharing, I'll tell Kriesi about this :)Posted 1 year ago # -
Thanks, I always forget about backticks.
Posted 1 year ago # -
Glad that Chris could help you :)
Posted 1 year ago # -
One other thing I forgot about. You have to add the following code to the functions.php file to make use of WordPress thumbnail images.
/* Activate native WordPress Post Thumbnails */ if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); }Posted 1 year ago #
Reply
You must log in to post.














