• Resolved clarke1866

    (@clarke1866)


    I have written a nifty plugin, but I cannot for the life of me assign template tags to $variables. Here is the unworking code I have and the template tags I would like assigned to variables.

    $var_the_perm = the_permalink()
    $var_the_title = the_title();
    $var_the_blogurl = bloginfo(‘url’);
    $var_the_blogname = get_bloginfo(‘name’);

    Anyone have any ideas? Being able to do this would really bring down the # of queries.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter clarke1866

    (@clarke1866)

    Bump because it fell off all the main pages. Sorry, but I’d really like to know…

    Bump because it fell off all the main pages.

    Wouldn’t it be fun around here if we all began bumping forum posts for just that reason? . . .

    Your last var:

    $var_the_blogname = get_bloginfo('name');

    should work because get_bloginfo() returns a value instead of displaying (i.e. echoing) it. So your last two can be:

    $var_the_blogurl = get_bloginfo('url');
    $var_the_blogname = get_bloginfo('name');

    The first two require a bit more, though. As post-related vars, they need access to the $post object. For a plugin, you can try this bit of code to do just that:

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

    $var_the_perm = get_permalink($post->ID);
    $var_the_title = $post->post_title;

    Keep in mind this works if a function in your plugin is called within The Loop or the plugin runs on a single post (or Page). Otherwise calling up the $post object in this way may not work as expected.

    Thread Starter clarke1866

    (@clarke1866)

    Ahhh… that should work excellently — thankyou very much! And with the search function currently fubar, I personally find it hard to discover posters whose questions languish into the ether in order to help them.

    Not only that, but I find that this forum is amazingly adept and answering questions quickly. So when I see my questions vanish I begin to think that they have just been lost in the fuzz.

    Regardless, thanks for your suggestions, I will publish my results for all shortly.

    Thread Starter clarke1866

    (@clarke1866)

    Your suggestions work elegantly, thanks again.

    What about
    get_archives();

    Don’t work:
    $get_archives = get_archives();

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Template tag to PHP variable’ is closed to new replies.