private function GetChunkFromCategory() { if (is_null($this->source_id)) { $this->source_id = 1; } // Check for ShowNumberOfPosts behaviour if the requirements are met $default_query = 'cat=' . $this->source_id . '&showposts=1'; $behavioural_params = OnePanelConfig::GetBehaviorAlteration($this->config_module, 'ShowNumberOfPosts'); if (!$behavioural_params) { $query = $default_query; } else { $query = 'cat=' . $this->source_id . '&showposts=' . $behavioural_params[1]; } $recent = new WP_Query($query); global $post; $i = 1; while ($recent->have_posts()) { $recent->the_post(); // Declare Variables if (!isset($this->detail_chunks['Title'])) { $this->detail_chunks['Title']; } if (!isset($this->detail_chunks['Image' . ($i > 1 ? $i : '')])) { $this->detail_chunks['Image' . ($i > 1 ? $i : '')] = ''; } if (!isset($this->detail_chunks['SubTitle' . ($i > 1 ? $i : '')])) { $this->detail_chunks['SubTitle' . ($i > 1 ? $i : '')] = ''; } if (!isset($this->detail_chunks['Content' . ($i > 1 ? $i : '')])) { $this->detail_chunks['Content' . ($i > 1 ? $i : '')] = ''; } if (!isset($this->detail_chunks['NumberOfComments' . ($i > 1 ? $i : '')])) { $this->detail_chunks['NumberOfComments' . ($i > 1 ? $i : '')] = ''; } // Set up pointers $title_chunk =& $this->detail_chunks['Title']; $image_chunk =& $this->detail_chunks['Image' . ($i > 1 ? $i : '')]; $subtitle_chunk =& $this->detail_chunks['SubTitle' . ($i > 1 ? $i : '')]; $content_chunk =& $this->detail_chunks['Content' . ($i > 1 ? $i : '')]; $comments_chunk =& $this->detail_chunks['NumberOfComments' . ($i > 1 ? $i : '')]; // Do the title (Category Name) if ($i == 1) { $title_chunk = '<div class="' . $this->title . '-title">'; $title_chunk .= '<a href="' . get_category_link($this->source_id) . '" title="' . get_cat_name($this->source_id) . '">'; $title_chunk .= !is_null($this->title_limit) && strlen(get_cat_name($this->source_id) > $this->title_limit) ? substr(get_cat_name($this->source_id), 0, $this->title_limit) . '...' : get_cat_name($this->source_id); $title_chunk .= '</a>'; $title_chunk .= '</div>'; } // Comments, ripped off a load of wordpress code for this global $id; $comments_number = get_comments_number($id); if ($comments_number > 1) { $comments_output = str_replace('%', $comments_number, __('% Comments')); } elseif ($comments_number == 0) { $comments_output = OnePanelLanguage::GetText('no_comments'); } else { $comments_output = OnePanelLanguage::GetText('1_comments'); } $comments_chunk = '<div class="' . $this->title . '-comments-number">' . apply_filters('comments_number', $comments_output, $comments_number) . '</div>' . "\n"; // Check to see if we are supposed to use an alternate thumb $default_thumb = get_post_meta($post->ID, 'Thumbnail', true); $behavioural_params = OnePanelConfig::GetBehaviorAlteration($this->config_module, 'UseAlternateThumbnail'); if (!$behavioural_params) { $thumbnail = $default_thumb; } else { $alternate_thumb_object =& $behavioural_params[1]; $custom_field = $alternate_thumb_object->GetCustomField(); $thumbnail = get_post_meta($post->ID, $custom_field, true); if (empty($thumbnail)) { $thumbnail = get_post_meta($post->ID, 'Thumbnail', true); } } $image_chunk = '<div class="' . $this->title . '-image">'; $image_chunk .= '<a href="' . apply_filters('the_permalink', get_permalink()) . '">'; $image_chunk .= '<img alt="' . get_the_title() . '" src="' . $thumbnail . '" />'; // TODO check for behaviour modification $image_chunk .= '</a>'; $image_chunk .= '</div>'; $subtitle_chunk = '<div class="' . $this->title . '-subtitle">'; $subtitle_chunk .= '<a href="' . apply_filters('the_permalink', get_permalink()) . '">'; $subtitle_chunk .= !is_null($this->title_limit) && strlen(get_the_title()) > $this->title_limit ? substr(get_the_title(), 0, $this->title_limit) . '...' : get_the_title(); $subtitle_chunk .= '</a>'; $subtitle_chunk .= '</div>'; $content = get_the_content(OnePanelLanguage::GetText('read_more')); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); // Check to see if the content limit is behaviourally modified $behavioural_params = OnePanelConfig::GetBehaviorAlteration($this->config_module, 'LimitContent'); if ($behavioural_params) { if (is_int($behavioural_params[1])) { $content_limit = $behavioural_params[1]; } } else { $content_limit = $this->content_limit; } if (!is_null($content_limit)) { $content = strip_tags($content); $content = substr($content, 0, $content_limit); $content .= ' <div class="read-more"><a href="' . apply_filters('the_permalink', get_permalink()) . '">' . OnePanelLanguage::GetText('read_more') . ' </a></div>'; } $content_chunk = $content; $i++; } $response = $this->detail_chunks['Title'] . $this->detail_chunks['Image'] . $this->detail_chunks['SubTitle'] . $this->detail_chunks['Content']; if ($i < 1) { for ($j = 2; $j <= $i; $j++) { $response .= $this->detail_chunks['Image' . $j] . $this->detail_chunks['SubTitle' . $j] . $this->detail_chunks['Content' . $j]; } } return $response; }