WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Redirecting?

[Resolved] Redirecting?

  • I was wondering if anyone might be able to help me out.

    I am trying to automatically redirect my category-16.php on loading to a specific post within the category.

    I need it to go to the category page first so that the url registers (the post page pulls a sidebar dependent on the referring url) but then I would like to to go directly to the post of my choice within the category.

    Is it possible with just a bit of code, or do I need a plug-n or something?

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Jeremy Clark

    @jeremyclark13

    Member

    Your making it harder than needed. You just need to use this conditional tag. You can use something like this on your sidebar.php file.

    <?php if ( in_category('16') ): ?>
    Put your category's sidebar information here.
    <?php endif; ?>

    Im not sure if that will work. My posts fall under many categories each, I have it set up to put posts from the same category in the sidebar, based on which category archive they used to access the post.

    Im using $_SERVER[‘HTTP_REFERER’] to get that information. I just remembered that there was a flaw where unless you click a link, the referring url doesnt register. So it wouldnt register the url from the archive anyway.

    So it looks like im out of luck on this solution, off to find another one.

    Thanks

    Jeremy Clark

    @jeremyclark13

    Member

    I imagine the answer is somewhere.

    I have difficulties getting my head around this whole idea…
    If you would use any kind of “redirect” – that means your category #16 posts can never be listed (as they normally would in category archive view). So, what’s the point?

    Or, why not show ONLY that one favourite post of yours in that template file?

    Sorry, I just don’t see the reason for all this complication…

    jeremy–

    Sorry, I misunderstood you, the in_category is much simpler than what I was doing. I thought that you were saying to use is_category. Sorry again, you actaully helped me out huge.

    moshu —
    Do you know where I can find a resource on showing just a single post on the category page?

    Delete the Loop and use get_a_post plugin.
    That’s one way. I guess you could also write your own query_posts based Loop.

    Jeremy Clark

    @jeremyclark13

    Member

    You can look here.
    http://codex.wordpress.org/Theme_Development#Theme_Template_Files_List
    http://codex.wordpress.org/Category_Templates

    Basically all you need to do is if you theme doesn’t already have a category.php file then you need to create it. A good start is to copy the contents of the main.php and then edit out what you don’t need. Also if you only need the template to be different for this one category make the file category-16.php

    Then you need to edit the loop. Resources for that.
    http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Redirecting?’ is closed to new replies.
Skip to toolbar