SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Wordpress PHP snipet to shortcode.

    The following php code when added to the html of a post prints the folowing:

    Price/per: [custom field :'item price'] €

    or if the site is in greek (qtranslate):

    Τιμή/τεμ: [custom field :'item price] €


    PHP Code:
    <?php $price get_post_meta(get_the_ID(),'item_price',true);?>
    <span align="center">'<?php _e("<!--:en-->Price/per: <!--:--><!--:EL-->Τιμή/τεμ: <!--:-->"); ?><?php echo $price;?><?php echo "\xE2\x82\xAc";?>'</span>

    What i'd like to do is create a shortcode so i don't have to go to html and copy paste this snippet in every post. Instead i'd like to type [price] and simply set a value to my custom field.
    The custom field is also displayed in the categories and soon in the store page. So i'd like to automate this as much as possible. I've tried to make the shortcode in several ways and i've tried several insert php to post plugins... All my function.php attempts result in a white screen and the site going unresponsive, the only way to recover is to ftp a copy of function.php to replace my changes.. No empty space is left at the end btw.

    The site is mainly empty due to small issues but the link is <snip>

    Another issue i have, is there any way to automatically fill in the style variable when adding an image to post? Everytime i have to click, image properties, advanced and type into styles : border-radius:10px;
    Last edited by TechnoBear; Jan 7, 2013 at 05:48. Reason: Link removed at member's request

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2011
    Location
    Kolding, Denmark
    Posts
    108
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Wordpress manual has good explanation on how to make shortcodes http://codex.wordpress.org/Shortcode_API, there's not that much work to get it done.
    As for image styles, you can add style to your style.css and target all post images:
    Code:
    .post img {
        border-radius:10px;
    }

  3. #3
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much for the style code, it works great even if it doesn't show the image oval in post the result is perfect

    Cheers.


Tags for this Thread

Bookmarks

Posting Permissions

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