Forums

select home post in current category (3 posts)

  1. Darfuria
    Member
    Posted 1 year ago #

    I'm using my category.php to select the post title "home" in the current category.

    <?php
    $currentcat = the_category_ID();
    $query = 'cat=' . $currentcat . '&name=home&showposts=1';
    ?>
    
    <?php query_posts($query); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    ?>

    However, this seems to select the latest post from any category titled home. Echoing $currentcat returns the correct category ID.

    Any help appreciated.

  2. rmk80
    Member
    Posted 1 year ago #

    Try this instead:

    <?php
    $cat = get_query_var('cat');
    query_posts("cat=$cat&name=home&showposts=1");
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
  3. Darfuria
    Member
    Posted 1 year ago #

    Hi there, thanks for the response.

    Unfortunately that's displaying the same post in both categories.

    I have "Home" posted in General (for example) and "Home" posted in News.

    Going to site/home/ displays the "Home" post in General, and going to site/news/ displays the "Home" post in General too.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.