ThemeShaper Forums » Thematic

[closed]

Feature Posts

(9 posts)
  • Started 9 years ago by dot-brian
  • Latest reply from dot-brian
  • This topic is not resolved
  1. dot-brian
    Member

    I am working with cozmoslabs.com Feature Posts function for Thematic...

    I do not know how to call for the post's image so that the feature "box" displays the attached image in the post. Thanks for any help in advance...here is the code:

    function featured_posts(){
    $my_query = new WP_Query('catagory=news&showposts=2');
    echo '<ul id="featured-posts">';
    $feat_class = array();
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    $feat_class = array();
    // Category for the post queried
    foreach ( (array) get_the_category() as $cat )
    $feat_class[] = 'category-' . $cat->slug;
    $feat_class = join(" ", $feat_class);
    ?>
    <li id="featured-<?php the_ID(); ?>" class="<?php echo $feat_class; ?>">
    <?php
    $posttitle = '<h4><a href="';
    $posttitle .= get_permalink();
    $posttitle .= '" title="';
    $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
    $posttitle .= '" rel="bookmark">';
    $posttitle .= get_the_title();
    $posttitle .= "</h4>\n";
    echo $posttitle;
    the_excerpt();
    ?>
    <!-- .post -->
    <?php
    endwhile;
    echo '';
    }
    add_action('thematic_belowheader','featured_posts');
    ?>

    Posted 9 years ago #
  2. Hi,
    I am using one of their themes, but I just added smooth slider to the top index widget to create my feature post. works good. see it here www.cookingsalmon.net

    Posted 9 years ago #
  3. I used this function as well, and it seems to respect the <!-- more--> tag. So if the image is above that tag it will be included.

    I did notice a typo in line 2 of your edited function
    $my_query = new WP_Query('catagory=news&showposts=2');

    "catagory" should be "category"

    Posted 9 years ago #
  4. I am trying to use this same function to output featured posts on a home page (front-page).

    I basically edited line 2 to include the condition is_front_page())

    while ($my_query->have_posts() & is_front_page()) : $my_query->the_post();

    this keeps the posts tagged with "feature" out of the blog posts on the blog page.

    I am still not outputting any of these featured posts to the front page however. The front page is still using the default template. Do I need to create a template for the front page that calls this function? Or should I just embedded the code in the new template?

    a code sample to get me started would be appreciated.

    Thanks, malcolm

    Posted 9 years ago #
  5. So I created a custom template for the home page & embedded the Cozmolabs example into that template (removed the function wrapper) and it works great. This code does not seem to respect the <!-- more --> tag however. Can i add this somehow?

    Template code:

    <?php
    /*
    Template Name: Front Page
    */
    ?>

    <?php get_header() ?>

    <div id="container" class="feature">
    <div id="content">

    <?php $my_query = new WP_Query('tag=featured&showposts=3');
    $feat_class = array();?>

    <?php while ($my_query->have_posts() & is_front_page()) : $my_query->the_post();
    $feat_class = array();
    // Category for the post queried
    foreach ( (array) get_the_category() as $cat )
    $feat_class[] = 'category-' . $cat->slug;
    $feat_class = join(" ", $feat_class);
    ?>
    <div id="post-<?php the_ID(); ?>" class="hentry <?php echo $feat_class; ?>">
    <?php
    $posttitle = '<h2 class="entry-title"><a href="';
    $posttitle .= get_permalink();
    $posttitle .= '" title="';
    $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
    $posttitle .= '" rel="bookmark">';
    $posttitle .= get_the_title();
    $posttitle .= "</h4>\n";
    echo $posttitle;
    the_excerpt();
    ?>
    </div><!-- .post -->
    <?php endwhile; ?>

    </div><!-- #content -->
    </div><!-- #container -->

    <?php thematic_sidebar() ?>
    <?php get_footer() ?>

    Posted 9 years ago #
  6. This code does not seem to respect the <!-- more --> tag however. Can i add this somehow?

    So if you decalre the variable "more" above the header...

    <?php global $more;?>
    <?php get_header() ?>

    and then replace...

    echo $posttitle;
    the_excerpt();

    with the following...

    echo $posttitle; $more = 0;
    the_content('Read More »');

    all is well. :-)

    Thanks, Malcolm

    Posted 9 years ago #
  7. dot-brian
    Member

    Thanks for the reply...
    manlikemalcolm...your replacement suggestion works - thanks. My problem is that I am trying to fit it into a smaller box that can't hold the full content so the_excerpt works better here. The page I am trying to duplicate is similar to this - http://teeoffpost.com - in where there are two featured posts at the top of the page. The Cozmoslabs code is perfect but I can't pull the images. What can it seems as simple as inserting code around the

    echo $posttitle;
    the_excerpt();

    lines...but I can't get it. Any thoughts? I've tried TimThumb but couldn't get it to work...

    Thanks for the help

    Posted 9 years ago #
  8. Try Jutsin Tadlock's get_the_image plugin

    Posted 9 years ago #
  9. dot-brian
    Member

    Thanks em hr...get_the_image plugin worked like a charm!

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.