WordPress.org

Ready to get started?Download WordPress

Forums

How to use get_linksbyname to show only links related to a single post (2 posts)

  1. mauropr
    Member
    Posted 7 years ago #

    I'm asking for some help here, as I wasn't able to find any answer in the WP Support forum.

    My site has 3 different sessions for organizing the content. One is the "BLOG". The lother two are "PORTFOLIO" and "ARTIGOS", where I put some projects I developed as a designer, and some articles I wrote as a professor. Each session has it's own template, where it lists all the posts that are categorized as "portfolio" or "artigos" - this way I manage to exclude them from the "blog", and to show only the posts corresponding to each category on the specific category page, and a specific "single" page (so I can use different sidebars, different menu itens etc.).

    Here comes the tricky part.

    Some projects, as well as some articles, has links to other stuff. For instance, if the project is about a website, it has a link to it. An article could also have a link to a PDF version, whatsoever.

    I wanted these links to appears in a separeted column, separated from the text. I've created a sidebar for each template, to put this stuff. On this sidebar I've created a "link" session, to show the links related to the post.

    As the content is dinamic, I wanted to show the "links" session of the sidebar ONLY if the post showing on the singlepage has links. As I had no idea on how to do this, I've used the "link manager" to create the links to theses files (PDFs, URLs for other sites etc.). I've also created link-categories with the name of the projects and articles.

    By making this link-categories with the same name of the project and article titles, I've used the get_liknksbyname combined with the get_the_title to create a list, with the comands bellow:

    `
    <h4 class="submenu">Links</h4>
    <ul class="menu">
    <?php get_linksbyname(get_the_title(),
    '<li class="menu">', '

  2. ', '',
    FALSE, 'id', TRUE, FALSE, -1, TRUE);?>

    `

    It works fine, UNLESS...in case there is not a linkname corresponding to the title of the page,

    here are some examples:
    (posts that have links-categories with the same name as the post title)
    http://www.feiramoderna.net/blog2007/2003/01/14/big-brother-brasil/
    http://www.feiramoderna.net/blog2007/2004/05/23/paraty/

    (post that has no links-category with the same name as the post title)
    http://www.feiramoderna.net/blog2007/2006/07/24/taruira/

    As you can see, in the 3rd case, where there isn't a link-category name equals to the title of the post, the list is generated as if the "cat-name" parameter in the "get_linksbyname" tag is null, showing all the links that exists.

    What I wanted is to create a way to check this before going through the "get_linksbyname" function. So, first I should be able to check if there is a link-category equals to "the_title" of the post. In that case, it would follow the script. Otherwise, it wouldn't even show the component to start with.

    Is this possible? I'm sure there is better ways to do this, but this is the way I was able to come with by myself...if only I could do this check, I think it would work...all solutions I've found in the support forum needed to put a specific category. As the element is dinamic, it wouldn't work if I put it manually - it would result always the same list of links.

    I would really appreciate some help with this!

    I'm using WP 2.2.1, by the way. :-)

    Forgive me for my english. :-)

    thanks in advance!!!
    mauropr

  • mauropr
    Member
    Posted 7 years ago #

    I had some help from Otto, and we've gone in different way. Instead of using these get_linksbyname and instead of creating links and categories, I just used the Custom Fields on the Write Post area.

    This way, each post has it's own "related links information".

    To show these info in a different way than the default format of the the_meta() command, Otto came up with this:

    <?php $links = get_post_custom_values("links");?>
    <?php if (! empty ($links)):?>
    <h4 class="menu">links</h4>
    <ul>
    <?php foreach ($links as $link) {
    echo '<li>'.$link.'</li>'
    };
    </ul>
    <?php endif;?>

    This generates an unordered list of the links, if the post has any, in the singlepage.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags