Title: Combination of two php code
Last modified: August 20, 2016

---

# Combination of two php code

 *  Resolved [ezapmar](https://wordpress.org/support/users/ezapmar/)
 * (@ezapmar)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/combination-of-two-php-code/)
 * Hello,
 * I’m sure it can be very easy for some of you.
 * I need the combine two codes below:
 * It calls all posts of an author:
 *     ```
       <?php
       $current_author = get_query_var('author');
       $author_posts=  get_posts( 'author='.$current_author.'&posts_per_page=-1' );
       if($author_posts){
       foreach ($author_posts as $author_post)  {
        echo '<li><a href="'.get_permalink($author_post->ID).'">'.$author_post->post_title.'</a></li>';
       }
   
       }
   
       ?>
       ```
   
 * And it calls an image of custom field of every posts of an author:
 * `<a href= "<? the_permalink(); ?>" title="<? the_title(); ?>"><img src="<? echo
   get_post_meta($post->ID, 'kapakliste', true) ?>" /></a>`
 * But the second code calls only five images. I need all.
 * All answers will be appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/combination-of-two-php-code/#post-3400949)
 * Actually, the second code just displays the results of one element of a query
   you do not show, it could be altered to return all posts. No matter, this is 
   the critical section you need to replace in the first sample, I believe:
 *     ```
       foreach ($author_posts as $author_post)  {
        $a=get_permalink($author_post->ID);
        $b=get_the_title($author_post->ID);
        $c=get_post_meta($author_post->ID, 'kapakliste', true);
        echo "<li><a href='$a' title='$b'><img src='$c' /></a></li>";
       }
       ```
   
 * The rest is the same.
 *  Thread Starter [ezapmar](https://wordpress.org/support/users/ezapmar/)
 * (@ezapmar)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/combination-of-two-php-code/#post-3400976)
 * Thank you so much.
 * Actually i was using the both at the same now.
 * As you can easily understand, i’m listing the photos tagged as “kapakliste”
 * and also post names..
 * now, while i’m using that code you suggested i can list the photos without any
   issues but i can’t list the post names 🙂
 * What code should i use for that?
 * Thank you so much again.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/combination-of-two-php-code/#post-3400982)
 * Replace the last line with this:
    `echo "<li><a href='$a' title='$b'><img src
   ='$c' />$b</a></li>";` If the title ends up next to the image, and you need it
   below, add the following in front of the second ‘$b’: `<br style='clear: both;'
   >` Or if you prefer the title on top, move the second $b to before `<img src=...`
   and put a simple `<br>` right after the $b.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Combination of two php code’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/combination-of-two-php-code/#post-3400982)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
