• Resolved Tim_gassel

    (@tim_gassel)


    Hi,

    Is it possible to combine these codes?

    <?php echo do_shortcode('[wp-blogroll catname="XXX"]'); ?>

    <?php the_title(); ?>

    I want to replace XXX with the_title.

    Thanks,

    Tim

Viewing 8 replies - 1 through 8 (of 8 total)
  • http://codex.wordpress.org/Function_Reference/the_title

    to get the title as a string to use in php, use

    the_title('','',false) inplace of “XXX”

    (if that will work might depend on the location you are using it in)

    there might also be the possibility of adding `global $post;’
    and then use $post->post_title inplace of “XXX”

    Thread Starter Tim_gassel

    (@tim_gassel)

    Thanks for you answer!

    Unfortunately I can not make it work.
    I can’t program very well…

    I would be very grateful if someone can explain a little bit more?

    I use the code outside the loop.

    Thanks again!

    have you tried something like:

    <?php global $post;
    $title = $post->post_title;
    echo do_shortcode('[wp-blogroll catname=$title]'); ?>

    (untested)

    is ‘the_title()’ the title of a page or post?
    and where do you try to run this code?
    header?
    sidebar?

    Thread Starter Tim_gassel

    (@tim_gassel)

    Thanks,

    I tried the code, it doesn’t work.

    the_title() is the title of a page.
    I tried to run this code in my sidebar.

    it may need a ‘wp_reset_query();’ at the start of the code, to reset any distortions of the query_string through the main content.
    also added a test line to see the content of $title, to check if it got the right title:

    <?php wp_reset_query();
    global $post;
    $title = $post->post_title;
    echo $title; //for testing only, remove later
    echo do_shortcode('[wp-blogroll catname=$title]'); ?>

    (today is national wp-reset-query day ; lol 😉

    another test:
    add the title of the page manually into the variable, to check if the shortcode call works with a variable:

    <?php global $post;
    $title = 'Title of the Page';
    echo do_shortcode('[wp-blogroll catname=$title]'); ?>

    Thread Starter Tim_gassel

    (@tim_gassel)

    I tested both codes, but they didn’t work.
    The echo $title; test worked well, my title showed up.
    But in the string of the do_shortcode it still doesn’t work.

    I also tried to put my title manually in the variable. still with no result.

    Sorry I’m so difficult…

    another try (i just realized that the do_shortcode() function is expecting a string, which my earlier suggestion does not deliver)

    <?php wp_reset_query();
    global $post;
    $title = $post->post_title;
    echo $title; //for testing only, remove later
    echo do_shortcode('[wp-blogroll catname="' . $title . '"]'); ?>

    if that fails:
    is the short code self-made or from a plugin?
    if plugin, can you post the download link of the plugin?
    if self-made, could you paste the code into a http://wordpress.pastebin.com/ and post the link to it here?

    Thread Starter Tim_gassel

    (@tim_gassel)

    Yeah! The last code you gave worked.

    Thank you very much for this sulution.
    You saved my day.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Combine 2 codes’ is closed to new replies.