ThemeShaper Forums » Thematic


So close yet so.... frustrated

(7 posts)
  • Started 8 years ago by mikeward
  • Latest reply from fwunder
  • This topic is resolved
  1. mikeward

    If anyone has any ideas, I would love to hear them. PHP Newb here and what I have I swiped and edited (See below). I have 3 functions in my functions.php and they only work when called in a specific order, 1, 2, 3 for example, but I want to call them in 3, 1, 2 order. When I do that, 3 renders, but 1 and 2 do not. When I call them in 1, 2, 3, order they all render. It does not matter what hooks I use (right now they are all the same).

    As far as I can tell, the issue is in the while loop because if I remove the while and endwhile lines, all 3 render in 3, 1, 2 order, but I do not get all the featured posts.

    Here are the functions:


    function addPrimaryColumn(){
        if ( get_secondary_content('Primary Column') ) {
          echo '<div class="fauxPrimary grid_7">' . "\n";
             the_secondary_content('Primary Column');
          echo '</div>' . "\n";


    function addSecondaryColumn(){
        if ( get_secondary_content('Secondary Column') ) {
           echo '<div class="fauxSecondary grid_7">' . "\n";
             the_secondary_content('Secondary Column');
             echo '</div>' . "\n";


    function featured_posts(){
     if (is_front_page()) {
            $my_query = new WP_Query('category_name=Spotlight&showposts=3');
            if ($my_query->have_posts()) {
            if ( ( get_secondary_content('Middle Column') ) && ( get_secondary_content('Right Column') ) ) {
              echo '<div class="feature grid_15">' . "\n";
            elseif ( ( get_secondary_content('Middle Column') ) || ( get_secondary_content('Right Column') ) ) {
              echo '<div class="feature grid_8">' . "\n";
            else {
              echo '<div class="feature grid_24">' . "\n";
            echo '<h3>Latest News!</h3>';
            echo '<ul id="featured-posts">';
            $feat_class = array();
            while ($my_query->have_posts()) : $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);
                          echo '<li id="featured-<?php the_ID(); ?>" class="<?php echo $feat_class; ?>">';
                            $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>";
                            echo $posttitle;
                    echo '<!-- .post -->';
            echo '';
            echo '</div>';

    ANY help would be appreciated. Thanks in advance,

    Posted 8 years ago #
  2. fwunder

    May I ask what you are trying to do? From my non-jedi eyes it looks like put a "featured post" abovemainasides?

    Posted 8 years ago #
  3. middlesister

    My first thought is that you are missing wp_reset_postdata(), just after the endwhile.

    Posted 8 years ago #
  4. or i like to use get_posts in lieu of monkeying w/ the query objects.

    there is a good example for resetting post data after your mini loop

    Posted 8 years ago #
  5. mikeward

    @fwunder - yes, basically.

    And we have a winner! @middlesister, that did it, thanks!

    Thanks @helgatheviking. I took a look at your suggestions too and dug into it a little bit but could not get it to work. Since the other answer is working, I decided to leave that can or worms closed(reminder, newb here) and stick with the other answer for now. :) I have used advice from some of your other answers in the past and appreciate you always being there to help though!

    Thanks all!

    Posted 8 years ago #
  6. all for going w/ what works. but in future, you'll let us help you better by being clearer about what you are trying to do. the ultimate support request looks something like

    1. what exactly you are trying to do
    2. what you have tried
    3. what problems you are seeing and/or how what you are trying differs from what you'd like it to do

    like fwunder, i too have no idea what you were attempting to achieve. just throwing out blocks of code is part of the question sure, but by itself it leaves us to have to decipher your code... which isn't always fnu. plus sometimes, convoluted code can be replaced by a more direct route if we know what the end goal is.

    glad you got it sorted.

    Posted 8 years ago #
  7. fwunder

    @ mikeward, *if* you are trying to do what I think you are trying to do, I accomplished it (with the help from the folks above) and this bit of code. If not, then maybe it will help someone else. I hope I got this right...

    // Creating a Post Category – place-it-post (slug: place-it-post ID=6)
    // Placing the category where I want it with conditions (one post and home page only)
    // Exclude the Category from the home default home page posts
    // format post for homepage only sidebar
    global $post;
    $postslist = get_posts( "category_name=place-it-post&numberposts=1" );
    if (is_home() || is_front_page()) {
        foreach ($postslist as $post) :  setup_postdata($post); ?>
            <div class="side-bar-post">
            <div class="side-bar-post-meta-title">
                <?php the_title(); ?>
            <div class="side-bar-post-meta-date">
                <?php the_time('F j, Y'); ?>
        <?php the_excerpt(); ?>
    <?php endforeach; }
    //filter category from home page
    function remove_category() {
        global $query_string;
    add_action ('thematic_above_indexloop', 'remove_category');
    // If you want to use the Thematic built-in Post header styling and thumbnail
    global $post;
    $postslist = get_posts( "category_name=place-it-post&numberposts=1" );
    if (is_home() || is_front_page()) {
        foreach ($postslist as $post) :  setup_postdata($post); ?>
            <div class="post-block">
                <?php thematic_postheader(); ?>
                <?php if ( has_post_thumbnail() ) { ?>
                    <a href=" <?php the_permalink() ?> "> <?php the_post_thumbnail( 'thumbnail', array('class' => 'alignleft') ); ?></a>
                <?php  } ?>
            <?php the_excerpt(); endforeach; } ?>

    I've got a couple examples in my messy sandbox -

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.