Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7701

    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.

    #58983

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

    #58984

    Apparently, that code just won’t display here. I’ve uploaded it to here. Maybe some admin can get it to post correctly.

    #58985
    <?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 :)

    #58986

    Thanks, I always forget about backticks.

    #58987

    Glad that Chris could help you :)

    #58988

    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' );
    }

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Latest Posts In Specific Category’ is closed to new replies.