943,175 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 193
  • PHP RSS
Sep 2nd, 2010
0

Wordpress Featured Posts Issue...

Expand Post »
Hey guys,

I am new to Wordpress and am having a slight issue. I have a "featured" posts section at the top of my index page that shows 3 recent posts from the featured category. Everything shows up fine except the post image. So I see the "post_summary" and the "post_type" (custom fields) but not the image from "post_image". I enter the picture like: /wp-content/uploads/2010/09/samplepicture.jpg

Any help would be greatly appreciated. Thank you...oh and the code is below : )


This is the code I have in the index.php to make it show up:

PHP Syntax (Toggle Plain Text)
  1. <!-- showcase -->
  2. <div id="showcase">
  3. <div id="showcase-inner">
  4.  
  5. <?php $dp_showcase = new WP_Query('cat=' . $dp_featured . '&showposts=3'); ?>
  6. <?php while ($dp_showcase->have_posts()) : $dp_showcase->the_post(); $more = 0; ?>
  7.  
  8. <div class="showcase-post">
  9. <?php if (get_post_meta($post->ID, 'post_image_value', true)) { ?><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>&amp;w=290&amp;h=239&amp;zc=1&amp;q=95" alt="<?php the_title(); ?>" /><?php } else if (get_post_meta($post->ID, 'post_showcase_value', true)) { ?><img src="<?php bloginfo('home'); ?><?php echo get_post_meta($post->ID, "post_showcase_value", $single = true); ?>" alt="<?php the_title(); ?>" /><?php } else { ?><img src="<?php bloginfo('template_directory'); ?>/images/showcase-placeholder.jpg" alt="" /><?php } ?>
  10. <div class="showcase-effects">&nbsp;</div>
  11. <div class="showcase-details">
  12. <?php if (get_post_meta($post->ID, 'post_title_value', true)) { ?><h3><?php echo get_post_meta($post->ID, "post_title_value", $single = true); ?></h3><?php } ?>
  13. <?php if (get_post_meta($post->ID, 'post_type_value', true)) { ?><p><?php echo get_post_meta($post->ID, "post_type_value", $single = true); ?></p><?php } ?>
  14. </div>
  15. <a href="<?php the_permalink() ?>">&nbsp;</a>
  16. </div>
  17. <?php endwhile; ?>
  18.  
  19.  
  20. </div>
  21. </div>
  22. <!-- /showcase -->

This is the code for the functions.php:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3.  
  4.  
  5. if ( function_exists('register_sidebar') )
  6. register_sidebar(1,array(
  7. 'before_widget' => '<div id="%1$s" class="sidebox">',
  8. 'after_widget' => '<br clear="all" /></div>',
  9. 'before_title' => '<div class="sidebox-heading"><h2>',
  10. 'after_title' => '</h2></div>',
  11. ));
  12.  
  13.  
  14.  
  15. // CUSTOM POST FIELDS///////////////////////////////////////////////////////////////////////////////////////////////////////////
  16.  
  17. $post_custom_fields =
  18. array(
  19. "post_image" => array(
  20. "name" => "post_image",
  21. "std" => "",
  22. "title" => "Post Image Path (eg. /wp-content/uploads/mypic.jpg):",
  23. "description" => ""
  24. ),
  25. "post_showcase" => array(
  26. "name" => "post_showcase",
  27. "std" => "",
  28. "title" => "Showcase Image Path (only required if image resizing is disabled):",
  29. "description" => ""
  30. ),
  31. "post_summary" => array(
  32. "name" => "post_title",
  33. "std" => "",
  34. "title" => "Short Title:",
  35. "description" => ""
  36. ),
  37. "post_type" => array(
  38. "name" => "post_type",
  39. "std" => "",
  40. "title" => "Post Type (Ex: Tutorial, Freebie, Interview, etc.):",
  41. "description" => ""
  42. )
  43.  
  44. );
  45.  
  46. function post_custom_fields() {
  47. global $post, $post_custom_fields;
  48.  
  49. foreach($post_custom_fields as $meta_box) {
  50. $meta_box_value = stripslashes(get_post_meta($post->ID, $meta_box['name'].'_value', true));
  51.  
  52. if($meta_box_value == "")
  53. $meta_box_value = $meta_box['std'];
  54.  
  55. echo '<p style="margin-bottom:10px;">';
  56. echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
  57. echo'<strong>'.$meta_box['title'].'</strong>';
  58. echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.attribute_escape($meta_box_value).'" style="width:98%;" /><br />';
  59. echo '</p>';
  60. }
  61. }
  62.  
  63. function create_meta_box() {
  64. global $theme_name;
  65. if ( function_exists('add_meta_box') ) {
  66. add_meta_box( 'new-meta-boxes', 'Additional Information', 'post_custom_fields', 'post', 'normal', 'high' );
  67. }
  68. }
  69.  
  70. function save_postdata( $post_id ) {
  71. global $post, $post_custom_fields;
  72.  
  73. foreach($post_custom_fields as $meta_box) {
  74. // Verify
  75. if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
  76. return $post_id;
  77. }
  78.  
  79. if ( 'page' == $_POST['post_type'] ) {
  80. if ( !current_user_can( 'edit_page', $post_id ))
  81. return $post_id;
  82. } else {
  83. if ( !current_user_can( 'edit_post', $post_id ))
  84. return $post_id;
  85. }
  86.  
  87. $data = $_POST[$meta_box['name'].'_value'];
  88.  
  89. if(get_post_meta($post_id, $meta_box['name'].'_value') == "")
  90. add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
  91. elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
  92. update_post_meta($post_id, $meta_box['name'].'_value', $data);
  93. elseif($data == "")
  94. delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
  95. }
  96. }
  97.  
  98. add_action('admin_menu', 'create_meta_box');
  99. add_action('save_post', 'save_postdata');
Similar Threads
Reputation Points: 45
Solved Threads: 5
Junior Poster
drewpark88 is offline Offline
177 posts
since Feb 2010
Sep 13th, 2010
0
Re: Wordpress Featured Posts Issue...
try this:
custom field name: post_image_value value: yourimageurl
custom field name: post_title_value value: your post title
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wpmonster is offline Offline
4 posts
since Sep 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: WordPress problem
Next Thread in PHP Forum Timeline: Inserting multiple rows with foreach





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC