• akallen

    (@akallen)


    A while back, I created a news site that uses a thumb on the index page and a larger image on the single post page (styled differently). We don’t have the ability to upload images using wp, so we just upload into a folder using DW. I gave the administrator the code to place in the post to display the images accordingly. Therefore, none of the posts have a custom field for ‘post-image’ or ‘post-thumb’. I would like to add these custom fields now for all future posts but need for older posts to continue as originally designed.

    I bought Smashing WordPress and found the solution. For some reason, the code from the book seems to have an error according to my color coding in DW. Since I am not a programmer, I can’t find the error. Can anyone please help? The error appears to be in the following line:

    <?php if ($ncimage !== “) { ?>

    Thanks to all.

    <?php
    $max_entries_per_page = 25;
    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    //The Query
    query_posts("posts_per_page=6&paged=" . $paged);
    
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    
     <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<div class="home">
    	 <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    <?php $ncimage = get_post_meta($post->ID, 'post-thumb', $single = false); ?>
    <?php if ($ncimage !== ") { ?>
    <img src="<?php echo $ncimage; ?>" alt="<?php { echo the_title(); } ?>" class="thumb" />
    <?php } else { echo "; } ?>
    		<?php the_content('&nbsp;more &raquo;'); ?>
    
        </div>
    		<div class="clearer">&nbsp;</div>
    
    </div>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter akallen

    (@akallen)

    I’ve heard people complain about having “uncategorized” always checked and didn’t want to have to uncheck it. That’s what I want – “all” should be checked automatically.

    Thread Starter akallen

    (@akallen)

    I know this is off topic and I’ll post it to the forum if you can’t help me, but I tried the solution using a static home page. I followed the instructions in the codex, using my posts page template as the default (index.php). On index.php, I put the code we’ve been working on. Instead of listing the posts with the custom fields, it displayed my static home page. Why doesn’t it recognize index?

    Thanks again for all your help.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘conditionally adding image to post using custom field’ is closed to new replies.