bantersaurus Posted October 16, 2013 Share Posted October 16, 2013 Hi, I am trying to customise some php code in a wordpress theme - the developer has left the planet and need to find a solution. This is the current code: <?php if ( $i < 3 ) { echo '<li class="margin_r"><div class="port_tn"><a href="'; echo the_permalink(); echo '" >'; echo the_post_thumbnail( array(40,40, true, "title" => "")); echo '</a> </div></li>'; $i= $i+"1"; } else { echo '<li class="no_margin"><div class="port_tn"><a href="'; echo the_permalink(); echo '" >'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a> </div></li>'; $i = "0"; } ?> When the thumbnail is clicked it goes to the portfolio page. WHAT I WANT IT TO DO: I want it to open up the featured image of that portfolio post and open a pretty photo lightbox gallery instead. Skipping the single portfolio page. I then change the code to this code: <a href="<?php echo $image[0]; ?>" rel="prettyPhoto[portfolio-gallery]">'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a> this now does skip the portfolip page and opens the prettyphoto lightbox, but then says it cant find the image or the url is incorrect. Please could you assist in amending the code to make this work the url of the website is: http://www.hayleyclarke.co.za/website/ Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/ Share on other sites More sharing options...
cyberRobot Posted October 16, 2013 Share Posted October 16, 2013 Where does $image[0] come from? Also note that the following: <a href="<?php echo $image[0]; ?>" rel="prettyPhoto[portfolio-gallery]">'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a> ...should be <a href="<?php echo $image[0]; ?>" rel="prettyPhoto[portfolio-gallery]"><?php the_post_thumbnail( array (40,40, true, "title" => "")); ?></a> Note that I added the PHP tags around the call to the_post_thumbnail(). I also removed the "echo" since the_post_thumbnail() function automatically outputs the result. More information about the function can be found here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454104 Share on other sites More sharing options...
bantersaurus Posted October 16, 2013 Author Share Posted October 16, 2013 $image[0] comes from some prettyphoto code snippet that I sampled - its probably whats also causing the issue. What should I replace it with? also I have used your code and in place of the image thumbnail it now has "")); ?> instead. please advise why this would be? http://hayleyclarke.co.za/website/what-i-do/ Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454122 Share on other sites More sharing options...
cyberRobot Posted October 16, 2013 Share Posted October 16, 2013 I think the answer can be found here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail#Post_Thumbnail_Linking_to_Large_Image_Size So basically, you would do something like the following: <?php $postThumbInfo = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?> <a href="<?php echo $postThumbInfo[0]; ?>" rel="prettyPhoto[portfolio-gallery]"><?php the_post_thumbnail( array (40,40, true, "title" => "")); ?></a> More information about the wp_get_attachment_image_src() function can be found here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454131 Share on other sites More sharing options...
bantersaurus Posted October 17, 2013 Author Share Posted October 17, 2013 Thank for your help - I am still not getting it right with my limited php skills - can you recommend anyone I can pay to do it for me? Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454258 Share on other sites More sharing options...
cyberRobot Posted October 17, 2013 Share Posted October 17, 2013 I don't have any personal recommendations, but you could try out the PHP Freelancing section: http://forums.phpfreaks.com/forum/20-php-freelancing/ Note that you could also post your updated code and perhaps someone here can help. Note that we'll likely need to see more of the code than just the link. Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454274 Share on other sites More sharing options...
bantersaurus Posted October 17, 2013 Author Share Posted October 17, 2013 Thank s- I will check them out - but lets take your advice and put up the entire code in the hope someone can figure it out - I know its fairly simple and its a case of a ';' or '"' in the wrong place: I have highlighted the code I am trying to change in red and with it the code in blue is the code that seems to open the pretty photo but then cant find the featured image of the portfolio post - this is the best I have got it to work. <?php /*----------------------------------------------------------------------------------- Plugin Name: Sidebar Custom Portfolio Widget Description: A widget that allows the display of your recent projects. -----------------------------------------------------------------------------------*/ // Add function to widgets_init add_action( 'widgets_init', 'rd_s_portfolio_widgets' ); // Register widget function rd_s_portfolio_widgets() { register_widget( 'RD_S_Portfolio_Widget' ); } // Widget class class rd_s_portfolio_widget extends WP_Widget { /*-----------------------------------------------------------------------------------*/ /* Widget Setup /*-----------------------------------------------------------------------------------*/ function RD_S_Portfolio_Widget() { /* Widget settings. */ $widget_ops = array( 'classname' => 'rd_s_portfolio_widget', 'description' => __('A widget for the Sidebar or footer that displays your latest projects with a short excerpt.', 'framework') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'rd_s_portfolio_widget' ); /* Create the widget. */ $this->WP_Widget( 'rd_s_portfolio_widget', __('Sidebar or Footer Portfolio Widget', 'framework'), $widget_ops, $control_ops ); } /*-----------------------------------------------------------------------------------*/ /* Display Widget /*-----------------------------------------------------------------------------------*/ function widget( $args, $instance ) { extract( $args ); $title = apply_filters('widget_title', $instance['title'] ); /* Our variables from the widget settings. */ $number = $instance['number']; /* Before widget (defined by themes). */ echo $before_widget; /* Display Widget */ ?> <?php /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) echo $before_title . $title . $after_title; ?> <ul class="port_widget"> <?php $i = 0; $query = new WP_Query(); $query->query(array( 'post_type' => 'Portfolio' , 'posts_per_page' => $number, )); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?> <?php if ( $i < 3 ) { echo '<li class="margin_r"><div class="port_tn"><a href="'; echo the_permalink(); echo '" >'; echo the_post_thumbnail( array(40,40, true, "title" => "")); echo '</a> </div></li>'; $i= $i+"1"; } else { echo '<li class="no_margin"><div class="port_tn"><a href="'; echo the_permalink(); echo '" >'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a> </div></li>'; $i = "0"; } ?> <?php if ( $i < 3 ) { echo '<li class="margin_r"><div class="port_tn"><a href="<?php echo $image[0]; ?>" rel="prettyPhoto[portfolio-gallery]">'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a> </div></li>'; $i= $i+"1"; } else { echo '<li class="no_margin"><div class="port_tn"><a href="<?php echo $image[0]; ?>" rel="prettyPhoto[portfolio-gallery]">'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a> </div></li>'; $i = "0"; } ?> <?php endwhile; endif; ?> <?php wp_reset_query(); ?> </ul> <?php /* After widget (defined by themes). */ echo $after_widget; } /*-----------------------------------------------------------------------------------*/ /* Update Widget /*-----------------------------------------------------------------------------------*/ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['number'] = strip_tags( $new_instance['number'] ); /* No need to strip tags for.. */ return $instance; } /*-----------------------------------------------------------------------------------*/ /* Widget Settings /*-----------------------------------------------------------------------------------*/ function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' => 'Latest Projects', 'number' => 4 ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!-- Widget Title: Text Input --> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'framework') ?></label> <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" /> </p> <!-- Number of post to show : Text Input --> <p> <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e('Amount to show:', 'framework') ?></label> <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo $instance['number']; ?>" /> </p> <!-- Link to the portfolio page : Text input --> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454277 Share on other sites More sharing options...
cyberRobot Posted October 17, 2013 Share Posted October 17, 2013 Did you have the code where you tried fixing the issue? Note: when posting code here, please surround it with tags. It makes the post and code easier to read. To fix the issue, you could try the following: $postThumbInfo = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); if ( $i < 3 ) { echo '<li class="margin_r"><div class="port_tn"><a href="<?php echo $postThumbInfo[0]; ?>" rel="prettyPhoto[portfolio-gallery]">'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a></div></li>'; $i= $i+"1"; } else { echo '<li class="no_margin"><div class="port_tn"><a href="<?php echo $postThumbInfo[0]; ?>" rel="prettyPhoto[portfolio-gallery]">'; echo the_post_thumbnail( array (40,40, true, "title" => "")); echo '</a></div></li>'; $i = "0"; } Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454284 Share on other sites More sharing options...
bantersaurus Posted October 17, 2013 Author Share Posted October 17, 2013 nope still not - it may be that I am editing the wrong .php file Quote Link to comment https://forums.phpfreaks.com/topic/283007-echo-permalink-for-featured-image-in-wordpress-portfolio/#findComment-1454344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.