• Resolved hansd

    (@hansd)


    Hello, I’ve just started to rebuild my webzine using WordPress. I have a question regarding the Link Manager. I’d like to have a separate page for each link category.

    For that purpose I created a Links template with the following code, for instance for category 1:

    <?php get_links('1', '<li>', '</li>', '<br />', FALSE, 'name', TRUE); ?>

    Then I created a Page with the link category as title, no content in the Post field and Links as template.

    This method works. But if I’d like to have 20 link categories, I would have to create both 20 pages and 20 templates. Would there be a method to achieve this with only one template, which uses a variable for the category? Perhaps I could distract the category name from the page title, or the category_id from a custom field?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Would there be a method to achieve this with only one template, which uses a variable for the category?

    Are you saying you want to set up one template for use with twenty Pages? If so, either of the “perhaps” options could work.

    This uses a custom field (‘linkcat’):

    <?php
    global $post;
    $custom = get_post_custom($post->ID);
    $linkcat = $custom["linkcat"][0];
    if($linkcat)
    get_links($linkcat, '<li>', '</li>', '<br />', FALSE, 'name', TRUE);
    ?>

    The next offers a way of passing Page title as the link category name:

    <?php
    global $post;
    get_linksbyname("$post->post_title", '<li>', '</li>', '<br />', FALSE, 'name', TRUE);
    ?>

    Thread Starter hansd

    (@hansd)

    Hi Kafkaesqui, thanks for your help.

    Your suggestions look exactly like what I was looking for. For some reason I don’t get either of them to work though.

    When I try the custom field option, no links show up. When I try the post_title solution, the links of all categories are displayed. Any idea why that would be?

    Thread Starter hansd

    (@hansd)

    OK, I’ve found out now that the code above works excellent in a Post template, but not on a static Page.

    What should I alter for that?

    Can’t say for sure, as I tested both on a regular ole’ Page template, and saw what you would expect.

    It’s possible the $post object is not available at the point the script runs on your Page(s). Try replacing the global scope on it to:

    global $post, $wp_query;
    $post = $wp_query->post;

    Thread Starter hansd

    (@hansd)

    Wonderful, that did the trick!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dynamic links template’ is closed to new replies.