Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Get the URL from the image I inserted in the HTML Editor.

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #39455
    chrisburton
    Participant

    I 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:

    • ">





    #108234
    chrisburton
    Participant

    I 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:
      if ( has_post_thumbnail()) {
      $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
      echo '
    • ';
      echo '1
      ';
      }
      ?>

    • ">





    #108235
    chrisburton
    Participant

    And 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.

    #108237
    wolfcry911
    Participant

    Not a wordpress guy, but try this:

    
    if( function_exists( 'attachments_get_attachments' ) )
    {
    $attachments = attachments_get_attachments();
    $total_attachments = count( $attachments );
    if( $total_attachments ) : ?>
      Process:
      if ( has_post_thumbnail()) {
      $large_image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
      echo '
    • ';
      echo '1
      ';
      }
      ?>

    • ">





    #108239
    chrisburton
    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') );
    #108285
    chrisburton
    Participant

    In 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:

    #108296
    chrisburton
    Participant

    Using 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 ) : ?>



Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘CSS’ is closed to new topics and replies.