Jump to content

CyberShot

Members
  • Posts

    322
  • Joined

  • Last visited

Everything posted by CyberShot

  1. I am working in wordpress. There is code that will get the category id of a category using the slug name of that category. So I have a category called homepage. I need the id of that category which should be 1. This will get that id $home = get_category_by_slug('homepage')->term_id; This code does return 1. What I wanted to do was modify it to take more parameters so that I could enter more than just one category and return them all. So I tried this $home = array(); $home[] = get_category_by_slug(array('homepage','blog'))->term_id; foreach($home as $key => $category){ echo $key; } I get this error: Warning: preg_match() expects parameter 2 to be string, array given in....
  2. I got it figure out. I think there was a problem somewhere further down in my code. When i replaced the file with an unedited version and then added in my code snippet, it worked. How do you mark a thread solved?
  3. The code should put out something like this query_posts($query_string . '&cat=-1,-5'); the line above should be making 5 posts I have on my page disappear, but they are still there. I have gone through the codex for two days now and everything in the documentation says that my code above should work. So I am thinking now that there is a missing ' at the end of the string. But I can't seem to make it work. So I thought that there was a way to view the output. I am trying to echo it right now to see but it looks good. I get -1,-5. I just need to make sure that the quotes are right and I can't see that.
  4. I am working with wordpress. I am using a chunk of code to get the category id's of 2 categories. when I do that, it outputs 1 and 5 which is correct. I then use that to change the query for the database so that it will exclude those categories. But for some reason the code is failing. I can't see why. Is there a way to see what php is generating? Like when you click view source from a web page. Is there a view source for php? This is the code //getting the option tree results $options = get_option('option_tree'); //looping through my key to get the values, this returns 1 and 5 foreach($options['exc_cat'] as $cat) { //concatenating my values into one string. I want the string to be -1,-5 $string .= '-' .$cat.","; } //trimming the trailing comma from the string, otherwise I would end up with -1,-5, $string = substr($string, 0, -1); // Delete the last character query_posts($query_string . '&cat=' . $string); //this is the line that I need to see exactly what it is sending to the database.
  5. I could see using the alternative when mixing html. I guess it would be easier to spot. That sounds like a good reason to make an alternative
  6. I am working with wordpress and I see a lot of "if" statements done like this if(condition): do something endif; I have always done it like so if(condition) { do something } what is the difference? does the first method have any advantages over the second method?
  7. Absolutely perfect my friend! That was an even better solution than I was hoping for. It worked perfect! I had to use the results in a wordpress query and getting the results out of the foreach loop made it great. Thank you.
  8. close, that gave me 551 instead of 5,1
  9. foreach($options['exc_cat'] as $cat) { echo $cat; } this code returns 1 5 I want it to display as 1,5 I have been searching and tried substr($cat, 0, -1) but this strips all the commas from the string. the way I am returning the value, it prints as 1,5, I need the last comma after the 5 to go away. But the substr strips all commas which just donned on me that the foreach loop loops through, returns 1, then loops again and returns 5, I want to combine the total overall results into one string so that I can strip the trailing comma.
  10. I am using a foreach loop to get the results of an array. My problem is that I need the results combined into one string. How can I accomplish this?
  11. well, I almost have it working. It removes one category but I think it is failing to remove the next one because of a trailing , It is returning -1,-5, instead of -1, -5 foreach($options['exc_cat'] as $cat) { query_posts($query_string . '&cat=-' . $cat . ','); } This is the only way I could get it to remove the category. One still stays on the page.
  12. okay, one more question. How do I use that out of the foreach loop? I need to put {$cat} into a wordpress query
  13. Wow!, that was a whole lot easier than I thought it was going to be. Thanks so much
  14. I am working with wordpress. I am using a plugin that gets options stored in an array in the database. This is how I get the options $options = get_option('option_tree'); echo $options['exc_cat']; the exc_cat is a key that stores a set of values. Right now with the code above, it echoes Array. If I do this echo $options['exc_cat'][0]; it returns 5. Which is what I would expect it to do. What I can't figure out is how to get it to store each value which should be a number into 1 variable. What I need to do is loop through each value that is stored in the exc_cat key, return the number seperated by a -1,. So the result should look like this -1, -5 1 and 5 should be the only two numbers stored in the array at this point. Can you help? Thanks
  15. I am running wamp 64 bit on windows 7. Everything was working fine. I am working on a wordpress theme. I opened up the apache modules menu and accidently clicked on something. I don't know which module it was. But I think it unchecked it and restarted wamp and now when I click on archives in my theme, it loads the index page and displays php on the screen rather than running the php. I tried setting other modules that I thought might have been the one and restared but I still get the same issue. Does anyone got a clue? Is there anyway to reset the modules to default configuration?
  16. I am working in wordpress and things are going good. I made a form, filled it with values and have been able to store those values in a database using a wordpress function. Now my issue is that I want learn how to write them into an array and store them that way. I have been looking at several different ways but can't figure out how to code it. This is my code now function add_slider_box(){ global $post; $imageurl = get_post_meta( $post->ID, 'imageurl', true ); $imagelink = get_post_meta( $post->ID, 'imagelink', true ); $imagecap = get_post_meta( $post->ID, 'imagecap', true ); ?> <div style="width: 50%" class="sliderbox"> <p><label for="imageurl">Image Url: <br /> <input type="text" class="widefat" id="imageurl" name="imageurl" value="<?php if( $imageurl ) { echo $imageurl; } ?>" /></label></p> <p><label for="imagelink">Image Link: <br /> <input type="text" class="widefat" id="imagelink" name="imagelink" value="<?php if($imagelink) { echo $imagelink; }?>" /></label></p> <p><label for="imagecap">Image Caption: <br /> <input type="text" class="widefat" id="imagecap" name="imagecap" value="<?php if( $imagecap ) { echo $imagecap; } ?>" /></label></p> <button class="remove_slide button-secondary">Remove This Slide</button> </div> <?php } function bigBusiness_save_slider_options($post_id){ global $post; if( $_POST ) { update_post_meta( $post->ID, 'imageurl', $_POST['imageurl'] ); update_post_meta( $post->ID, 'imagelink', $_POST['imagelink']); update_post_meta( $post->ID, 'imagecap', $_POST['imagecap'] ); } } so the update_post_meta function is what is saving the information into the database. How do I put that into an array? I was thinking foreach($_POST as $slides) $slides[] = array( 'imageurl' => '$_POST['imageurl'], 'imagelink' => $_POST['imagelink'], 'imagecap' => $_POST['imagecap']; ); I have been able to use the data out of the database by creating a function function get_half_slider_slides() { global $post; $imageurl = get_post_meta( $post->ID, 'imageurl', true ); $imagelink = get_post_meta( $post->ID, 'imagelink', true ); $imagecap = get_post_meta( $post->ID, 'imageurl', true ); return array( $imageurl, $imagelink, $imagecap ); } and then calling that function in my code like this $slide = get_half_slider_slides(); I thought since it returned an array that I would be able to do this $slides['imagelink'] $slides['imageurl'] but it doesn't work. What I am trying to do is populate the nivo-slider ( http://nivo.dev7studios.com ) with images from the database. I have been following a tutorial but since the license on the tutorial doesn't cover reusing the code, I am trying to rewrite it in a way that doesn't violate the license agreement. This code is so far is hacked together but completely different from the tut. Can you help? Thanks
  17. It seems to be working now. I think shutting down my computer fixed it somehow. Don't ask me how.
  18. I just set up wamp on my computer. I had phpmyadmin working. At the bottom of the screen it said that there was no password for the root user. I clicked on the privelages tab clicked edit next to root user and there was a password box there. I typed in a password, retyped the password in the second box and restarted wamp. Now when I go to phpmyadmin I get this error #1045 - Access denied for user 'root'@'localhost' (using password: NO) So I then navigated to wamp/apps/phpmyadmin3.3.9/config.inc.php and I found on line 16 $cfg['Servers'][$i]['password'] = ' '; so I typed my password in there and restarted wamp but I still get the error. What is missing?
  19. I just installed windows 7 64 on my computer. I tried moving the wamp folder from my old computer to the new one and tried to start wamp. It won't start, so I downloaded it again and reinstalled it. It still won't start. The red icon stays red. If I try to go to localhost, I get this error Count not execute menu item (internal error) [Exception] Count not execute run action: The system cannot find the file specified If I check the php_error.log, the last thing in it is Undefined offset: 1 in C:\wamp\scripts\refresh.php on line 385 can you help?
  20. I reinstalled wamp on my computer. I was trying to update the php version while trying to figure out why other things don't work on localhost. All of my websites still work, the databases work fine. But now phpmyadmin doesn't work anymore and I can't figure out why. I get this error when I click on phpmyadmin from the wamp menu You don't have permission to access /phpmyadmin/ on this server.
  21. I didn't realize that is what I was doing. I think I see what you mean. So I should not use the mysqli inside the class. How do I make this work?
  22. I thought query was a function of it's own. I don't know how to fix it
  23. I am trying to set up a class for my database connection. I have it working one way, this is a completely new method I am trying to learn. I have a file called MyClasses.php and in that file I did this. (I am following a not very well done tutorial) class MySQLDatabase { private $connection; function __construct(){ $this->open_connection(); } public function open_connection(){ $this->connection = new MySQLi('localhost','MyDatabase','password','billpay') or die($mysql->error); } } $database = new MySQLDatabase(); then in my index page where I want to begin by doing a query on the database, I did this <?php include MyClasses.php ?> $result = $database->query("SELECT * FROM names") or die($mysql->error); but that gives me this error Fatal error: Call to undefined method MySQLDatabase::query() in C:\wamp\www\BillPay\index.php I can't figure out how to get past it.
×
×
  • 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.