how to include any script output into WP_tag as a parameter? (6 posts)

  1. ulitka
    Posted 10 years ago #

    Hi all!
    I am trying to include a PHP (or cgi, doesn't matter) script output into a get_archives() tag instead 'before' parameter
    for example:
    <?php get_archives('postbypost','10','html','','<?php include('file.php'); ?>',''); ?>
    but i can't...
    how to do that?

  2. Kafkaesqui

    Posted 10 years ago #

    You can't nest <?php ... ?> tags.

    You could try include('file.php') as the argument, but that won't work in the way you're after as it outputs and evaluates the file contents rather than just return it as a string (which is what you need here). If your host is running PHP 4.3.0 or greater, use:

    <?php get_archives('postbypost','10','html','', file_get_contents('file.php'),''); ?>

  3. ulitka
    Posted 10 years ago #

    Thank you Kafka!
    It works great, but only for the file contents, not for the script output.
    Actually i want to have a random quote as 'before' parameter. Could you please help me with this?

  4. ulitka
    Posted 10 years ago #

    I am triyng to use 'witty text' rundomizer plugin like this:
    <?php get_archives('postbypost','5','html',witty(),'<br><br>',''); ?>
    but it works only for the first post from five. How to do it for all fives?

  5. Kafkaesqui

    Posted 10 years ago #

    You could assign the output of Witty Text to a variable, which is then passed to get_archives(). However, since Witty Text doesn't return its output, we'll have to work around that:

    $witty = ob_get_contents();
    get_archives('postbypost','5','html',"$witty",'<br /><br />','');

    Note this won't generate a new "witty text" for each line displayed through get_archives(). For something like that you're looking at customizing the get_archives() code.

  6. ulitka
    Posted 10 years ago #

    Thank you, Kafka!
    It works great.
    I'll try to customize function get_archives()
    Are you talking about this code (from /wp-includes/template-functions-general.php)?
    /* link navigation hack by Orien http://icecode.com/ */
    function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
    $text = wptexturize($text);
    $title_text = wp_specialchars($text, 1);

    if ('link' == $format) {
    return "\t<link rel='archives' title='$title_text' href='$url' />\n";
    } elseif ('option' == $format) {
    return "\t<option value='$url'>$before $text $after</option>\n";
    } elseif ('html' == $format) {
    return "\t

  7. $before$text$after
  8. \n";
    } else { // custom
    return "\t$before$text$after\n";

Topic Closed

This topic has been closed to new replies.

About this Topic