WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Make Index page = latest post page? (15 posts)

  1. feverblue
    Member
    Posted 7 years ago #

    Greetings!

    Let me see if I can describe this issue as well as I can. Any help or advice would be appreciated.

    I'm assembling a photoblog. Very simple, one image per post, one post per page. It's just about ready to go live. The challenge is this: I'm using an Ajax-based comments system for comments that keeps comments hidden until readers click a 'view comments' link, at which point the comments appear at the bottom of the same post page. On all the post pages, it works like a charm.

    However, since the link points to an anchor on the POST PAGE, this presents a problem when the viewer is on the index page. Visitors end up having to click the link twice in order to view the comments--once to get to the individual post page and then again to open the comments.

    The only solution I can think of is to redirect the index page to the most current post page somehow when the index is loaded, but I can't seem to figure out how to do it. Does anyone out there know of a way to do this? Or maybe there's a better solution that I haven't considered?

    Thanks so much for taking the time.

    Cheers,
    Will

  2. Doodlebee
    Member
    Posted 7 years ago #

    I'm not really clear on what you're trying to do, but I'll take a stab...

    If you want your index page to only show the most recent post, then just do a query:

    <?php if (is_home()) {
    query_posts('showposts=1');
    }
    ?>

    Put that right before the Loop starts (starts with "<?php if (have_posts()) : ?>"). Then, when you're on the home page, it'll only show the most recent post.

  3. feverblue
    Member
    Posted 7 years ago #

    Thanks for the reply, but that's not exactly what I'm after.

    Hmm...Let's see if I can explain a little better. I've got one post (one single picture) on the index page, no problem. But the 'view comments' link does not work as it should because it's an index page. The link needs to be on a post page in order to work.

    So my question is, perhaps there's a way to have the index page redirect to the most recent post page when it loads. That way visitors to the site can comment on the first post they see without having to first go to the post page for the image.

    Does this make any more sense?

  4. Doodlebee
    Member
    Posted 7 years ago #

    But the 'view comments' link does not work as it should because it's an index page. The link needs to be on a post page in order to work.

    That doesn't make any sense...all you'd need to do is make the page title "clickable" (which it already does by default), and it'll take the end user directly to the single post page with the comments. Alternatively, you just need the post to have the code for "view comments" and it'll do the same thing.

    Sounds like you need to edit your template file to include these links in your posts.

    Unless..

    Do you have your blog in one area of your server, and you're just trying to link from a regular web page that has no involvement whatsoever with WordPress?

  5. feverblue
    Member
    Posted 7 years ago #

    Thanks, doodlebee

    Maybe this will help. Here's the URL:
    http://planetneil.com/photos/

    Mouse over the 'view comments' link below the image. check the target in the status bar. See how it's aimed at an anchor located on the individual post page? If you click it, you're taken to the post page. click it again, the comments open like normal.

    What I'd like is for the latest post page to open up by default when you visit the site, thereby eliminating the need for that first click.

    Either that or figure out a way to configure the Ajax function to open the comments right there on the index page...

    Any suggestions, anyone?

  6. Doodlebee
    Member
    Posted 7 years ago #

    WOW. Nice photo. Awesome.

    I think you and I are missing something. What you want *should* be doable, just as WP is set up, without any extra redirects or anything. It should just work. That's why I asked if you had a regular site, and you were just linking to the page in question.

    Now, I see that you *do* have a regular site. This link:http://planetneil.com/photos/ shows *exactly* the same thing as if you visit here: http://planetneil.com/photos/wordpress. That tells me that you have your WordPress files in /photos/wordpress, and you've put the index in "photos". So, how about this - in your Options page, what is your Blog URL set as?

    I'm also wondering why you didn't just upload the files themselves into the "photos" directory, rather than putting it in yet another directory (that would also solve the issue).

    But in any case, the setup you have now - I'd say it's probably something in your theme code - what's the code of your index.php file?

    Another thing you might do - this'll take your "Ajax" into account - is use the same kind of scripting that the "show/hide" for the "more" function uses.

    Anyway, if you post the code for your index.php (provided it's not too long - if it's seriously long, put it in pastebin and pass a link, please), I'll take a look at it and see what I see.

  7. Doodlebee
    Member
    Posted 7 years ago #

    By the way, I just noticed you're using 2.1.1. You NEED to upgrade - like immediately. There's a sitcky on the forums (right at the top), as well as a post on your dashboard when you login to admin.

  8. feverblue
    Member
    Posted 7 years ago #

    The WordPress files ARE installed directly into the photos folder. There is no 'wordpress' subfolder. And the homepage setting in options is this: http://planetneil.com/photos

    Here's the index code (I've omitted non-essential stuff, such as links code):

    <?php get_header(); ?>    
    
    <!-- begin post -->
    <div class="entry">  
    
    <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
    
    <?php static $ctr = 0;
    if ($ctr == "1") { break; }
    else { ?>
    
    <div class="nav">
    <?php previous_post_link('%link','<<&nbsp;&nbsp;&nbsp;'); ?>
    <?php the_title(); ?>
    <?php next_post_link('%link', '&nbsp;&nbsp;&nbsp;>>'); ?>
    </div><!-- NAV -->
    
    <?php global $post, $tableposts;
    $previous = @$wpdb->get_var("SELECT ID FROM $tableposts WHERE post_date < '$post->post_date' AND post_status = 'publish' AND id != 19 AND id != 3 AND id != 2 ORDER BY post_date DESC LIMIT 0,1 ");
    if ($previous) {
    $link = get_permalink($previous);
    echo '<a href="' . $link . '" title="Previous">' . $post->post_content . '</a>';
    } else {
    the_content('[More Photos]');
    } ?>
    
    <?php $ctr++; } ?>
    </div><!-- end ENTRY -->
    
    <div class="posted"><a href="<?php the_permalink() ?>" title="Permalink"><?php the_time('M j, \'y') ?></a> / <?php the_category(', '); ?> / <?php inap_comments_link();?> / <?php inap_addcomments_link();?> / <?php edit_post_link('   &middot; edit','<span class="editlink">','</span>'); ?>
    </div> <!-- end POSTED -->
    
    <!--#####################################-->
    <!-- EDIT OR ADD LINKS IN THE CODE BELOW -->
    
    <div class="links">
    
    **omitted**
    
    </div><!-- end LINKS -->
    
    <!-- <?php trackback_rdf(); ?> -->    
    
        <?php endwhile; ?>
      <?php endif; ?>
    
    <?php inap_comments(); ?> 
    
    <br />
    <?php inap_addcomments(); ?>
    <?php get_footer(); ?>
    </div><!-- end CONTAINER -->
  9. sadish
    Member
    Posted 7 years ago #

    try the following and see if it works.
    1. create a new file called 'home.php' within your theme folder.
    2. copy the contents of your single.php, into that.
    3. just before the loop, paste the following code
    http://pastebin.ca/404135
    4. save it and view your site's home page and see if it works.

    Thanks
    Sadish

  10. sadish
    Member
    Posted 7 years ago #

    this code gets the ID of the most recent post.

    and then makes WP to think, people are viewing a single post for that ID.

    See if it works.
    Sadish

  11. feverblue
    Member
    Posted 7 years ago #

    Thanks, Sadish. It kinda worked. Well...actually not exactly. Upon loading, the index points the link to the first post in the database, in this case, the Dalmatian image. My grasp of php/mysql is getting better, but it's not quite good enough to figure out how to tweak it. What do you think?

  12. rudolf45
    Member
    Posted 7 years ago #

  13. feverblue
    Member
    Posted 7 years ago #

    Ah. Problem solved. This was just a hunch, but I wondered if I needed to include the code:

    <?php inap_comments(); ?> and the <?php inap_addcomments(); ?> within the loop instead of outside it. That did the trick. It was theme related, but the solution was not what I thought it would be.

    Thanks all for the help!

  14. johnny5w
    Member
    Posted 6 years ago #

    Thanks! This is just what I needed.

  15. ravi44
    Member
    Posted 6 years ago #

    ok thank you thanks for mail

Topic Closed

This topic has been closed to new replies.

About this Topic