Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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.

share|improve this question

2 Answers 2

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!

share|improve this answer
    
Hi would you mind making that code copy/paste ready? I think this might be another good solution, but when I put it in DW I get all kinds of PHP errors. I tried placing the <?php's etc where I thought they should go, but I guess I"m not doing it right. –  streetfire Sep 25 '13 at 2:28
    
It involved adding in a set of tags around the first chunk of php "$args" and "$query". I forgot it when I copied it over. I added it in. Also, as a note, "<?" is short for "<?php". They do the same thing. Technically, it's against the Wordpress coding standards: make.wordpress.org/core/handbook/coding-standards/php/… But it'll still work that way. I'm lazy and it's a bad habit I've yet to kick. Feel free to replace my "<?" with "<?php" –  Thought Space Designs Sep 25 '13 at 2:34

Hmm... this shouldn't be too hard. I did a quick search and came up with this one: http://wordpress.org/plugins/latest-custom-post-type-updates/. There are probably many like it.

You should be able style the output to display horizontally using CSS, no need to "offset posts".

share|improve this answer
    
I am having trouble getting those posts to display horizontally using the widgets classes. Any idea? –  streetfire Sep 25 '13 at 2:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.