Jump to content

Liberty53k

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Liberty53k

  1. In my own research, I had come across the in_array function and couldn't figure out to use it since the info was an object??? I tried putting your example in, and couldn't get it working... This seems like the right path though. I've now got something working, & I intend on tinkering some more with this idea, and see if I can work through it. I appreciate your input!! So now using this (and a slight modification) I've finally gotten something working with the desired output. Here's what I've got, in case anyone else want to see it... <ul id="reblog"> <? foreach ($xml->posts->post as $post) { ?> <li> <? // REGULAR POSTS if ($post['type'] == "regular" ){?> <? // if this is a status post with no title... if ($post->{'regular-title'} == "") {?> Regular Post: This is a status update <? ;} ?> <? // regular post with check for the "infographic" tag if(property_exists($post, 'tag')) { $count = count($post->tag); $i = 0; while($i <= $count) { if(isset($post->tag[$i]) && $post->tag[$i] == 'infographic') { $bunch[$i] = 'infographic'; $tag = true; } else { $bunch[$i] = 'non-infographic'; } $i++; } if($tag) {?> Regular Post: This is an infographic <? $tag = null;} else {?> Regular Post <? ;} } ?> <? } // PHOTO POSTS if ($post['type'] == "photo" ){ ?> Photo Post <? } // LINK POSTS if ($post['type'] == "link" ){ ?> Link Post <? } // Quote Posts if ($post['type'] == "quote" ){ ?> Quote POST <? } // CHAT POSTS if ($post['type'] == "conversation" ){ ?> Chat Post <? } // AUDIO POSTS if ($post['type'] == "audio" ){ ?> Audio Post <? } // VIDEO POSTS if ($post['type'] == "video" ){ ?> Video Post <? } ?> </li> <? } ?> </ul> /** <ul> <li>Video Post</li> <li>Video Post</li> <li>Photo Post <li>Regular Post</li> <li>Video Post</li> <li>Link Post</li> <li>Regular Post: This is an infographic</li> <li>Video Post</li> <li>Video Post</li> <li>Regular Post</li> <ul> */
  2. I spoke too soon.... Here's what I have based off of your post... <? // if the post is tagged "infographic" if(property_exists($post, 'tag')) { $count = count($post->tag); $i = 0; while($i <= $count) { if(isset($post->tag[$i]) && $post->tag[$i] == 'infographic') { echo 'infographic'; } else { echo 'non-infographic'; } $i++; } } ?> What I'm getting is something like this (each bullet represents a single post ): non-infographicnon-infographicnon-infographicnon-infographicnon-infographicnon-infographicnon-infographicnon-infographic non-infographicnon-infographicnon-infographicnon-infographicinfographicnon-infographicnon-infographic non-infographicnon-infographicnon-infographicnon-infographicnon-infographicnon-infographic What I'm trying to get is output that looks like this... non-infographic infographic non-infgraphic I do not NEED to print something for every single tag -- I only need to check the whole bunch of tags to see if something is indeed an "infographic"
  3. thank you!!!... I've been able to adapt this.
  4. I'm apologize for the lack of clarity. I'm not sure what would make it more understandable. // check the presence of 'tag' foreach($xml->posts->post as $post) { if(property_exists($post, 'tag')) { echo 'tag'; } else { // ... } } The effect of that code is that it's echoing the word "tag" for every occurrence of a tag on each post OR doing something else if it doesn't exist. What I'm trying to do is more narrow: Each blog post has a set of tags-- (ie "infographic", "news", "real estate", "buying a house", "foreclosure" ...etc) I want to be able to check for the the existence of a particular tag... (ie "infographic") and then if that particular tag exists.. do something.
  5. Thanks for the response… Not exactly what I'm trying to get at... Rather than printing all of the tags as being "infographic" or "non-infographic" -- what I'm trying to do is simply test to see if a certain tag is present --- and do something based on that or NOT if the infographic tag exists for this post.. {do this } else {do this}
  6. I'm working through some code to display a tumblr blog on a website. Each of Tumblr's post types are easy enough to get to... <ul id="reblog"> <? foreach ($xml->posts->post as $post) { ?> <li> <? // REGULAR POSTS if ($post['type'] == "regular" ){ echo "This is a regular post"; } // PHOTO POSTS if ($post['type'] == "photo" ){ echo "This is a photo post"; } // LINK POSTS if ($post['type'] == "link" ){ echo "This is a link post"; } // AUDIO POSTS if ($post['type'] == "audio" ){ echo "This is an audio post"; } ?> </li> <? } ?> </ul> What I'm trying to do is to check and see if certain tags are used on a post, and the based on that I'll be formatting the entry a little different. I can list all of the tags, but I'm stumped on how to check the existence of a certain tag in $post->{'tag'} $xml = simplexml_load_file('http://applesold.com/assets/cache/tumblrposts.txt'); <ul id="reblog"> <? foreach ($xml->posts->post as $post) { ?> <li> <? // REGULAR POSTS if ($post['type'] == "regular" ){ echo "type of post: regular<br>"; // THIS DOESN'T WORK -- if ($post->{'tag'} == "infographic") { echo "INFOGRAPHIC"; } else { echo "non-INFOGRAPHIC"; } } ?> </li> <? } ?> </ul>
×
×
  • 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.