WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Combination of two php code (4 posts)

  1. ezapmar
    Member
    Posted 1 year ago #

    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.

  2. bcworkz
    Member
    Posted 1 year ago #

    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.

  3. ezapmar
    Member
    Posted 1 year ago #

    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.

  4. bcworkz
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.