Support » Plugins » Hacks » Combination of two php code

  • Resolved ezapmar



    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:

    $current_author = get_query_var('author');
    $author_posts=  get_posts( 'author='.$current_author.'&posts_per_page=-1' );
    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


    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)  {
     $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.

    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


    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.