• Hey,

    I have this code:

    <?php 
    
    			// Categories of promos to pull in
    				$categories = get_post_meta($post->ID, "categories", true);
    				if($categories) {
    $catID = $categories;
    $categories = "cat=".$categories;  }
    
    				// OR use the items below:
    
    				// manually add images instead of using post thumbnail or custom field on other posts
    				$add_images = get_post_meta($post->ID, "add_images", true);
    				// manually add image URLs, used with above
    				$add_urls = get_post_meta($post->ID, "add_urls", true);
    				// manually add image titles, used with above
    				$add_titles = get_post_meta($post->ID, "add_titles", false);
    
    				// Posts per page
    				$posts_per_page = get_post_meta($post->ID, "posts_per_page", true);
    				if(!$posts_per_page){ $posts_per_page = "-1"; }
    			?>
    
    			<!--// updated 6.20.10 -->
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    			<?php endwhile; endif; ?>
                <!--// updated 6.20.10 -->
    
    			<?php
    
    				$count = 1;
    				$items = "";
    
    				// if custom field add_images is not set use post query
    				if(!$add_images)
    				{
    					// page size does not really apply since more posts are returned
    					// than displayed since a post thumbnail is required
    					$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    					query_posts($categories . "orderby=date&order=DES&posts_per_page=".$posts_per_page. "&paged=" . $paged);
    					// While there are promos to loop through...
    					while (have_posts()) : the_post();
    						$thumbnail = get_post_meta($post->ID, "thumbnail", true); // optional custom field inserted on POST being pulled in, not page tempalte
    						$thumbnail_link = get_post_meta($post->ID, "thumbnail_link", true); // optional custom field inserted on POST being pulled in, not page tempalte
    						if($thumbnail_link){ $url = $thumbnail_link; }else{ $url = get_permalink(); }
    
    						// If the posts have a post thumbnail OR
    						// the post has custom fields set for the thumbnail / thumbnail_link
    					if(has_post_thumbnail() || $thumbnail)
    						{
    							if($count % 4 == 0){ $extra_class='end'; }else{ $extra_class = ""; }
    							$items .= "<li class='item".$count." project-item ".$extra_class."'>";
    							$items .="<a href='".$url."'>";
    							if($thumbnail){
    								$items .= "<img src='".$thumbnail."' class='post-thumbnail' />";
    							}else{
    								$items .= get_the_post_thumbnail($post->ID, "gallery-project");
    							}
    							$items .="</a>";
    							$items .="<p><a href='".get_permalink()."'>".get_the_title()."</a></p>";
    							$items .= "</li>";
    							$count++;
    						}
    					endwhile;
    
    				}else{ /* custom field add_images is set/used */
    
    					$arr_slider_images = explode("|", $add_images);
    					$arr_slider_urls = explode("|", $add_urls);
    					$arr_slider_titles = explode("|", $add_titles);
    					$count = 1;
    					$i = 0;
    					foreach($arr_slider_images as $img)
    					{
    						if($count % 4 == 0){ $extra_class='end'; }else{ $extra_class = ""; }
    						$items .= "<li class='item".$i." project-item ".$extra_class."'>";
    						if($arr_slider_urls[$i]){ $items .= "<a href='".$arr_slider_urls[$i]."'>"; }
    						$items .= "<img src='".$img."' />";
    						if($arr_slider_urls[$i]){ $items .= "</a>"; }
    						if($arr_slider_titles[$i]){ $items .= "<p>" . $arr_slider_titles[$i] . "</p>"; }
    						$items .= "</li>";
    						$count++;
    						$i++;
    					}
    
    				}
    
    				// Only insert the list of items if count > 0, otherwise it will be empty
    				if($count > 0)
    				{
    					$output .= "<div id='container'>";
    					$output .= "<ul class='clean clearfix' id='project-thumbnails'>";
    					$output .= $items;
    					$output .= "</ul>";
    					$output .= "</div>";
    				}else{
    					$output .= "<p class='grid_12'>No gallery items to display.</p>";
    				}
    
    				// output promo
    				echo $output;
    
    			?>

    Which works brilliantly. It pulls in a certain category for a page. You can set the category via Custom Fields.

    Is there a way I can alter this so it pulls down certain posts with “tag5” which I have set in Custom Fields?

  • The topic ‘Pull in post with certain tag’ is closed to new replies.