Jump to content

Djoris

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Posts posted by Djoris

  1. I use the following code to output individual categories in the wordpress navigation:

     

    <?php echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2>$3</a>',wp_list_categories('echo=1&orderby=id&title_li&include=1897')); ?>

     

    This works great and gives the output:

     

    <li class="cat-item cat-item-1897"><a href="http:www.test.org/category/category-name/">category</a></li>

     

    For some categories I would like to add ?gpc_sortby=views to the end of the url. Does anybody know how I can change the preg replace to get this right.

     

    Thanks!

  2. What do you mean by "not working"? If you don't provide errors it seems like you don't want this solved.

     

    I sure would like this problem to be solved. When I try to parse the simple xml, I don't get any output at all, not even an error message.

     

    I spend a couple of days playing with the codes given in this thread but still don't get the comma's between the 'actors'. I tried the code:

     

    <?php
    $data = file_get_contents("XML URL");
    $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match);
    $str = implode(", ", $match[1]);
    echo $str; //echos actor#1, actor #2, actor #3
    ?>

     

    I think this should work but the preg match is not like it should be because the xml takes all the content between <actors></actors> and because the individual actors are also tagged it doesn't get it right:

     

    <actors>

    <actor id="1234">Actor #1</actor>

    <actor id="12345">Actor #2</actor>

    <actor id="123456">Actor #3</actor>

    </actors>

     

    I tried the preg match:

     

    $actors = preg_match_all("/<actor>(.+)<\/actor>/", $data, $match);

     

    But this doesn't give any output nor error messages. Anybody an idea how to get this right?

  3. I tried all the above codes but they didn't work. The simple xml gives no output at all and the other options give the Warning: implode() [function.implode]: Invalid arguments passed in /home/../public_html/wp-content/themes/test/single.php on line 132.

     

    I tried for example this:

     

    $data = file_get_contents("XML URL");
    $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match);
    foreach ($n_data->actor as $d) {
    
    $show[] = $d;
    }
    
    echo implode(", ", $show); 
    

     

    or this

     

    $data = file_get_contents("XML URL");
    // Build an array of actor names like array("Actor #1", "Actor #2", ...)
    $actors = array();
    foreach ($xml->actor as $actor) {
        $actors[] = (string) $actor;
    }
    
    // Echo with commas
    echo implode(", ", $actors);
    

     

    Any more tips would be appreciated. After that I promise I will buy a php book to avoid embarresing situations like this..

     

  4. I am sorry that I gave the impression that I didn't try, because I did. Tried several options including this one:

     

    <?php
    $data = file_get_contents("XML URL");
    $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match);
    $str = implode(", ", $match[1]);
    foreach ($match[1] as $actors)
    {
    echo $str; //echos actor#1, actor #2, actor #3
    } ?>
    

     

    I will have a another look at the implode function, but of course any reply is welcome ;)

  5. After a lot of lurking, thanks for all the great topics ;) I now have a guestion where I could really use your help.

     

    I am parsing some xml data with the following php:

     

    <?php
    $data = file_get_contents("XML URL");
    $actors = preg_match_all("/<actors>(.+)<\/actors>/", $data, $match);
    foreach ($match[1] as $actors)
    {
    echo $actors; 
    } ?>

     

    For the following XML part:

     

    <actors>

    <actor id="1234">Actor #1</actor>

    <actor id="12345">Actor #2</actor>

    <actor id="123456">Actor #3</actor>

    </actors>

     

    This gives the ouput: Actor #1 Actor #2 Actor #3

     

    Now I would like to separate the actor names by comma, like this: Actor #1, Actor #2, Actor #3

     

    Does anybody know how to modify the php code for this? Thanks  8)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.