WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to link Post in Custom Field Loop.. HELP (14 posts)

  1. Janu Studio
    Member
    Posted 3 years ago #

    Hi there all, i am coding & i am getting little problem which is that i am getting a featured post by adding a custom field and i found a custom loop which grabs the custom field post and displays as a heading what i want is the post is not showing link like

    i have a H1 heading its showing its head from Post title but the permalink to that post is not working like the heading is not a link its just a head simple without link to its post can anyone tell me how to add link to that post.. i tried to add the_permalink under the_title(); but no success... i want to link this H1 heading to its post which its showing... thanks

    <h1>
    <?php if (have_posts()) :
    while (have_posts()) : the_post();
    $customField = get_post_custom_values("Featured");
    if (isset($customField[0])) {
    //Custom field is set, display post info
    the_title();
    }
    endwhile;
    endif;
    ?>
    </h1>

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    have you tried the permalink:
    I'm not sure what you want to do, but maybe this will help

    <?php if (have_posts()) :
    while (have_posts()) : the_post(); ?>
    <h1>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php
    $customField = get_post_custom_values("Featured");
    if (!empty($customField[0])) {
    //Custom field is set, display custom field
    echo $customField[0];
    } else { the_title(); }
    endwhile;
    endif;
    ?>
    </a>
    </h1>
  3. Janu Studio
    Member
    Posted 3 years ago #

    Thanks buddy but it doesnt works.. its showing all of the post...

    I have front Page and it shows 5 headings... what i want is i want to show the heading but it must be linked to the post which its showing look here how it must work..

    <h1>OBAMA : 'EGYPT WILL NEVER BE THE SAME'</h1>

    *where PERMALINK should be the link to the Post of Obama as written.

    Like without href it will show no link i want to show link but it must be linked to the following post like a normal post title is with its permalink...

  4. Janu Studio
    Member
    Posted 3 years ago #

    When I added the_permalink(); after the the_title(); it shows the permalink of the post after the heading like instead of linking the post to its link.

    OBAMA : 'EGYPT WILL NEVER BE THE SAME'http://localhost/mynews/?p=103

    <h1>
    <?php if (have_posts()) :
    while (have_posts()) : the_post();
    $customField = get_post_custom_values("Featured");
    if (isset($customField[0])) {
    //Custom field is set, display post info
    the_title();
    the_permalink();
    }
    endwhile;
    endif;
    ?>
    </h1>
  5. keesiemeijer
    moderator
    Posted 3 years ago #

    This is how you show the permalink with the title:

    <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

    What is the custom field doing?

  6. Janu Studio
    Member
    Posted 3 years ago #

    Man i know how to show the link but the loop for custom field i am using is not accepting any permalink template tag... &

    What Custom Field is doing is look here

    1. I have a News Headline Post with Custom Field Added with Name:Featured & Value:1

    2. Then What the loop is doing is it searches for the Post with Custom field containing Name:Featured & Value:1 and shows in the H1 tag...

    its working alright but what the problem is its not showing H1 with link to the post...

    The Post using Custom Field has Post ID# 294... what loop is doing it does shows the Title of the post ID# 294 but doest not link it to the post# 294 as a link...

    Now are u clear what i want..? thanks buddy for helping me out...

    This loop is showing the H1 like dead without link

    OBAMA : 'EGYPT WILL NEVER BE THE SAME'

    INSTEAD OF SHOWING LIKE THIS AS A LINK

    OBAMA : 'EGYPT WILL NEVER BE THE SAME'

  7. keesiemeijer
    moderator
    Posted 3 years ago #

    Still not clear but:

    <?php
    $customField = get_post_custom_values("Featured");
    if (isset($customField[0])) :
    ?>
    <h1><a href="<?php the_permalink(); ?>" title="<?php echo $customField[0]; ?>"><?php echo $customField[0]; ?></a></h1>
    <?php endif; ?>
  8. Janu Studio
    Member
    Posted 3 years ago #

    Man thats still not working...

    I already told what i want in the post above
    in http://wordpress.org/support/topic/how-to-link-post-in-custom-field-loop-help?replies=7#post-1955091

  9. Janu Studio
    Member
    Posted 3 years ago #

    HELLO ANY ONE TO HELP... Its urgent plz... I will be thankful

  10. Janu Studio
    Member
    Posted 3 years ago #

    *BUMP*

  11. keesiemeijer
    moderator
    Posted 3 years ago #

    What you want to do is show the title of one post with a custom field featured linking to the post.

    This shows the last post (with a custom field Featured) title linked to the post:

    <?php $my_query = new WP_Query('posts_per_page=1&meta_key=Featured');
    while ( $my_query->have_posts() ) : $my_query->the_post() ?>
    <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    <?php endwhile ?>
  12. Janu Studio
    Member
    Posted 3 years ago #

    WHOAAAAAAAAAA!!!!! Man u did it....!!!!!! Its exactly working as said... your as genius........ THANKS A TONSSS!!!!!!! HATS OFF TO YOU...!!!! THANKS A MILLIONS MAN!!! You saved the day!!!

    Exactly man what i am doing is i have a homepage like
    http://www.huffingtonpost.com/

    I am just trying to get the featured posts as the above site has it features many posts so i was searching for any plugin but fail to find so just doing the work with the help of custom fields.. this is helping me... can u suggest any thing else

  13. Janu Studio
    Member
    Posted 3 years ago #

    THANKS A MILLION @KEESIEMEIJER BUDDY!!!

  14. keesiemeijer
    moderator
    Posted 3 years ago #

    you're welcome. Glad you got it how you wanted it.

Topic Closed

This topic has been closed to new replies.

About this Topic