WordPress.org

Ready to get started?Download WordPress

Forums

Page2Cat 2.5 (2 posts)

  1. melissasue
    Member
    Posted 6 years ago #

    I am using the Page2Cat plug in (http://wordpress.org/extend/plugins/page2cat/) and I am using the new feature to list the posts in each category. I've managed to make it look exactly like I want it, except I want the posts to display in date order, the oldest at the top and the newest at the bottom.

    I can't quite decipher how to do in the code for it:

    // filter the content of a page, check for tag and replace it with a list of posts in the requested category.
    // function heavily inspired from Alex Rabe NextGen Gallery's nggfunctions.php.
    function page2cat_content_catlist($content){
    global $post;
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<p><h3>".$title."</h3>"; else $output = "";
    				$output .= "<ul class='p2c_catlist'>";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
    						$output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "</ul></p>";
    			}
    		}
    	}
    return $content;
    }

    I'd rather not mess with it more than I already have. Thanks!

  2. jahbini
    Member
    Posted 5 years ago #

    Yes, I've looked at that code for quite some time. Not the easiest code to figure out. Quite frankly I have no clue what the '^\+' sequence is supposed to do. totally opaque and has no reference anywhere in the authors documentation or other description.

    You can put something like this in a post:
    <p>[catlist=10]</p>

    And it will give you a list of titles in that category as links. No description, no content, no styling. I'm sure some people will like it, but...

    Oh, and by the way. It makes you figure out what category ID's go with which category name.

    Also I have yet to get the 'page to category' connection thing to work. disappointing.

Topic Closed

This topic has been closed to new replies.

About this Topic