Jump to content

Lassie

Members
  • Posts

    390
  • Joined

  • Last visited

Everything posted by Lassie

  1. Hi I have solved my problem and post my revised code in case it of help to anyone. I am sure it can be improved and it feels a long winded piece of code but thats where my abilities are right now. Good luck. <?php //get post id from form //select all post ids for a specific address global $posts; //$wpdb->show_errors();//debug $attachments_id=array(); $property_title="23 Park Road";//property title will be passed from front end form where property is selected. global $wpdb; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post IDs while ( $row = mysql_fetch_assoc( $result ) ) { $attachments_id[]=$row['post_id'];//put all post ids for specific address into array } // print_r($attachments_id); //extract post ids and cycle through image code to display images for selected property foreach ($attachments_id as $iPostID) { //echo $iPostID; // Get images for this post $arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID ); // If images exist for this page if($arrImages) { // Get array keys representing attached image numbers $arrKeys = array_keys($arrImages); /******BEGIN BUBBLE SORT BY MENU ORDER************ // Put all image objects into new array with standard numeric keys (new array only needed while we sort the keys) foreach($arrImages as $oImage) { $arrNewImages[] = $oImage; } // Bubble sort image object array by menu_order TODO: Turn this into std "sort-by" function in functions.php for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) { for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) { if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) { $oTemp = $arrNewImages[$j]; $arrNewImages[$j] = $arrNewImages[$j + 1]; $arrNewImages[$j + 1] = $oTemp; } } } // Reset arrKeys array $arrKeys = array(); // Replace arrKeys with newly sorted object ids foreach($arrNewImages as $oNewImage) { $arrKeys[] = $oNewImage->ID; } ******END BUBBLE SORT BY MENU ORDER**************/ // Get the first image attachment //$iNum = $arrKeys[0]; foreach ($arrKeys as $iNum) { // Get the thumbnail url for the attachment $sThumbUrl = wp_get_attachment_thumb_url($iNum); // UNCOMMENT THIS IF YOU WANT THE FULL SIZE IMAGE INSTEAD OF THE THUMBNAIL //$sImageUrl = wp_get_attachment_url($iNum); // Build the <img> string $sImgString = '<a href="' . get_permalink() . '">' . '<img src="' . $sThumbUrl . '" width="150" height="150" alt="Thumbnail Image" title="Thumbnail Image" />' . '</a>'; // Print the image echo $sImgString; } } }//end of foreach ?>
  2. Sorry I did attach a file. Anyway below is the code . Thanks <?php /* * Template Name: gallery_test2 * */ ?> <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the page. * If you want to overload this in a child theme then include a file * called loop-page.php and that will be used instead. */ get_template_part( 'loop', 'page' ); ?> <?php //get post id from form //select all post ids for a specific address function bdw_get_images() { global $posts; $wpdb->show_errors(); $attachments_id=array(); $property_title="1 hawkesley Close"; global $wpdb; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post ID while ( $row = mysql_fetch_assoc( $result ) ) { $attachments_id[]=$row['post_id']; } print_r($attachments_id); foreach ($attachments_id[] as $iPostID => $attachment_id) { // Get images for this post $arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID ); // If images exist for this page if($arrImages) { // Get array keys representing attached image numbers $arrKeys = array_keys($arrImages); /******BEGIN BUBBLE SORT BY MENU ORDER************ // Put all image objects into new array with standard numeric keys (new array only needed while we sort the keys) foreach($arrImages as $oImage) { $arrNewImages[] = $oImage; } // Bubble sort image object array by menu_order TODO: Turn this into std "sort-by" function in functions.php for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) { for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) { if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) { $oTemp = $arrNewImages[$j]; $arrNewImages[$j] = $arrNewImages[$j + 1]; $arrNewImages[$j + 1] = $oTemp; } } } // Reset arrKeys array $arrKeys = array(); // Replace arrKeys with newly sorted object ids foreach($arrNewImages as $oNewImage) { $arrKeys[] = $oNewImage->ID; } ******END BUBBLE SORT BY MENU ORDER**************/ // Get the first image attachment //$iNum = $arrKeys[0]; foreach ($arrKeys as $iNum) { // Get the thumbnail url for the attachment $sThumbUrl = wp_get_attachment_thumb_url($iNum); // UNCOMMENT THIS IF YOU WANT THE FULL SIZE IMAGE INSTEAD OF THE THUMBNAIL //$sImageUrl = wp_get_attachment_url($iNum); // Build the <img> string $sImgString = '<a href="' . get_permalink() . '">' . '<img src="' . $sThumbUrl . '" width="150" height="150" alt="Thumbnail Image" title="Thumbnail Image" />' . '</a>'; // Print the image echo $sImgString; } } } } bdw_get_images() ?> </div><!-- #content --> </div><!-- #container --> <?php get_footer(); ?>
  3. I want to use the results of a db query to print images associated with several wordpress posts. To do this I need to pass the post id to the image processing code. I can get all the post ids ok but I am not getting the code in my foreach to work. Is their an error or a better approach please. I have attached my file.gallery_test2.html
  4. Thank. Said I was rusty.
  5. I have a table 'combo' with two fields, id and char. I want to populate a table, with the following query which fails. $sql = mysql_query("SELECT id,char FROM combo ORDER BY id DESC LIMIT 28"); I a bit rusty on sql but can't see what is wrong with this. Can anyone help please.
  6. The reason I entered them manually was that I was on a different machine at the time. I will repeat the exercise and post the logs. Thank you for your help.
  7. By offline I mean I am not leaving it on permenately. of course it is on for testing. The access log gives ,where xxx is the website name, GET xxx/http1.1 404 227 Get xxx/index.php/http1.1/ 404 236 Get xxx/index.php/http1.1/ 404 236 GET favicon .ico http1.1 200 584 GET /http/1.1 200 358 Happy to provide anything else Thanks
  8. Yes.Thanks for your reply The url is used is www.xxxx.com and the folder is xxxx as per the ghosts above. If i try www.xxx.com/index.php I get a 404. Note the server is offline at present until I resolve this.
  9. Thanks. I am not sure I understand what you are saying. The first vhost is supposed to be the default, correct.As indicated in the apache config file. The vhosts are configured from the uniserver menu on the control panel so I don't understand what is wrong. The paths are set by variables e.g.${US_ROOTF} etc however I don't know how to check these values. Could you expand on your reply please?
  10. As an experiment I changed the icon in the VHosts file and now that icon shows if I open the link in the index, which I guess means that the Directory being shown is the VHosts. The path is C:\Uniserver\vhosts\hawkesleypublishingsolutions This is the the http- vhost file # Virtual Hosts # # Required modules: mod_log_config # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.4/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # # First Virtual Host must be a shallow duplicate of the main host # in httpd.conf <VirtualHost _default_:${AP_PORT}> DocumentRoot ${US_ROOTF_WWW} ServerName ${US_SERVERNAME} ErrorLog "logs/error.log" CustomLog "logs/access.log" common </VirtualHost> <VirtualHost *:${AP_PORT}> ServerAdmin webmaster@hawkesleypublishingsolutions.com DocumentRoot ${US_ROOTF}/vhosts/hawkesleypublishingsolutions ServerName hawkesleypublishingsolutions.com ServerAlias www.hawkesleypublishingsolutions.com *.hawkesleypublishingsolutions.com ErrorLog logs/hawkesleypublishingsolutions.com-error.log CustomLog logs/hawkesleypublishingsolutions.com-access.log common <Directory "${HOME}\vhosts\hawkesleypublishingsolutions"> Options Indexes Includes AllowOverride All Require all granted </Directory> </VirtualHost> <VirtualHost *:${AP_PORT}> ServerAdmin webmaster@somewhere4u.com DocumentRoot ${US_ROOTF}/vhosts/somewhere4u ServerName somewhere4u.com ServerAlias www.somewhere4u.com *.somewhere4u.com ErrorLog logs/somewhere4u.com-error.log CustomLog logs/somewhere4u.com-access.log common <Directory "${HOME}\vhosts\somewhere4u"> Options Indexes Includes AllowOverride All Require all granted </Directory> </VirtualHost>
  11. Hi, Index of/ does not show a title . It only shows the favicon of the uniform server, so I presume it is showing me the www directory. The contents of www are Folder hawkesleypublishingsolutions Folder somewhere4u Folder nbproject .htaccess .htaccess_back index.php favicon I would have thought it would show index.php I should add that this is my own home server I am using. index.php is again a simple hello world file which shows when staring up the server. Thank you for coming back.
  12. I have set up two directories in www which reflect two domains I have using uniform server z which is a wamp package. I have set up Vhosts also. The sever is accessible from the internet The directories hold a simple hello world page ( one index HTML and one index.php) I set these up on uniform server z to test access as I have previously had problems getting virtual host to work on coral 6.8 I can test the IP address fine and ping the sever. I can access the two addresses from the net (not on my local network) How ever when I access either site externally I get the Index of/ My DirectoryIndex in the main apache config allows index.php & index.html. I also have that in the .htaccess and in the Vhosts ht access. The Index of however only shows a favicon and not the index.html/php Any help appreciated.
  13. I will check the points you raise and get back. The file is a php file I just copied the code into text wrangler in order to attach the file. Thanks
  14. I am experimenting with capturing the result of a form , storing the result in a database and visiting the page. I am using the header function but can't get a result. Is this the right way to do it and how can I get it to work please. File attached untitled text 2.html
  15. Thank you. Outputs Array ( [0] => 2014-01-21 [1] => 2014-01-7 [2] => 2014-01-16 [3] => 2014-01-16 )
  16. Dropping ARRAY_A gives fatal error
  17. Ok print_r $events is Array ( [0] => 2014-01-7 ) Array ( [0] => 2014-01-7 [1] => 2014-01-16 ) Array ( [0] => 2014-01-7 [1] => 2014-01-16 [2] => 2014-01-16 ) I have I got too many arrays? Drop ARRAY_A maybe?
  18. That outputs Array ( [0] => Array ( [title] => Viewing [event_date] => 2014-01-7 ) [1] => Array ( [title] => Viewing [event_date] => 2014-01-16 ) [2] => Array ( [title] => Viewing [event_date] => 2014-01-16 ) )
  19. Hi, thanks This gives me Array ( [0] => [1] => [2] => ) Should I see the values?
  20. I have a sql query that gets all the events from a specified month and should put the values into an array.print _r shows the values are being pulled from the database. I can't get this to work. Any suggestions appreciated. Code $events = array(); global$wpdb; echo $month; echo $year; $query=("SELECT title, DATE_FORMAT(event_date,'%Y-%m-%e')AS event_date FROM sw_appointments WHERE YEAR(event_date) = $year AND MONTH(event_date) = $month"); $result = $wpdb->get_results($query,ARRAY_A); print_r($result); foreach( $result as $results ) { $events=$results->event_date; echo $events; }
  21. Thanks for that. It works and it was LIKE 2014-1
  22. I am developing a calendar for use on a wordpress site. I have a series of events and need to retrieve all the events in a selected month and get them into the $events array I am getting no results from my query and no errors. My table has title, event_date,time.notes,post code. Only the first two fields are populated at the moment The event_date is stored as DATE. After retrieving the data $year,$month and $events is passed to a function to draw the calendar and show the months events. $events = array(); global $wpdb; $query=("SELECT title, DATE_FORMAT(event_date,'%Y-%m-%D')FROM sw_appointments WHERE event_date LIKE '$year-$month%'"); $result = $wpdb->get_results($query); print_r($result); while($row = mysql_fetch_assoc($result)) { $events[$row['event_date']][] = $row; /* verify that the query gets results. Also generates a list of this months events */ echo $row['title']." ----- ".$row['event_date']; echo "<br />"; } Any suggestions appreciated
  23. Thanks, that works. Whats the thinking here?
  24. I have a query that I want to get the value from and put into a variable. My query is $result =$wpdb->get_results("SELECT MAX(`mapid`) FROM `sw_mappress_maps` ORDER BY mapid DESC LIMIT 1"); if(!$result) echo"No result"; if($result) echo "Result"; var_dump($result); I get a result so i assume query is Ok, but I can't access the result var_dump gives array 0 => object(stdClass)[402] public 'MAX(`mapid`)' => string '28' (length=2) 28 is the value I want from field mapid but the foreach gives nothing. Any suggestions appreciated. foreach( $result as $results ) { echo $results->mapid; }
  25. Thanks. I will pursue that line
×
×
  • 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.