• Resolved goodonpaper

    (@goodonpaper)


    <?php if (have_posts()) : ?>
    <?php query_posts(‘cat=3’); ?>

    <h1 class=”subtitle_home”>” rel=”bookmark”><?php the_title(); ?></h1>
    <h2 class=”tagline”><?php echo c2c_get_custom(‘tagline’); ?> <?php edit_post_link(‘Edit’,'(‘, ‘)’); ?> </h2>

    <div class=”storycontent”>
    <?php the_excerpt_reloaded(70,”,”, true, ‘<br><div class=”moretext”>Read On …</div>’); ?>
    <?php wp_link_pages(); ?>
    </div>

    <?php else : ?>
    <p>No post found.</p>
    <?php endif; ?></div>

    Can anyone tell me why this is displaying the most recent overall post, not the most recent in the category?

Viewing 15 replies - 1 through 15 (of 17 total)
  • Wouldn’t those first two lines be reversed?

    <?php query_posts('cat=3'); ?>
    <?php if (have_posts()) : ?>

    Thread Starter goodonpaper

    (@goodonpaper)

    Yeah, thats a styled category page, not an archive.

    eg.
    https://iheartau.com/wordpress/albums/

    Nothing – see?

    Well, if you meant that you want to use a Page (as in Pages) to display posts from a category… you are way off! Wrong thinking.

    Use Category_Templates.

    Thread Starter goodonpaper

    (@goodonpaper)

    Sorry – wrong topic! The code the other way round displays the most recent post overall as well …

    Even if it displays… you are still wrong in your approach.

    Thread Starter goodonpaper

    (@goodonpaper)

    Care to tell me how I should be doing it?

    I just did it above.

    Thread Starter goodonpaper

    (@goodonpaper)

    No, this code is for the home.php – to display the newest entry from a category. My reply about the “styled category page” was misplaced.

    I guess you should have been a bit more explicite when you made your initial post: nothing said that was for an index. Sorry.

    In your index you can use one, two, 3, more… Loops or you can just have a plugin that exludes categories from being shown on the main page.

    Thread Starter goodonpaper

    (@goodonpaper)

    But shouldn’t that code work, hypothetically? Take a look at https://iheartau.com/wordpress and scroll past the ad, you’ll see what I’m trying to do.

    My issue with this kind of questions is… I have no idea what you are trying to do. When users think they know how to go about a problem/question and they go technical and post code – I am lost, sorry.

    I prefer a detailed laymen description of what the end goal is, then we might be able to tell the “how-to” (if there is a solution).

    If your main page is displayed by a home.php file as you stated above, I might assist you since I also have a blog where I have a home.php with 4 different Loops and I know exactly how that template file works. But if you give just one bit of info in every 24 hours about what you want… that will not work. Like it was with your initial post: why it doesn’t work? How the heck should we know where you are using it and why???

    Thread Starter goodonpaper

    (@goodonpaper)

    Alright then.

    It’s an excerpt from a piece of code on my home.php, where I want to pull the last entry from a specific category to be displayed. You’ll see on iheartau.com/wordpress – after the advertisement – that it’s already displaying, but it’s displaying the latest entry overall, not from the category specified.

    The code running in that particular div is:

    <?php if (have_posts()) : ?>
    <?php query_posts(‘cat=3’); ?>

    <h1 class=”subtitle_home”><?php the_title(); ?></h1>
    <h2 class=”tagline”><?php echo c2c_get_custom(‘tagline’); ?> <?php edit_post_link(‘Edit’,'(‘, ‘)’); ?> </h2>

    <div class=”storycontent”>
    <?php the_excerpt_reloaded(70,”,”, true, ‘<br><div class=”moretext”>Read On …</div>’); ?>
    <?php wp_link_pages(); ?>
    </div>

    <?php else : ?>
    <p>No post found.</p>
    <?php endif; ?>

    Any help provided would be extraordinary.

    Sory, but MichaelH told you several posts and days ago… the first two lines are in wrong oder!
    The query_post should come BEFORE the Loop starts, and I don’t see the loop finished.

    I have this in one of my blogs:

    <?php query_posts('cat=-3&showposts=4'); // exclude the third category ?>
    
     <?php while (have_posts()) : the_post(); // start your Loop ?>
    
    <h4 class="storytitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    <?php the_time('d.m.Y'); ?><br />
    <?php the_excerpt_reloaded(30, '', '<a><img>', TRUE, 'Keep reading...', FALSE, 2); ?>
    
     <?php endwhile; ?>

    It does the opposite: excludes one category (the minus sign) and shows 4 posts, but you should get the idea.

    Thread Starter goodonpaper

    (@goodonpaper)

    Perfection – thank you!

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘query_posts question’ is closed to new replies.