Wordpress and Webdesign Forum go41 » WordPress Code Snippets

  1. omerkhan02
    Member

    Hi Joern,

    I figured out my last issue. I am using realpress a property search and listing plug in for wordpress. The problem is that when you enter a search for a particular property, the resulting listing only gets you the title of the property and the excerpt, not the image. I have to add an html <img> tag inside the excerpt
    everytime I write a post. I much rather set a custom field and simply cut/paste the absolute path to the image in it and then update/publish my post. That is only possible if the custom field is read in the index.php file so that each post automatically generates an image.

    Can you tell me what is the code that will cause the php code to include an image.

    and where would I put it.

    Here is my index.php file

    <?php get_header(); ?>
    <div class="span-24" id="contentwrap">
    <div class="span-16">
    <div id="content">
    <?php if(is_home()) { include (TEMPLATEPATH . '/featured.php'); } ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2 class="title">" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>
    <div class="postdate">Posted by <?php the_author() ?> on <?php the_time('F jS, Y') ?> <?php if (current_user_can('edit_post', $post->ID)) { ?> | <?php edit_post_link('Edit', '', ''); } ?></div>
    <div class="entry">
    <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(200,160), array("class" => "alignleft post_thumbnail")); } ?>
    <?php the_excerpt(''); ?>
    <div class="readmorecontent">
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Read More »
    </div>
    </div>

    </div><!--/post-<?php the_ID(); ?>-->

    <?php endwhile; ?>
    <div class="navigation">
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    <?php } ?>
    </div>
    <?php 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; ?>
    </div>
    </div>

    <?php get_sidebars(); ?>
    </div>

    <?php get_footer(); ?>

    Thanks

    Omar

    Posted 1 year ago #
  2. so you managed the category 3 problem, okay.

    Here it's about the post thumbnail, where you could easily use the function like in arthemia to query for a custom field and load an image if there is.

    basicly you have to replace this code from sample above:
    <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(200,160), array("class" => "alignleft post_thumbnail")); } ?>

    with a code as in arthemia. I give you a sample without that timthumb stuff, but you should size the image manually to 200x160px

    Modified Arthemia code looks like this:

    <?php $values = get_post_custom_values("Image"); if (isset($values[0])) { // checks for custom field Image and shows it if there is ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
    <img src="<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="<?php the_title(); ?>" class="alignleft post_thumbnail" width="200px" height="160px" /></a>
    <?php } ?>

    Above code links the image to the post, the 'a href' stuff is around.

    Without link like this:

    <?php $values = get_post_custom_values("Image"); if (isset($values[0])) { // checks for custom field Image and shows it if there is ?>
    <img src="<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="<?php the_title(); ?>" class="alignleft post_thumbnail" width="200px" height="160px" />
    <?php } ?>

    you should be able to create a custom field 'Image' and paste in the value either a path on your site like /wp-content/uploads/picture.jpg and it should also work with a path including http:/ ... in front.
    The img class I used as in your code, so styling should be the same, try it!

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

Join us! or log in (lost password?):