• Resolved Jardry

    (@jardry)


    Can anyone direct me to a plugin which would display the post if the category of the post only contains one post.

    I have a category called TRIPS with a sub-category for each trip which only contains one post (for ease of finding).

    I would like to display the post when I click on the sub-category for that trip.

    Is this possible. I’m looking for an if…then, which would check the number of posts for the category, if more than 1, display the category.php file, if only one, display the single.php file for that post ID.

    Thanks in adavance.

    Jardry

Viewing 3 replies - 1 through 3 (of 3 total)
  • Kafkaesqui

    (@kafkaesqui)

    Hmm.

    I don’t know of such a plugin. I do know this, or something like this (typically for search results), has been asked for from time to time.

    Let me think about what would be needed to accomplish it. Meanwhile, if anyone else can add anything…

    Kafkaesqui

    (@kafkaesqui)

    Ok, I’ve come up with something.

    Swingle
    Download plugin | View source

    To install, download the swingle.php file, upload to the wp-content/plugins/ directory, and activate Swingle under Plugins.

    Notes:

    This plugin does not perform a redirect to the post. I looked at that, but the posts object (the only thing I can imagine testing on for this) is apparently not available until after the http header has been sent. That nixes the idea of a clean redirect to a post’s permalink. A dirty redirect may be possible, but just considering the steps needed to accomplish it quickly annoyed me.

    So, what does the plugin do? In the grand scheme of things, not much really. But I do find it a little cool.

    In summary, when you perform a query that can have multiple posts (category, search, archive or author), the plugin checks to see if there’s no second post in the posts object. If this is the case, it does some behind the scenes magic to convince WordPress we’re looking at a single post, then loads the single post template. This means the url is the same — recall I said no redirect occurs — but the query is displayed as a single post page.

    What testing I’m able to do is limited, so it’s possible I missed something in the broth. And with variations in theme templates and query coding (use of query_posts() will no doubt cause unexpected behavior), it will likely fail to work everywhere. But, it’s *A* solution.

    Thread Starter Jardry

    (@jardry)

    You’re a legend.

    Downloaded plugin, uploaded to plugins directory, activated, and it worked with no problems.

    I’m extremely grateful. Thank you for such a prompt response and solution.

    Jardry

    PS – I can live with the permalink not updating as I’m sure my readers wouldn’t know it is incorrect anyhow.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category or Post Plugin’ is closed to new replies.