ThemeShaper Forums » Thematic

[closed]

So close yet so.... frustrated

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

    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:

    1)

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

    2)

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

    3)

    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;
                            the_excerpt();
                    echo '<!-- .post -->';
            endwhile; 
    
            echo '';
            echo '</div>';
            }
    }
    }
    add_action('thematic_abovemainasides','featured_posts');

    ANY help would be appreciated. Thanks in advance,
    Mike

    Posted 7 years ago #
  2. fwunder
    Member

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

    Posted 7 years ago #
  3. middlesister
    Member

    My first thought is that you are missing wp_reset_postdata(), just after the endwhile.
    http://forums.themeshaper.com/topic/multiple-loops-demystified#post-21145

    Posted 7 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
    http://codex.wordpress.org/Function_Reference/get_posts#Reset_after_Postlists_with_offset

    Posted 7 years ago #
  5. mikeward
    Member

    @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 6 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 6 years ago #
  7. fwunder
    Member

    @ 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
    <?php
    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>
            <div class="side-bar-post-meta-date">
                <?php the_time('F j, Y'); ?>
            </div>
        <?php the_excerpt(); ?>
        </div>
    <?php endforeach; }
    
    //filter category from home page
    function remove_category() {
        global $query_string;
        query_posts('cat=-6');
    }
    add_action ('thematic_above_indexloop', 'remove_category');
    
    ?>
    
    // If you want to use the Thematic built-in Post header styling and thumbnail
    <?php
    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; } ?>
            </div>

    I've got a couple examples in my messy sandbox - http://grafiks101.com/dev/

    Posted 6 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.