Splitting up text and images in a page (3 posts)

  1. TJong
    Posted 3 years ago #

    Hi all,

    I recently started looking for a plugin or a lil piece of code that can split the images of my page content. The idea is as follows; the text and the images both get a column next to each other. I found some solutions for this, but it only works with posts.. In conclusion i couldn't find an solution that could achieve what i want.

    Could someone help me with this?


  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    I found some solutions for this, but it only works with posts.

    as posts and pages are very similar organized, please post that solution as a starting point for further suggestions.

  3. TJong
    Posted 3 years ago #

    Thanks for your reaction, here is the code. I just noticed that this code only works for the first attachment.

    Function.php part

    function get_first_attachment() {
    	global $post;
    	$id = $post->ID;
    	$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order ASC') );
    	$tpl = get_bloginfo('template_url');
    	$nothing = $tpl.'/nothing.jpg';
    	if ( empty($attachments) )
    		return $nothing;
    		foreach ( $attachments as $id => $attachment )
    			$link = wp_get_attachment_url($id);
    		return $link;

    HTML Loop part

    <!-- put this inside the loops -->
    <div class="alignleft"><img src="<?php echo get_first_attachment(); ?>" width="150" height="150"></div>
    <div class="alignright">
    <!-- your title, text and meta goes here -->

Topic Closed

This topic has been closed to new replies.

About this Topic