WordPress.org

Forums

custom_field (image of a post) (3 posts)

  1. TrippleL
    Member
    Posted 5 years ago #

    Hello,
    I have a problem with the custom_field thing.
    I have a custom field with the name: featured_image
    This is because I have on my homepage a box where my latest post images comes (things from my portfolio)
    Now is the problem, that I also have this code on the portfolio page, but a little bit changed. The image's works, it is showing the right images, but the title of that post is wrong and the to the post. (at the link down here the title is fdgdf not Klant and Overige that are the categories) Here is the link from how it looks now LINK
    And here is the code I use:

    <?php
    /*
    Template Name: Portfolio
    */
    
    get_header(); ?>
    
    	.
    	<div class="balklang"></div>
    
        <div id="content">
    
        <?php get_sidebar(); ?>
    
        <div id="page">
    
            <div class="info">
    
                        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="contentber" id="post-<?php the_ID(); ?>">
    		<h2 style="margin-bottom: 15px;"><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    
            </div>
    
    <?php
    // page id 52 will get category ID 3 posts
    if (is_page('7') ) {
    $cat = array(11);
    } else {
    $cat = '';
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );
    $my_query = new WP_Query($args); 
    
    // loop over de subcategorien
    
    $categories=  get_categories('child_of=11');
    foreach ($categories as $cat) {
    ?>
    <h2 class="cat"><? echo $cat->cat_name; ?></h2>
    <?php
    	//echo "nieuwe cat".$cat->cat_name." ".$cat->cat_ID;
    	//The Query
    	query_posts('cat='.$cat->cat_ID);
    
    	//The Loop
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    	?>
            <div class="portcat" id="post-<?php the_ID(); ?>">
    
    				<div class="port">
    
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
                    	<?php
    		$featured_posts = get_posts('numberposts=1');
    
    		foreach( $featured_posts as $post ) {
    			$custom_image = get_post_custom_values('featured_image', the_ID());
    			$image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/images/geen-afbeelding.jpg";
    			printf('<div class="latestimage"><a href="%s" title="%s"><img src="%s" alt="%s" width="321" height="121" border="0" /></a></div>', get_permalink(the_ID), $post->post_title, $image, $post->post_title, get_permalink($post->ID));
    		}
    		?>
    
                        <p>
    
                        <strong><?php the_title(); ?></strong><br />
    
                        <?php excerpt('15', '<br />'); ?>
                        <br />
    
                        </p>
    
                    </div>
    
                    </div>
    
        <?php
    	endwhile;
    	else:
    	?>
    				<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    <?php
    	endif;
    
    	//Reset Query
    	wp_reset_query();
    	?>
    
    <?php
    }
    
    ?>
    
            </div>
            <div class="clear"></div>
    
        </div> <!-- End content -->
    
    </div><!-- End Container -->
    
    <?php get_footer(); ?>

    And this is the part where it's about I think:

    <?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
                    	<?php
    		$featured_posts = get_posts('numberposts=1');
    
    		foreach( $featured_posts as $post ) {
    			$custom_image = get_post_custom_values('featured_image', the_ID());
    			$image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/images/geen-afbeelding.jpg";
    			printf('<div class="latestimage"><a href="%s" title="%s"><img src="%s" alt="%s" width="321" height="121" border="0" /></a></div>', get_permalink(the_ID), $post->post_title, $image, $post->post_title, get_permalink($post->ID));
    		}
    		?>
    
                        <p>
    
                        <strong><?php the_title(); ?></strong><br />
    
                        <?php excerpt('15', '<br />'); ?>
                        <br />
    
                        </p>
    
                    </div>

    Could someone help me with this, i'm strugling with this for a long time!
    Thnxx!

  2. TrippleL
    Member
    Posted 5 years ago #

    somebody?

  3. TrippleL
    Member
    Posted 5 years ago #

    nobody please help men..

Topic Closed

This topic has been closed to new replies.

About this Topic