Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   [SOLVED] Recent posts of same category, on single post pages (http://forum.bytesforall.com/showthread.php?t=1491)

GeoParadise Apr 30, 2009 09:23 AM

[SOLVED] Recent posts of same category, on single post pages
 
Hello again! When the user is reading a post (on a sigle post page) which belongs to one category, is it possible that the next/prev page navigation shows only posts inside the same category? Or, if not possible, would it be possible to have in the sidebar a list of all the other posts on that category?
Because, currently it shows the newer/older post of all categories making it difficult to navigate inside one category without having to go back again to the category multipost page. I hope the question make sense.
Again, our blog is:
www.geoparadise.org/blog
Thanks in advance!
NOA

Flynn Apr 30, 2009 02:37 PM

You can put this into a PHP code widget http://wordpress.org/extend/plugins/php-code-widget/

PHP Code:

<?php if ( is_category() ) {
global 
$wp_query;
$current_cat_id $wp_query->get_queried_object_id(); ?>
<div id="category-posts-<?php echo $current_cat_id?>" class="widget widget_recent_entries">
<div class="widget-title"><h3><?php single_cat_title('Recently in '); ?>:</h3></div>
<div class="widget-content">
<ul>
<?php global $post$cat_posts get_posts('numberposts=10&category='.$current_cat_id);
foreach(
$cat_posts as $post) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php ?>


GeoParadise May 7, 2009 10:12 AM

Hello Flynn! Thanks for your answer.
I did it, but I canīt see any change at all!! What was supposed to be doing?

Noa

Flynn May 7, 2009 10:29 AM

It should have listed the recent posts of the given category in the sidebar, when on a category page. Did you install the plugin? After that you should put one instance of the PHP code widget into a sidebar, and into the widget put the above code

GeoParadise May 8, 2009 03:13 PM

Ok! Sorry, I was trying with the widget Php Code that comes with the theme, but now Iīve installed the plugin from your link and done everything again, and it certainly shows a list with the lasts posts of the category in the sidebar, like you said, but it does it in the Category MULTIPOST Page, which doesnīt give any extra functionality, as long as they are also listed in the center/main space.
What we would need and appreciate is to have that list/menu of the lasts entries on that category in the sidebar, but on the SINGLE Post Pages. (or otherwise, change the next/prev nav menu to show only post inside the category). I hope is possible...
Thanks again!
NOA

Flynn May 8, 2009 03:47 PM

Use this instead:
PHP Code:

<?php
if (is_single( )) {
$post_ID $wp_query->posts[0]->ID;
$all_cats_of_post get_the_category($post_ID);
$first_cat_ID $all_cats_of_post[0]->cat_ID;
$first_cat_name $all_cats_of_post[0]->cat_name;
?>
<div id="category-posts-<?php echo $first_cat_ID?>" class="widget widget_recent_entries">
<div class="widget-title"><h3>Recently in <?php echo $first_cat_name?>:</h3></div>
<div class="widget-content">
<ul>
<?php global $post$cat_posts get_posts('numberposts=10&category='.$first_cat_ID);
foreach(
$cat_posts as $post) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php ?>


paulae May 8, 2009 03:56 PM

I found a really easy way to do this: http://wordpress.org/extend/plugins/category-posts/

It's a widget that lets you put a certain number of posts from a category in the sidebar, showing up just in that category.

Grant R Brown Jan 4, 2010 09:47 PM

Hey Flynn,

Really like the code you got, but I was looking to take it one step further if you could assist. For each tagged category I want to create a list of their recent posts. I've been messing around with and haven't figured it our yet, but I'm thinking it would be something like:

for each cat
do this
end foreach

Looking forward to hearing your thoughts.

Thanks

Grant R Brown Jan 4, 2010 10:51 PM

Hey,

I was able to get it to work, here's the code in case anyone else has the same need:

Code:

<?php
if (is_single( )) {
        $post_ID = $wp_query->posts[0]->ID;
        $all_cats_of_post = get_the_category($post_ID);
        for($i = 0; $i < sizeof($all_cats_of_post); $i++) { ?>
   
            <li id="category-posts-<?php echo $all_cats_of_post[$i]->cat_ID; ?>" class="widget widget_recent_entries">
                        <h3>Recently in <?php echo $all_cats_of_post[$i]->cat_name; ?>:</h3>
                                <ul>
                                        <?php global $post; $cat_posts = get_posts('numberposts=3&category='.$all_cats_of_post[$i]->cat_ID); foreach($cat_posts as $post) : ?>
                                   
                    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                                       
                    <?php endforeach; ?>
                </ul>
                </li>               
       
        <?php } ?>
<?php } ?>

-Grant

etripp Apr 19, 2010 08:15 AM

hi, i just found this forum via google, and it looks like you guys are trying to do the same thing i am.
i have a sidebar that i call on my category archive pages, and single post pages, that pulls in all the post titles from the 20 most recent posts.

it has a serious problem though. for some reason, when i include it, all post links, and all links within the sidebar link to the most recent post only, even though the urls are correct for each specific link.

perhaps someone know what i'm doing wrong.

here's the code for sidebarright.php

PHP Code:

    <div id="sidebarright">
        <?php global $post$categories get_the_category(); foreach ($categories as $category) : ?>
        <h3>Previous posts:</h3>
        <ul>
        <?php $posts get_posts('numberposts=20&category='$category->term_id); foreach($posts as $post) : ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endforeach; ?>
        
        <li>View the full archive for<a href="<?php echo get_category_link($category->term_id);?>" title="View all posts filed under <?php echo $category->name?>"> <?php echo $category->name?> &raquo;</a></li>
        <?php endforeach; ?>
    </ul>
    </div>

the site i'm working on is: www.lgtrippgallery.com

thanks!

juggledad Apr 19, 2010 08:54 AM

etripp, this forum is for the Atahualpa theme and you are not using it. If you decide to switch, feel free to ask questions here.


All times are GMT -6. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.