WordPress.org

Ready to get started?Download WordPress

Forums

Latest post in an entirely different div and section - help? (41 posts)

  1. ladydelaluna
    Member
    Posted 7 years ago #

    http://www.pajamaspastnoon.com

    Okay, see that little grey box up on the right? That's where I want the latest post excerpt to go. That box is in it's own .php file (squaresidebar.php) and is called in with php include on the index.php page.

    I want everything other post to show up below the header image, with a maximum of 3 posts there.

    I've tried every thread I can find on this, and nothing's working for me.

    The ONLY difference right now, is that the most recent post is ALSO showing up below the header image.

    This is probably a simple fix, but I'm stumped.

  2. ladydelaluna
    Member
    Posted 7 years ago #

    Okay gang,

    I checked here: http://wordpress.org/support/topic/67784
    and here: http://wordpress.org/support/topic/20617
    and here: http://wordpress.org/support/topic/35504

    And I'm lost. I've tried some of what I've seen, but it either stops pulling the recent post or gives me a parse error or something like that.

    Here's the code I have in the squaresidebar.php file to pull in a post:

    <div align="center">
    <h3 id="latest">Most Recent...</h3>
    <?php $my_query = new WP_Query('showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;?>
    <h2 id="latestheadline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
    from <?php the_time('F jS, Y'); ?></h2>
    <?php the_excerpt('Read more...'); ?>
    <?php endwhile; ?>
    </div>

    That's the only code in that file.

    Here's what I'm using on index.php:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <br /><br />
    <div id="post-<?php the_ID(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon_post.gif" alt="" /> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="View Details: <?php the_title(); ?>"><?php the_title(); ?></a></h2></div>
    <!-- End Of Class Title -->
    <div class="small">
    <?php the_time("l j F Y @ g:i a") ?>
    </div>
    <!-- End Of Class Small -->
    <div class="article">
    <?php the_content("<br />Continue Reading &raquo; <br />" . the_title('','',false), 0). ""; ?>
    </div>
    <!-- End Of Class Article -->
    <br />
    <div class="postmetadata alt">
    <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
    &nbsp;|&nbsp;<?php _e("Posted in"); ?> <?php the_category(',') ?>
    &nbsp; &nbsp;<?php edit_post_link(); ?>
    </div>
    <!-- End Of Class Meta -->
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    That's just "the loop" from the index page, I guess.

    Anyone can give me the proper code here? Please and thank you!

  3. vkaryl
    Member
    Posted 7 years ago #

    Well, I looked around some earlier, but it appears that "the_post();" doesn't have any parameters you can give it to stop display of the latest post at the top in the loop. Now, keep in mind that there are people here that know far far more than I do as regards tags n such; I just normally don't use them much since my blog needs seem to be much simpler than most; there may indeed be parameters you can set somewhere to accomplish this, and hopefully if so the guy with the info will be along shortly - whoever heesh may be.

    It looks as if your "grey box" shows what it's supposed to; so if someone has the info to stop display of the latest post from within the loop, that should fix it, right?

  4. ladydelaluna
    Member
    Posted 7 years ago #

    Yes to that, vkaryl! That's exactly what I need.

    And I forgot - the box ain't grey anymore... sorry! It's the one to the right of the header image, with the (currently) purple border. :P

  5. vkaryl
    Member
    Posted 7 years ago #

    Heh - okay, it was grey earlier when I looked.... I'm still kinda digging through codex, if I find anything I'll holler.

  6. ladydelaluna
    Member
    Posted 7 years ago #

    Thanks for digging for me - I'm just lost!

  7. vkaryl
    Member
    Posted 7 years ago #

    Okay, being the space cadet I am, I was looking in the wrong galaxy earlier....

    http://codex.wordpress.org/Template_Tags/get_posts - Now, if you use the default, but tweak the offset from what's shown in that first example, what happens? You might have to play with it a while, I'm totally unsure how that's supposed to work....

    Where's a great plugin programmer like KafkaesquĆ­ when you need him?

    And of course, as I said earlier (I repeat myself in other words) - may be an easy way to do this and I just don't know of it....

  8. ladydelaluna
    Member
    Posted 7 years ago #

    One of the other posts I'd seen was Kaf's solution for this, but it confused the heck out of me. LOL

    Hoping for the ultimate easy way out on this one - just to have someone show me, with the code I posted, what to put where. I'm a php/query moron, seriously. ;)

    Thanks for the help vkaryl - I'm going to dig around that codex link and see if I can play with something to get it to work properly. Hopefully as it happens, someone will come along and just hand me the fish, so to speak. LOL

  9. tsguitar
    Member
    Posted 7 years ago #

    I vote for you keeping all of that code in one file and just running the loop twice:
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    With that, you can have a second loop that displays the "x" most recent posts except for the most recent one. Glance around that page and see if something makes sense to you. We'll help from there.

  10. vkaryl
    Member
    Posted 7 years ago #

    Oh yeah, been there done that one. Hey, link me that post, wouldja? I didn't know he'd MADE a post about it, but let me look it over, maybe it'll make some sort of sense to me.

  11. ladydelaluna
    Member
    Posted 7 years ago #

    tsguitar - I'd keep it all in one file but this is a shredded up theme as it is - and I'm worried about moving too many things. I've seen somewhere that someone did it this way, I just need to know how.

    vkaryl - I think this was the one I was referring to with Kaf's solution. I know I saw another one earlier though, just can't remember where or how I found it. But this one looks like it's close.

  12. vkaryl
    Member
    Posted 7 years ago #

    [You forgot the link....]

    S'okay, I think I found it.... are you on deadline for this? I'll have to play with all Kaf's and moshu's stuff on a sandbox.... and I'll be gone all day tomorrow....

  13. ladydelaluna
    Member
    Posted 7 years ago #

    ROFL - long day. sorry about that!
    No deadline - and I soooo appreciate your help!

  14. vkaryl
    Member
    Posted 7 years ago #

    Well, good.... what I'll do is start on it first thing Sunday, and please just update this thread if someone else comes along with the answer, 'cause I'll check here first.

  15. ladydelaluna
    Member
    Posted 7 years ago #

    You rock, chica. Thank you. And yes, if I do get the answer, I'll get here immediately. :)

  16. tsguitar
    Member
    Posted 7 years ago #

    What if you use get_posts?
    http://codex.wordpress.org/Template_Tags/get_posts#Generate_list

    Here's what I'm thinking (to be placed in your index.php):
    http://pastebin.ca/raw/138235

    Let me know if that works. Do you see what it's trying to do? That's the most important thing, that you start spotting what code is attempting to do and how.

  17. spencerp
    Member
    Posted 7 years ago #

    I'm *not sure* if this is "something" you might like, or need.. but..*maybe* one of these plugins?

    http://www.cre8d-design.com/blog/2006/03/09/wordpress-tutorial-blog-posts-in-different-columns/

    http://www.coffee2code.com/archives/2004/08/27/plugin-customizable-post-listings/

    If not, it's cool.. =)

    spencerp

  18. ladydelaluna
    Member
    Posted 7 years ago #

    tsguitar - that's close, except it gives the title of the 2nd most recent post, but the content of the most recent one! And it does that three times!! How the heck does that happen?!? When you click on the title, it takes you to the real post. But then underneath the title, is the latest post, with it's content AGAIN. Argh - this is confusing me so much!

    Then it gives the posts like it's supposed to, then it gives a them again, with syntax errors.

    I'm going to take a full screenshot and take that code out - it's borked up completely. :(

    http://www.pajamaspastnoon.com/i/pjpn.jpg

    I know what you mean about understanding the code... and I'm really trying to (I know that it didn't sound like that last night) but the best way for me is to see the code that does what I want it to, and then use it as a reference point a few times before it gets committed to memory.

    Spencer - I'd rather not use a plugin for this... the first theme I tried using wasn't using a plugin, and I know it's possible to do without one. But thank you for trying. :)

    I'm close now - but why is it showing the title of the 2nd post, but the content of the first (that's in the box as well)??

  19. spencerp
    Member
    Posted 7 years ago #

    Spencer - I'd rather not use a plugin for this... the first theme I tried using wasn't using a plugin, and I know it's possible to do without one. But thank you for trying. :)

    It's cool, I'm actually planning on doing something similiar then myself. =) I'd like to go the same route, minus the plugin..

    Here below is a post, that Kaf as well as some others..posted on something similiar to what you might be looking for..from there down. =)

    http://wordpress.org/support/topic/66600?replies=24#post-352694

    Also, some good reads, from the links "they" posted in there. I hope this might help too.. ;)

    spencerp

  20. ladydelaluna
    Member
    Posted 7 years ago #

    That's the one I can't understand to save my life.
    Too many people talking in it or something, I don't know. And it looks geared toward specific categories being placed in certain spots, isn't it? That's not really what I'm wanting.

    I just want the most recent to show up in the box, and everything else to show up below the header image. :( No category separations, nothing that complicated. That's why I'm getting confused I think.

  21. spencerp
    Member
    Posted 7 years ago #

    Oh ok.. Hmm, well..this code here, is right from the Papillion theme, it displays the last 10 post titles, right on the index page, or most likely.. where ever you want to call it to..

    http://www.vindictivebastard.net/downloads/last-10-posts.txt

    Of course, you can "up/lower" the "count" on the latest post titles showing.. I'm not sure if that's what you want, or not sigh.. =/

    spencerp

  22. tsguitar
    Member
    Posted 7 years ago #

    It looks like what spencerp posted is what I was trying to do. I'll have to look at mine later to try and figure out why it resulted in listing the content so many times and such. That's very frustrating (for me!). spencerp's code really should do it, though.

  23. vkaryl
    Member
    Posted 7 years ago #

    ladydeluna: I've spent some time looking this over today. What I can tell you is that from looking at moshu's page linked from one of the other search results, this code from Kaf

    <?php while($top_query->have_posts()) : $top_query->the_post(); $first_post = $post->ID; ?>

    [post and comment stuff goes here]

    <?php endwhile; ?>

    followed by this code

    <?php query_posts('showposts=6'); ?>
    <?php while(have_posts()) : the_post(); if(!($first_post == $post->ID)) : ?>

    [post and comment stuff goes here]

    <?php endif; endwhile; ?>

    is what's working on moshu's site to display sidebar excerpts with no duplication in the main post section. I'm still working with it, though I haven't been able to make it "behave" just yet....

    Hopefully moshu will come along to verify that's the case....

    But.... I think part of the problem I'm experiencing is that moshu's usage and Kaf's examples are category specific ("cat=1" for instance) - so I may have to dig around s'more....

  24. moshu
    Member
    Posted 7 years ago #

    Yeah, I got a code from Kaf in this thread:
    http://wordpress.org/support/topic/28203?replies=15

    and yes, it is cat specific (at least for me) and it is in use here:
    http://myprairiegazette.transycan.net/
    - on the top 1 posts (the latest) from cat X)

    However, toward the end of that thread from above, there is a solution posted without any category stuff...
    Also, if you just leave out the ('catgeory-stuff') from the first Loop - I suppose it should work.

  25. vkaryl
    Member
    Posted 7 years ago #

    Hi moshu - thanks for verifying. I've been tweaking with the "later in thread" solution, as well as others I've found both within codex and as far afield as maxpower.ca.

    None of them seem to actually want to drop the post displayed in the "mini-loop" from the main post display. I'll keep looking, thanks again!

  26. vkaryl
    Member
    Posted 7 years ago #

    Okay! After more trial and error, this is what I have (and I'm no programmer - I know good code, but I don't happen to be able to produce it), it's probably a kludgy workaround, and no doubt someone who IS a programmer will come along and shoot holes in it; but for now, you may be able to use it to get on with your in-process situation.

    [This requires that you make the mini-loop for the "box" load and run first, so you may have to tweak your layout to take that into account, btw.]

    Within the divide where the "box" is located, use the following code:

    <!-- begin mini loop -->
    <?php $my_query = new WP_Query('showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?></small>
    <div class="entry">
    <?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    </div>
    </div>
    <?php endwhile; ?>
    <!-- end mini loop -->

    Then, in index.php use this code BEFORE the loop:

    <?php query_posts('cat=1,2,3,4,5,6,7,8,9&showposts=6&offset=1'); ?>

    (This tells your main post display to use all the cats, show 6 posts, and offset by the post in the sidebar - you need to tweak for the actual cat ID numbers, and how many posts you want the main post column to show.)

    This is the main loop:

    <?php while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; ?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    </div>
    <p class="postmetadata">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    <!-- <?php trackback_rdf(); ?> -->
    </div>
    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?>
    </div>
    </div>
    <?php endwhile; ?>

    If it would be easier for you, you may email me at vkaryl *at * bytehaven *dot * com, and I'll take the extraneous crud out of my files, zip and send along to you.

    Hope that works, for you and anyone else who may need it.

    [Edit: and I DO wish I could get all the codebits to display like they should, not even happening using backticks and re-editing *sigh*]

    [Edit again: of course, if I wasn't a space cadet it would help!]

  27. ladydelaluna
    Member
    Posted 7 years ago #

    LOL vkaryl - I've had space cadet moments... no worries!

    Thank you so much for working this through! I'm going to go to bed now, my eyeballs are burning, but I'll apply it first thing in the morning and report back here.

    Thank you SOOOO much. I really appreciate everyone who's worked on this. I can't wait to apply this in the morning! :)

  28. vkaryl
    Member
    Posted 7 years ago #

    Yes, please let me know if it works. As I said, I'm no coder....

    [And I woke up in the middle of the night, thinking there was something I'd forgot to say about the setup; of course, I cannot now remember what it was. I'll keep trying to come up with it, sorry!]

  29. ladydelaluna
    Member
    Posted 7 years ago #

    Wheee!! With just a little bit of tweaking, it's working!
    Thank you so much, vkaryl... your help was tremendous.

    Here's the exact code I used and where:

    In the box:

    <div align="center">
    <h3 id="latest">Most Recent...</h3>
    <!-- begin mini loop -->
    <?php $my_query = new WP_Query('showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2><br />
    <small><?php the_time('F jS, Y') ?></small>
    <div class="entry">
    <?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    </div>
    </div>
    <?php endwhile; ?>
    <!-- end mini loop -->
    </div>

    And in the index.php (this includes a little moving around of elements, because otherwise I was getting some weird looking boxes and spacing issues:

    <div id="blogs">
    <?php query_posts('cat=1,2,3,4,5,6,7,8,9&showposts=2&offset=1'); ?>
    <?php while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; ?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><a rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <div class="small">
    <?php the_time("l j F Y @ g:i a") ?>
    </div>
    <div class="article">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    </div>
    <p class="postmetadata alt">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><?php edit_post_link('Edit','<strong> | </strong>',''); ?> </p>
    <!-- <?php trackback_rdf(); ?> -->
    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div>
    </div>
    </div> <!-- end blogs -->

    That's the part of index.php that displays the posts, and navigation. (However right now, the navigation links aren't working for some reason??)

    Again, many thanks to everyone for decoding the mess for me. Especially vkaryl for getting me a final (nearly 100% with the exception of the navigation) working piece of code! :)

  30. vkaryl
    Member
    Posted 7 years ago #

    Well, that's good to hear! Though it's a bit odd that the nav links aren't working.... I see that I had the nav link setup inside the loop - my bad, sorry. I didn't have enough posts on the test blog to have them show up.

    Might check the default theme to see how those nav links are set up? It's more than possible that I got things wonked while playing around, y'know!

    [Edit: hmmm. Okay, I went and pasted in the "new version" nav setup from 2.0.4 default theme. And set the display down to 3 with the offset so there's only 3 posts in the main display. The nav links appear now, just fine. BUT. Apparently the change in the loop function is getting in the way of the proper functioning of the nav links, because paging back simply redisplays the same posts rather than cycling back through. Is this what you're seeing too?

    I don't know that I have a clue how to start solving that one....]

Topic Closed

This topic has been closed to new replies.

About this Topic