Diplay content from custom type as widget or sidebar?

I am wanting to display the title, featured image, excerpt, and read more link for posts from my custom post type in a horizontal manner. Some other things I want to do here is limit the post count to 3.

I’ve looked for plug ins to do this, but all seem to fall a little short. For example, since i want to display these horizontally, I would need a plug in to be able to offset posts. I haven’t found one that does all those things. The only one is for the Genesis framework and Im not using that. 🙁 Can someone make a suggestion?

Read More

I’ve also tried using a php call <?php include("recent-portfolio-items.php"); ?> instead of a widget area, but I’m not a PHP guru so am running into issues with that as well.

For an example of what I’m trying to do, visit this link and scroll down to the Portfolio section http://www.streetfiredesigns.com/testsite/ Right now I am just using text widgets to give the look I’m going for.

Related posts

2 comments

  1. You’ll want to first set up a new query and enter the loop. Here’s how you would set up a query to retrieve only posts from your custom post type:

    $args = array(
        "post_type"=>"your-post-type",
        "posts_per_page"=>"3"
    );
    $query = new WP_Query($args);
    

    Then, you need to enter the loop in order to retrieve the data you’re looking for:

    have_posts()): $query->while(have_posts()): $query->the_post(); ?>

    <!-- Your content goes here -->
    

    Then, you can just use standard WordPress loop functions like the_title(); and the_excerpt(); to display the content for the current item in the loop. Ideally, you would want a template kind of like this:

    <h2><? the_title(); ?></h2>
    <? the_post_thumbnail(); ?>
    <p><? the_excerpt(); ?> - <a href="<? the_permalink(); ?>">Read more</a>.</p>
    

    Your mileage will vary. You can start with the above, and then theme the result with CSS to achieve the desired effect.

    Here’s all the code:

    <?
    $args = array(
        "post_type"=>"your-post-type",
        "posts_per_page"=>"3"
    );
    $query = new WP_Query($args);
    
    ?>
    
    <? if($query->have_posts()): $query->while(have_posts()): $query->the_post(); ?>
    
        <h2><? the_title(); ?></h2>
        <? the_post_thumbnail(); ?>
        <p><? the_excerpt(); ?> - <a href="<? the_permalink(); ?>">Read more</a>.</p>
    
    <? endwhile; endif; ?>
    

    Hopefully this helps!

Comments are closed.