WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Template tag to PHP variable (6 posts)

  1. clarke1866
    Member
    Posted 8 years ago #

    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

  2. clarke1866
    Member
    Posted 8 years ago #

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

  3. Kafkaesqui

    Posted 8 years ago #

    "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.

  4. clarke1866
    Member
    Posted 8 years ago #

    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.

  5. clarke1866
    Member
    Posted 8 years ago #

    Your suggestions work elegantly, thanks again.

  6. alligator
    Member
    Posted 8 years ago #

    What about
    get_archives();

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

Topic Closed

This topic has been closed to new replies.

About this Topic