raybeam
Forum Replies Created
-
Forum: Hacks
In reply to: Dynamically Create new table items in a CUSTOM fieldHey I think I might have solution in the form of Types plugin. It wasn’t the way I wanted to go, but as I have a tight deadline and I don’t see myself coming up with some amazing code in 3 days, I think it’s the best i can find. This is the code I am using with this plugin to generate one line of the table
<?php echo '<table class="table-striped table-bordered table-responsive table">'; echo '<tr> <th>Unit Name</th> <th>Number of Beds</th> <th>Size M2</th> <th>Price from THB</th> <th>Price up to THB</th> </tr>'; echo '<tr>'; $unit_types=get_post_meta($post->ID,'wpcf-unit-type'); foreach ($unit_types as $unit_type) { echo '<td>'.$unit_type.'</td>'; } $num_beds=get_post_meta($post->ID,'wpcf-number-of-beds'); foreach ($num_beds as $num_bed) { echo '<td>'.$num_bed.'</td>'; } $size_sq_mtrs=get_post_meta($post->ID,'wpcf-size-square-meters'); foreach ($size_sq_mtrs as $size_sq_mtr) { echo '<td>'.$size_sq_mtr.'</td></tr>'; } $prices_from=get_post_meta($post->ID,'wpcf-price-from'); foreach ($prices_from as $price_from) { echo '<td>'.$price_from.'</td>'; } $prices_to=get_post_meta($post->ID,'wpcf-price-to'); foreach ($prices_to as $price_to) { echo '<td>'.$price_to.'</td>'; } echo '</tr>'; echo '</table>'; ?>
Only problem occurs when I try to add a new row. I can see why that’s happening, its because my block of code is wrapper in <tr></tr> tags and just forces all the content into an ever growing row. How can I write is so that one block of code will be put into a new row every time I add a new items?
Could I, for example, but that block of items in <td>s and make it a block of code that is always wrapped in <tr>s? Would i use a function, or an array, or just create a variable..?
P.S Working on this project has really improved my understanding of programming, variables and arrays and all that suddenly make sense to me.. I just can’t seem to use them when it comes to writing my own stuff!
Forum: Hacks
In reply to: Dynamically Create new table items in a CUSTOM fieldI appreciate all the help you’ve given me on this. I’m not sure if I can make sense of the code example you given me, or how I could modify it to my needs.
I’m light years behind the level I need to be at and I have to finish this by the end of the week. I’m thinking I’ll just have to come up with some artificial solution such as hard coding 10 rows then only displaying them if they’re !=’ ‘;
Thanks man!
Forum: Hacks
In reply to: Dynamically Create new table items in a CUSTOM fieldThanks.
A lot of this makes sense to me, but my experience as a programmer is pretty limited. I’m not exactly sure how I would write a lot of what you’re saying here, or how I would include jQuery in a php document.
My usual method of writing code like this is to find an example online that is close to what I want and then modify it to my needs.
Could you give me some examples of code?
I think the main one would be how to write that function to add new table rows dynamically.
I was thinking, as each table cell currently has a unique var name, it would get pretty crazy if I had to create say 10 rows and then hard code the var names for each cell.
Could you show what the array would look like? Or would be some thing like:
`$var = array ($unit_type, $size_msq, $price_from $etc) {
//code here
}then to access these variables in the array I would use [0][1] etc so, something like $var[2], would get the $price_from ?
I will have a go writing some code and see what I can do.
Thanks
Forum: Hacks
In reply to: Dynamically Create new table items in a CUSTOM fieldThank you, this is the code I wrote to output one row in a table
/********************************************************************/ /* UNITS CUSTOM FIELDS */ /*********************************************************************/ add_action( 'admin_init', 'unit_type_admin' ); function unit_type_admin() { add_meta_box( 'unit_type_meta_box', 'Unit Type', 'display_unit_type_meta_box', 'post', 'normal', 'high' ); } function display_unit_type_meta_box( $unit_type ) { $unit_name = esc_html( get_post_meta( $unit_type->ID, 'unit_name', true) ); $num_beds = esc_html( get_post_meta( $unit_type->ID, 'num_beds', true) ); $size = esc_html( get_post_meta( $unit_type->ID, 'size', true) ); $price_from = esc_html( get_post_meta( $unit_type->ID, 'price_from', true) ); $price_to = esc_html( get_post_meta( $unit_type->ID, 'price_to', true) ); ?> <label for="unit_name_text">Unit Name: </label> <input type="text" id="unit_name_text" name="unit_name_text" value="<?php echo $unit_name; ?>" /><br /> <label for="num_beds_text">Number of Beds: </label> <input type="text" id="num_beds_text" name="num_beds_text" value="<?php echo $num_beds; ?>" /><br /> <label for="size_text">Size M2: </label> <input type="text" id="size_text" name="size_text" value="<?php echo $size; ?>" /><br /> <label for="price_from_text">Price From (THB): </label> <input type="text" id="price_from_text" name="price_from_text" value="<?php echo $price_from; ?>" /><br /> <label for="price_to_text">Price To (THB): </label> <input type="text" id="price_to_text" name="price_to_text" value="<?php echo $price_to; ?>" /><br /> <?php } add_action( 'save_post', 'unit_type_fields', 10, 2 ); function unit_type_fields( $unit_type_id, $unit_type) { if ( $unit_type->post_type == 'post') { if ( isset( $_POST['unit_name_text'] ) && $_POST['unit_name_text'] != '' ) { update_post_meta( $unit_type_id, 'unit_name', $_POST['unit_name_text'] ); } if ( isset( $_POST['num_beds_text'] ) && $_POST['num_beds_text'] != '' ) { update_post_meta( $unit_type_id, 'num_beds', $_POST['num_beds_text'] ); } if ( isset( $_POST['size_text'] ) && $_POST['size_text'] != '' ) { update_post_meta( $unit_type_id, 'size', $_POST['size_text'] ); } if ( isset( $_POST['price_from_text'] ) && $_POST['price_from_text'] != '' ) { update_post_meta( $unit_type_id, 'price_from', $_POST['price_from_text'] ); } if ( isset( $_POST['price_to_text'] ) && $_POST['price_to_text'] != '' ) { update_post_meta( $unit_type_id, 'price_to', $_POST['price_to_text'] ); } } } function display_unit_type() { global $post; $unit_name = get_post_meta( $post->ID, 'unit_name', true ); $num_beds = get_post_meta( $post->ID, 'num_beds', true ); $size = get_post_meta( $post->ID, 'size', true ); $price_from = get_post_meta( $post->ID, 'price_from', true ); $price_to = get_post_meta( $post->ID, 'price_to', true ); $allowed_html = array( 'a' => array( 'href' => array(), 'title' => array() ), 'em' => array(), 'strong' => array() ); $_unit_name_output = wp_kses( $unit_name, $allowed_html ); $_num_beds_output = wp_kses( $num_beds, $allowed_html ); $_size_output = wp_kses( $size, $allowed_html ); $_price_from_output = wp_kses( $price_from, $allowed_html ); $_price_to_output = wp_kses( $price_to, $allowed_html ); $output = '<div class="col-md-12"> <div class="table-responsive"> <table class="table table-bordered table-striped"> <tr> <th>Unit Name</th> <th>Number of Beds</th> <th>Size M2</th> <th>Price from THB</th> <th>Price up to THB</th> </tr> <tr> <td>'.$_unit_name_output.'</td> <td>'.$_num_beds_output.'</td> <td>'.$_size_output.'</td> <td>'.$_price_from_output.'</td> <td>'.$_price_to_output.'</td> </tr> </table> </div> </div>'; return $output; } add_shortcode( 'project-info-box', 'display_unit_type' );
How could I create a function that says either:
1) Only display a row if it is filled in.
0r
2) Allows user to add new inout fields dynamically in backend?
Thanks again
Forum: Hacks
In reply to: Custom Fields Plugins – How to properly outputBrother! I could kiss you! well, maybe not.. but you just helped me fix a problem that I have spent 2 days on!!!!
THANK YOU SO MUCH
It worked!!! now all I have to do is add more facility options…
Forum: Fixing WordPress
In reply to: Show Author Related Posts if they have postThanks man,
I’m not exactly a programmer, so I don’t full understand where I would put that in relation to my code. I usually just utilise php functions from other people to do the tasks I want.
So would it look like this?:
[ Moderator note: please wrap code in backticks or use the code button. ]
/********************************************************************/ /* Function for displaying related post thumbnails */ /*********************************************************************/ function get_related_author_posts() { global $authordata, $post, $wpdb; $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 7 ) ); $author_post_number = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->posts." WHERE post_author = ". intval($authordata->ID) ); if( $author_post_number == 1){ $output = '<div class="tiles-block"><h4 class="other-props" >Other properties by this developer</h4>'; foreach ( $authors_posts as $authors_post ) { $output .= '<a>ID ) . '">' . get_the_post_thumbnail($authors_post->ID) . '</a>'; } $output .= '</div>'; return $output; } }
Forum: Fixing WordPress
In reply to: Show Author Related Posts if they have postMy friend, I think I didn’t explain this clearly or something. It’s not the css. I don’t want the block that the posts are wrapped in to show if the author has no posts.
I believe this is about if statements. example : if author_has_posts : display the posts…
problem is, I don’t if WordPress has a “author_has_posts” statement..
Thanks for the reply!
Forum: Fixing WordPress
In reply to: Edit indivdual pagesthanks for pointing out my mistake. However, that doesn’t answer my question
Forum: Fixing WordPress
In reply to: Edit indivdual pagesI forgot to add my blog address:
https://www.madeinthai.orgthanks again.
Forum: Fixing WordPress
In reply to: SEOThanks for your reply rob! I will try removing the adds and see if the stats improve.
Cheers!
Forum: Fixing WordPress
In reply to: SEOHi.
maybe I didn’t make it clear. Yes, the search engine terms were showing up in my wordpress dashboard. My stats were say 70 views per day but now seem only about 7 +. Perhaps I’m just being to eager to get going….All good things take time, after all.Thanks
Forum: Fixing WordPress
In reply to: Home Page SummaryThanks Samuel B. I don’t see that theme in my dashboard. DO I have to access it through my FTP client?
Thanks again!