Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1022590

    DwiceFox
    Participant

    Hi there! I need to create a link to the most recent post in different categories. I don’t want to list or show a preview of posts, I want to be able to have someone click on a category called “Art”, and it will automatically take them to the full, most recent post, with comments and all. I have some code that I think should work:

    <?php $cat_id = 7; //the certain category ID
    $latest_cat_post = new WP_Query( array(‘posts_per_page’ => 1, ‘category__in’ => array($cat_id)));
    if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post(); ?><h1><?php the_title(); ?></h1> <?php the_content(); ?><?php endwhile; endif; ?>

    But I have no idea which file to insert it into. I am using X/Cornerstone, so even though someone suggested putting this in functions.php, that didn’t work. I believe that works for some themes but not X/Cornerstone. Any ideas, by chance?? Thanks so much in advance!!

    #1023189

    Rad
    Moderator

    Hi there,

    Thanks for posting in.

    That will not work on functions.php , it’s loop and should be added to a template. Where do you wish to display it? Maybe I can point out the template that needs editing.

    Thanks!

    #1024696

    DwiceFox
    Participant

    Thanks so much for your help! We would like this to happen in a category (or ‘archive’ page). For example:

    http://www.dwicefox.com/archives/category/artandwit
    http://www.dwicefox.com/archives/category/drugsandgum

    We have 6 categories in total and would like to do it for each one.

    Thanks again!!

    #1025283

    Rad
    Moderator

    Hi there,

    They are already the category pages, in which it displays recent posts for that specific category. Hence, no need to add category ID, nor a loop.

    I’m not sure if I understand it correctly, would you mind providing a mockup design?

    Thanks!

    #1028763

    DwiceFox
    Participant

    Thank you for looking into this!! It’s so appreciated. I get why this might be confusing, but I don’t want users to just see the title or a list of most recent posts. I want them to be redirected to the MOST RECENT POST in ENTIRETY. So that would mean the content, the comments, etc. The actual blogpost itself, not a link. I don’t want users to have to click twice. So I guess what I need is a dynamic link to the most recent post in any category. Thanks again 🙂

    #1029384

    Paul R
    Moderator

    Hi,

    If I understood you correctly, you would like to redirect your category urls to your blog page?

    eg.

    Redirect http://www.dwicefox.com/archives/category/artandwit to http://www.dwicefox.com/blog ?

    You can try this third party plugin to redirect urls – https://wordpress.org/plugins/redirection/

    Hope that helps

    #1034747

    DwiceFox
    Participant

    Hi, no, that’s not what I mean lol. I’ll explain again. I have a blog. Within the blog are many categories. Art and Wit for example, is one. I would like to create a link that automatically displays the latest post in any given category. So, if I create a post today within the Art & Wit category, and someone clicks on this link, it will take them directly to that post. If I then create a new Art & Wit blogpost tomorrow, and someone clicks on that same link, it will then take them directly to the new blogpost. I do not want a list of posts. I want a redirect to the latest post WITHIN a category. In other words, I don’t want people to be able to look at an archive of posts with their titles. I want visitors, when viewing a category, to see the LATEST post, content, comments, and all. Since I have many categories, I would like this to happen for all of them. So, on my homepage, I will have links to each category, and instead of taking them to the “archives” page, which is just a list of recent posts, I would like each link to go DIRECTLY to the latest blogpost within that category. Does that make sense? Thanks again 🙂

    #1035259

    Rue Nel
    Moderator

    Hello There,

    Thank you for the clarifications! Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

    Thank you for your understanding.