Tagged: x
-
AuthorPosts
-
June 2, 2016 at 12:26 pm #1022590
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!!
June 2, 2016 at 7:15 pm #1023189Hi 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!
June 3, 2016 at 3:10 pm #1024696Thanks 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/drugsandgumWe have 6 categories in total and would like to do it for each one.
Thanks again!!
June 4, 2016 at 12:15 am #1025283Hi 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!
June 6, 2016 at 4:28 pm #1028763Thank 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
June 7, 2016 at 1:44 am #1029384Hi,
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
June 9, 2016 at 4:48 pm #1034747Hi, 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
June 9, 2016 at 11:26 pm #1035259Hello 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.
-
AuthorPosts