WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Variable in function option (17 posts)

  1. mariatmind
    Member
    Posted 4 years ago #

    Hi i have a problem, i want pass the category title: single_cat_title() as a value for the function option....

    <?php wp_list_bookmarks('title_li=&categorize=0&show_name=1&show_description=1&category_name=single_cat_title()'); ?>

    ..bat it dosn't work .... please help me...

    Thank for all

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Try:

    <?php
    $ctitle=single_cat_title();
    wp_list_bookmarks('title_li=&categorize=0&show_name=1&show_description=1&category_name='.$ctitle); ?>
  3. mariatmind
    Member
    Posted 4 years ago #

    It doesn't work ... it ignore the $ctitle... any idea? ... thanks...

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    There's an error in your use of wp_list_bookmarks. There's no show_name parameter. Try

    <?php
    $ctitle=single_cat_title();
    wp_list_bookmarks('title_li=&categorize=0&show_description=1&category_name='.$ctitle); ?>
  5. mariatmind
    Member
    Posted 4 years ago #

    The how_name parameter exists in wp_list_bookmarks function

    if i use

    <?php wp_list_bookmarks('title_li=&categorize=0&show_name=1&show_description=1&category_name=CATEGORIATEST'); ?>

    it works

    the proble is to pass a variable as value for category_name option...

    Thanks for your time...

  6. mariatmind
    Member
    Posted 4 years ago #

    Noone knows if is possible?

  7. esmi
    Forum Moderator
    Posted 4 years ago #

    Is this code inside or outside The Loop?

    And my bad with show_name but it only work when show_images is TRUE.

    http://codex.wordpress.org/Template_Tags/wp_list_bookmarks

  8. mariatmind
    Member
    Posted 4 years ago #

    yes i have the image for the link and it is all ok with show name...

    the code is out of the loop...

  9. esmi
    Forum Moderator
    Posted 4 years ago #

    Try re-reading the Codex page. You need to set show_images to TRUE if you want show_name to work.

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 4 years ago #

    Using single_cat_title() as a parameter to category_name for wp_list_bookmarks doesn't even make any sense.

    Post categories and Link Categories are wholly separate. The single_cat_title() returns a post category, but bookmarks is expecting a link category.

    Won't work.

  11. mariatmind
    Member
    Posted 4 years ago #

    Hi OTTO

    i knw that the link category are different from post category, but i have the category with same name.

    EXAMPLE

    Link Category name -> MOTOR

    Post Category name -> MOTOR

    I put the code

    <?php wp_list_bookmarks('title_li=&categorize=0&show_name=1&show_description=1&category_name=single_cat_title()'); ?>

    in Categoy post page to show the link of the link category with same name.

    if i use

    <?php wp_list_bookmarks('title_li=&categorize=0&show_name=1&show_description=1&category_name=MOTOR'); ?>

    it works

    but i need to pass the single_cat_title() cvariable so it works for all category

    THANKS

  12. Adam Harley
    Member
    Posted 4 years ago #

    <?php wp_list_bookmarks('title_li=&categorize=0&show_name=1&show_description=1&category_name=single_cat_title()'); ?>
    You're trying to run a function inside of a string, which will make PHP treat it as part of the string. You need to append functions' output or use a variable and either append that or include it in a string surrounded by double quotes.

    single_cat_title by default outputs the category as text too, so you'd be better off doing something like:
    <?php wp_list_bookmarks( single_cat_title( 'title_li=&categorize=0&show_name=1&show_description=1&category_name=', false ) ); ?>
    (first parameter is the prefix, second tells PHP to return it as a string instead of outputting it)

  13. esmi
    Forum Moderator
    Posted 4 years ago #

    Which would be the same as:

    <?php
    $ctitle=single_cat_title();
    wp_list_bookmarks('title_li=&categorize=0&show_description=1&category_name='.$ctitle); ?>

    Yes?

  14. Adam Harley
    Member
    Posted 4 years ago #

    Not quite, you need to pass false as the 2nd argument to single_cat_title() for it to return rather than print the output. Sorry, I did see your post, but I think mariatmind just kind've skipped over it :)

  15. mariatmind
    Member
    Posted 4 years ago #

    Thanks Kawauso but i still have problems,

    with your code it dosn't filter the lik by category name,

    it shows links of all the link categoy...

    Any ideas???

  16. esmi
    Forum Moderator
    Posted 4 years ago #

    You're right. It should be:

    <?php
    $ctitle=single_cat_title('', false);
    wp_list_bookmarks('title_li=&categorize=0&show_description=1&category_name='.$ctitle); ?>

    {just in case anyone else reads this thread)

  17. mariatmind
    Member
    Posted 4 years ago #

    It works thaks esmi

Topic Closed

This topic has been closed to new replies.

About this Topic