Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smile What is wrong with this code snippet

    Hello! I am trying to get some options to show up on the front page on my website but I think there is something wrong with the code. Can someone have a look please!

    This is what I think I want but DW says it's wrong:
    Code:
    <?php 	if ( $fields['price']) {  echo '<li><span class="bold-text">'.$field['pricetext'].': </span>').'</li>'; } else { echo ''; } ?>
    This is what it was before:
    Code:
    <?php 	if ( $fields['price']) {  echo '<li><span class="bold-text">'.$field['pricetext'].': </span>' .  $symbols['currency']; echo number_format($fields['price']).'</li>'; } else { echo ''; } ?>
    I still uploaded the first bit of code but it has made no difference to the website.

    I'ts a listing site where I need the price bracket for each listing to show up on each listing on the front page of the site. It's in wordpress. The way the system has built it is that it has a number format for the price but I have changed it to text and now I need it to show up.

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    147
    Thanks
    3
    Thanked 22 Times in 22 Posts
    PHP Code:
    echo '<li><span class="bold-text">'.$field['pricetext'].': </span>').'</li>'
    Abov has a Syntax error..

    PHP Code:
    echo '<li><span class="bold-text">'.$field['pricetext'].': </span>'.'</li>'
    Not sure why the bracket is there, have removed it, now syntax error free

  • #3
    Regular Coder
    Join Date
    Dec 2011
    Posts
    108
    Thanks
    5
    Thanked 17 Times in 17 Posts
    In this case I find using the ternary operator easier to use

    PHP Code:
    echo ( $fields['price'] ) ?  '<li><span class="bold-text">' $fields['pricetext']   . ': </span></li>' ''
    Last edited by Strider64; 04-22-2013 at 04:01 AM.

  • #4
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you so much for both of your answers... I now understand the syntax error. Although the "pricetext" is not showing up where I want it to.

    The way the theme was built was that there would show a number or a price of an item that had a number format.

    Hence:
    Code:
    echo number_format($fields['price']).'</li>'; } else { echo ''
    Could this be the problem? That I just removed that? I know html and css but very little about php, therefore it's like looking at Chinese for me. But I have understood that it has something to do with the options and fields (Yes this is written by a complete idiot ) Is there some other term one can use instead of "number_format" to make that specific span show text instead?

    This is the website I am working on (it's my own) http://dev.andalusitano.com

    In the front page you see posts with "for sale" buttons. Next to the button it should say the price indication for that post and not a "0".

    So if I have set the price of the particular horse to "Exclusive" it should say Exclusive...

    I am ripping my hair out with this, and no support from the creators of the theme!

    So hope someone can help me.

    Warm regards
    Sofie

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    147
    Thanks
    3
    Thanked 22 Times in 22 Posts
    Where are you setting the price as 'Exclusive'? I am assuming it is a field within your DB correct? We can point you in the direction of displaying the text, however first you need the variable that displays it.

    Based on your post you are indicating that your SQL query is querying the column 'pricetext'. Is this the case??

    The code you first supplied indicates that if the column 'price' is a valid variable (has a price) then it will show the column 'pricetext'. Although I note the first variable is $fields (ending in s) and the second just $field (no s) is this an error?

    PHP Code:
    if ( $fields['price']) { 
    echo 
    '<li><span class="bold-text">'.$field['pricetext'].': </span>'.'</li>'
    } else {
     echo 
    ''


  • Users who have thanked itxtme for this post:

    The Alchemist (04-22-2013)

  • #6
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by itxtme View Post
    Where are you setting the price as 'Exclusive'? I am assuming it is a field within your DB correct? We can point you in the direction of displaying the text, however first you need the variable that displays it.

    Based on your post you are indicating that your SQL query is querying the column 'pricetext'. Is this the case??

    The code you first supplied indicates that if the column 'price' is a valid variable (has a price) then it will show the column 'pricetext'. Although I note the first variable is $fields (ending in s) and the second just $field (no s) is this an error?

    PHP Code:
    if ( $fields['price']) { 
    echo 
    '<li><span class="bold-text">'.$field['pricetext'].': </span>'.'</li>'
    } else {
     echo 
    ''

    Yes it may well be an error. Thank you so much for helping!
    I have the following codes that I think has something to do with this:

    In the admin when someone adds a horse to the listings I have made the following code:
    Code:
     "price" => array(
    	  "name" => "price", 
      	  "title" => $options['pricetext'], 
    	  "description" => "Enter the price indication of the horse (Low, Medium, Exclusive).",
    	  "type" => "text",
    	  "class" => "text",
    	  "rows" => "",
          "width" => "",
    	  "hide_in_search" => $options['pricehide'],
    	  "options" => ""
    This I believe also has something to do with it...
    Code:
    if(!empty($fields['price']))
    				{  
    					echo '<div style="font-weight:bold;font-size:22px;color:#779f78!important;margin-top:20px!important;">'.$symbols['currency'].number_format($fields['price']). '</div><br/>';
    And this is something too, the last bit that says Price Group:
    Code:
    function reg_fields() 
    	{
    		add_settings_section('main_section', '', 'gorilla_t', 'currency_metrics');
    		add_settings_section('main_section', '', 'gorilla_t', 'fields');		
    		register_setting('gorilla_fields', 'gorilla_fields', 'validate_fields');
    		register_setting('gorilla_symbols', 'gorilla_symbols', 'validate_symbols');		
    		add_settings_field('currency', '<span class="optionmain"><strong>'.(__('Price Group:','language')).'</strong></span>', 'currency_setting','currency_metrics', 'main_section');
    Then I have this:
    Code:
    <?php	$options = get_option('gorilla_fields');
    	if (isset($options['pricetext']) && !empty($options['pricetext']))
    		{
    		  $options['pricetext'];
    		}
    		else
    		{
    		$options['pricetext'] = 'Price';
    And then of course the first snippet that I sent... I feel like a complete twat! Just so you know!
    Kind regards
    Sofie

  • #7
    Regular Coder
    Join Date
    Jun 2009
    Posts
    147
    Thanks
    3
    Thanked 22 Times in 22 Posts
    Still not sure where you save the text for "exclusive". Once you know what the array value is that is holding that text it is as simple as echoing out the variable in that first line you gave.

    So when someone creates a listing where does the Exclusive get entered. Is it in the current price field or somewhere else??

  • Users who have thanked itxtme for this post:

    The Alchemist (04-22-2013)

  • #8
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    The text for exclusive is not only exclusive...
    I have set up four fields that are:
    LOW
    MEDIUM
    EXCLUSIVE
    P.O.A
    When someone adds a listing in the admin of the wordpress they get the choice of a drop down where I have these options and they chose one of them.

    Might this be what controls the drop down?:
    PHP Code:
    <?php
    }

        function 
    currency_setting() 
        {
            
    $options get_option('gorilla_symbols'); 
            if(empty(
    $options['currency']))
            {
                
    $options['currency'] = 'Price Level';
            } 
            else 
            { 
                
    $options['currency'];
            }
            
            
    $items = array("Price Level");
            
               echo 
    "<select name='gorilla_symbols[currency]'>";
               foreach (
    $items as $item
            {
                
    $selected = ( $options['currency'] === $item ) ? 'selected = "selected"' '';
                echo 
    "<option value='$item' $selected>$item</option>";
               }
               echo 
    "</select>";
    This theme was from the beginning a property theme that I have edited to make it a horse selling theme. So there weren't any fields with options for price from the beginning just a field for putting in a numeric value or price of the listing.

    The value might not be pricetext, but "currency"? I am not sure...

  • #9
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ok, The code that controls the drop down in the admin for the selection of the price levels, low, medium, exclusive etc. Must be this:
    PHP Code:
    add_settings_field('pricetext''<span class="optionmain"><strong>'.(__('Price:','language')).'</strong></span>''price_text''fields''main_section'); 
    Then in the same document I have:
    PHP Code:

        function 
    price_text() {
           
    $field get_option('gorilla_fields');
           if(empty(
    $field['pricetext']))
            {
                
    $field['pricetext'] = 'Price';
            }
            else
            {
                
            }
           echo 
    "<input name='gorilla_fields[pricetext]' type='text' value='{$field['pricetext']}' />";
             
    $items = array("Yes","No"); 
           echo 
    "<span class='optionsearch'>".(__('Hide in Search Module:','language'))."</span><select name='gorilla_fields[pricehide]'>";
           foreach (
    $items as $item) {
            
    $selected = ( $field['pricehide'] === $item ) ? 'selected = "selected"' '';
            echo 
    "<option value='$item' $selected>$item</option>";
           }
           echo 
    "</select>"
    This is the box code for the front page. It has to be!
    PHP Code:
    <?php    $options get_option('gorilla_fields');
        if (isset(
    $options['pricetext']) && !empty($options['pricetext']))
            {
              
    $options['pricetext'];
            }
            else
            {
            
    $options['pricetext'] = 'Price';
            }
                if (isset(
    $options['tagtitletext']) && !empty($options['tagtitletext']))
            {
              
    $options['tagtitletext'];
            }
            else
    I have fields and options.. And i don't really know the difference... Some areas says options and some fields...

  • #10
    Regular Coder
    Join Date
    Jun 2009
    Posts
    147
    Thanks
    3
    Thanked 22 Times in 22 Posts
    Looks like you have got it sorted


  • Users who have thanked itxtme for this post:

    The Alchemist (04-23-2013)

  • #11
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    101
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I tried to implement the code, but still no support for the theme.

  • Users who have thanked annaharris for this post:

    The Alchemist (04-23-2013)

  • #12
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Yay!

    Well it looks like it sorted itself but I don't know if I have done it? I have no idea! It works on the front page but in the bottom of each listing there are some related posts that should work the same and they still have the 0 on them.. Also if you search for a horse you also get the 0 in the search...

  • #13
    New Coder
    Join Date
    Sep 2004
    Location
    Sweden
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I know now what it was.. It had a setting where the price field only accepted number format and I have taken that away in the widgets using only this code:
    PHP Code:
    <span class="price"><?php echo $options['price'];?></span>

    Now I found this piece of code that I think controls the rest of the site... How can I change it to only show the option price and not the number format?
    PHP Code:
    if(!empty($fields['price']))
                    {  
                        echo 
    '<div style="font-weight:bold;font-size:22px;color:#779f78!important;margin-top:20px!important;">'.$symbols['currency'].number_format($fields['price']). '</div><br/>';   
                    } 
                    else 
                    {
                        echo
    ''
                    } 
    I need to keep this bit but remove everything else that has to do with the number format...
    PHP Code:
    <div style="font-weight:bold;font-size:22px;color:#779f78!important;margin-top:20px!important;"
    To get the price value to show up in the search I think I have to do something with this code...
    PHP Code:
    <span class="<?php echo $fields['statustag'];?>"><?php echo $fields['statustag'];?></span><span class="results-price"><?php       include(TEMPLATEPATH."/functions/var/default-box-one.php");
          include(
    TEMPLATEPATH."/functions/var/default-box-two.php");
          include(
    TEMPLATEPATH."/functions/var/default-box-three.php"); 
          if ( 
    $fields['price'])
              { 
              echo 
    $symbols['currency']; echo number_format($fields['price']); } else { echo ''; } ?>
    It's that darn number_format again... I don't know how to write the code. I keep getting errors. If you have any idea! Please help me!
    Last edited by The Alchemist; 04-23-2013 at 10:20 PM. Reason: Found more info...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •