ryancolins
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: using get_posts to grab from specific categoryYep! That fixes it! Thanks for putting up with my nonsense Otto.
Forum: Fixing WordPress
In reply to: using get_posts to grab from specific categoryI don’t expect you to write the page for me, just wanting to know how to implement this correctly.
I’m getting a “Fatal error: Call to undefined method WP_Query::has_posts()” on line 21, line 21 being the “while($myposts->has_posts()) { $myposts->the_post();” line.
Anyone mind telling me what this means and how I fix it?Forum: Fixing WordPress
In reply to: using get_posts to grab from specific categoryhere, let me just make this easier and post the whole code:
I am using a template that posts all the images in one gallery, ordering them by year. As I said before, I want to put make multiple galleries, putting images in separate pages, seperated by what category was.This is the original code for the template:
if (have_posts()) : while (have_posts()) : the_post(); ?> <div id="pagecontent"> <h2><?the_title();?></h2> <?the_content('');?> <?php $posts = get_posts('numberposts=-1&order=DESC'); $postyear = 0; foreach ($posts as $post) { $this_postyear = intval(substr($post->post_date, 0, 4)); if ($this_postyear != $postyear) { $postyear = $this_postyear; echo '<h2 class="mosaicheader">'.$postyear.'</h2>'; } $image = YapbImage::getInstanceFromDb($post->ID); if ($image->width > $image->height) { $thumb_param = array( 'sx='.intval(($image->width - $image->height)/2), 'sy=0', 'sw='.$image->height, 'sh='.$image->height ); } elseif ($image->width < $image->height) { $thumb_param = array( 'sx=0', 'sy='.intval(($image->height - $image->width)/2), 'sw='.$image->width, 'sh='.$image->width ); } else { $thumb_param = array(); } array_push($thumb_param, 'h=100', 'q=70'); echo '<a href="'.get_permalink($post->ID).'">'; echo '<img class="mosaic" src="'.$image->getThumbnailHref($thumb_param).'" />'; echo '</a>'; } ?>
Now I get rid of the code that separates and order it by date, but because I don’t want that and add your code and I get:
if (have_posts()) : while (have_posts()) : the_post(); ?> <div id="pagecontent"> <h2><?the_title();?></h2> <?the_content('');?> <?php $page-title = get_the_title(); $myposts = new WP_Query('category_name='.$page-title); while($myposts->has_posts()) { $myposts->the_post(); ... do all the normal loop here ... } foreach ($posts as $post) { $image = YapbImage::getInstanceFromDb($post->ID); if ($image->width > $image->height) { $thumb_param = array( 'sx='.intval(($image->width - $image->height)/2), 'sy=0', 'sw='.$image->height, 'sh='.$image->height ); } elseif ($image->width < $image->height) { $thumb_param = array( 'sx=0', 'sy='.intval(($image->height - $image->width)/2), 'sw='.$image->width, 'sh='.$image->width ); } else { $thumb_param = array(); } array_push($thumb_param, 'h=100', 'q=70'); echo '<a href="'.get_permalink($post->ID).'">'; echo '<img class="mosaic" src="'.$image->getThumbnailHref($thumb_param).'" />'; echo '</a>'; } ?>
If I am screwing this up somewhere, and I can assure you I am as I am very new to php/wordpress, please let me know. Not only do I want to be able to get this to work, but I want to learn. Sometimes it all seems to overwhelm me though.
Forum: Fixing WordPress
In reply to: using get_posts to grab from specific categoryI’m using it for part of photo blog using yet-another-photoblog plugin.
I’m using the code I am asking about to generate multiple image gallery pages for the photoblog. Each category the pictures are filled under will be a different gallery, thus I want it to only grab the posts that match the title of the page.I tried the code you gave me, its giving me a
parse error: syntax error, unexpected ‘=’ on line 19.Line 19 is the $page-title = get_the_title():