- This topic is empty.
-
AuthorPosts
-
August 20, 2012 at 9:00 pm #39455
chrisburton
ParticipantI am using the Attachments Plugin (http://wordpress.org/extend/plugins/attachments) to use for a slideshow-like effect.
Result: Process: 1 2 3
Now what I’m trying to do is make it so the image I insert in the HTML editor (post_content) will link to 1 and the attachments from the plugin will apply to the rest. However, depending on the number of attachments I have, should reflect on the numbers outputted.
Example (Let’s say I have 4 attachments)
Process: 1 (post_content image) 2 3 4 5 (attachment images)Here is the code I have so far that reflects the attachments. What I need help with is how to display the URL of the post_content image to apply to 1.
if( function_exists( 'attachments_get_attachments' ) )
{
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>
- Process:
- ">
August 20, 2012 at 10:02 pm #108234chrisburton
ParticipantI believe I have solved this. Not exactly sure if it will work overall since I only tested on one page. Perhaps more advanced WP developers can chime in.
Here is the following code:
if( function_exists( 'attachments_get_attachments' ) )
{
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>
- Process:
- ';
echo '1';
}
?>
- ">
if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo '
August 20, 2012 at 10:10 pm #108235chrisburton
ParticipantAnd it doesn’t work. Without noticing the code right away, it uses the post_thubmnail, not the actual full image which is what I need.
August 20, 2012 at 11:06 pm #108237wolfcry911
ParticipantNot a wordpress guy, but try this:
if( function_exists( 'attachments_get_attachments' ) )
{
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>
- Process:
- ';
echo '1';
}
?>
- ">
if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo '
August 20, 2012 at 11:43 pm #108239chrisburton
Participant@wolfcry911 What that does is give the permalink to the post not the image file (which is what I need). The following code below is what I believe to be the issue however I don’t know how to call the image I inserted inside the editor.
$large_image_url = wp_get_attachment_url( get_post_thumbnail_id('full') );
August 21, 2012 at 2:10 pm #108285chrisburton
ParticipantIn case anyone doesn’t understand. ALL I need is to get the URL of the image I inserted into the HTML editor in the backend. I believe in order to get that, I need to use wp_get_attachment_src however I’m not sure how to go about getting the ID dynamically.
End result:
August 21, 2012 at 5:19 pm #108296chrisburton
ParticipantUsing a function, I believe I have solved the issue.
I placed this code in my functions.php file that allows me to grab the very first image in a post.
// CREATES A FUNCTION TO GRAB FIRST IMAGE OF A POST
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}From there I can echo the URL using the following
The end result would look like this
$meta = $custom_metabox->the_meta('description', TRUE);
if (!empty($meta)):
echo ''.$meta.'
'; ?>
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.