Viewing 22 reply threads
  • Author
    Posts
    • #4045
      giec
      Member

      Hi, i’ve followed the instructions and created the folder structure as follow:
      twentytwelve-child –> piklist–>parts–>meta-boxes and this is my my-fields.php file (which is just a test to see if I can get the metabox):

      <?php
      /*
      Title: My custom fields
      Post Type: page
      */
      piklist('field', array(
        'type' => 'text'
        ,'field' => 'field_one'
        ,'label' => 'First Field'
      ));
      ?>

      What I want to do is to give users, when they create a page in wordpress, the possibility of adding one or more repeatable divs, but I don’t seem to be able to see this metabox
      Any idea?

    • #4046
      giec
      Member

      OK I think I managed to get it to display, but how do I change the sample code to get a div with a class? I had a look at the field parameters page https://piklist.com/user-guide/docs/field-parameters/ but there is nothing about divs. Any idea?

    • #4048
      Steve
      Keymaster

      @giec– Welcome to the Piklist Community!

      Piklist fields have very minimal markup. If you want to add a div, you can just wrap your field in a div in your my-fields.php file:

      < div class="my-class"> 
      
      	 'text'
      		  ,'field' => 'field_one'
      		  ,'label' => 'First Field'
      		));
      	?>
      
      < /div>
      
      
    • #4053
      Steve
      Keymaster

      I just read your post on Stack Exchange, and I think I have a better understanding of what you want.

      It would be best to use the WordPress function get_template_part() to bring in your divs. This is how I would do it.

      YOUR PIKLIST PARTS FILE (my-fields.php)
      This is where your users select the Divs they want and can reorder them.

        piklist('field', array(
          'type' => 'select'
          ,'field' => 'my_divs'
          ,'label' => __('Select a Div')
          ,'add_more' => true
          ,'choices' => array(
            'div_one' => 'Div One'
            ,'div_two' => 'Div Two'
            ,'div_three' => 'Div Three'
          )
        ));
      

      YOUR THEME FILE (PAGE TEMPLATE)
      Your page template should look something like this:

      
      
      ID, 'my_divs'); // Get the field data
      
        foreach ($my_divs as $my_div => $name) // loop through each add_more
        { 
          get_template_part('custom-div', $name); // display the template
        }
      
      ?>
      
      
      
      

      Then you would name your divs (template parts) this, to match the dropdown values:

      custom-div-div_one.php
      custom-div-div_two.php
      custom-div-div_three.php
      

      Does that make sense?

    • #4054
      giec
      Member

      Hi steve, thanks for taking the time to write the code. I think it makes sense to an extent (the problem is also my limited understanding of PHP at this stage as I literally just started with it) in any case, I will apply the code you gave me and see how I get on with it, i’ll post back if I get seriously stuck!
      thanks again

    • #4056
      Steve
      Keymaster

      Feel free to zip up your child theme and email to [email protected] if you want us to take a look. Always happy to help.

    • #4061
      giec
      Member

      Very nice of you, I’ll see how I get on. One more question of a more general nature about the plugin if I may. As you gathered from my previous question, allowing user to add functional markup without knowing any HTML from the backend, is one of the main reasons why I downloaded the plugin. I’ll also need users to be able to change things like CSS styles (using always the same method of selecting/deselecting boxes/radio buttons at the backend)and perhaphs, if possible, make some changes to jquery functionalities, like er, change the speed of animations etc. Does this plugin allow this?
      thanks

    • #4062
      giec
      Member

      OK, so I’ve done some work implementing your code. One thing I’m not too sure about – and sorry for being a complete noob – but you know the 3 divs you said they should match the dropdown values:

      custom-div-div_one.php
      custom-div-div_two.php
      custom-div-div_three.php

      Those presumably are partial templates, aren’t they? Should they go together with my custom template in the page-template folder? More importantly, what code goes in them? Presumably <div class="infoBox"></div> but if so, I don’t need three separate partial templates because the divs inside will always be the same, I just want the users to have the possibility to choose how many they want to add if that makes sense
      thanks

    • #4063
      Steve
      Keymaster

      I thought you wanted different partials, but if you only have one, that’s fine too. If you ever want to add different partials this code is easy to expand.

      Your partials can go in the root directory of your theme or in a folder if you like. You would just need to tell get_template_part to look in a folder.

      ROOT: get_template_part('custom-div', $name);
      DIRECTORY NAMED PARTIALS: get_template_part('partials/custom-div', $name);

      Here’s a good tutorial on get_template_part().

      Does that make sense.

    • #4064
      giec
      Member

      Thanks Steve, I think it makes sense yes, and thanks for the tutorial, I will read it with interest and i’ll keep implementing your solution. Thanks!

    • #4071
      giec
      Member

      Hi Steve, I’ve just implemented your solution, and I do get the select box with the add/remove buttons as per screenshot http://s1.postimg.org/qxcifziz3/wordpress_backend.png but I don’t seem to be able to add any div to the editor. Here is the code:
      my-fields.php

      <?php
      /*
      Title: My Metabox
      Description: My cool new metabox
      Post Type: page
      
      */
       
      // Let's create a text box field
      piklist('field', array(
      	'type' => 'select'
      	,'field' => 'my_divs'
      	,'label' => __('Select a Div')
      	,'add_more' => true
      	,'choices' => array(
      		'div_one' => 'Div One'		
      	)
      )

      custom-div-div_one.php

      <?php
      	<div class="infoBox one"></div>
      
      ?>

      test-templ.php

      <?php /* Template Name: New Test page*/ ?>
      <?php get_header(); ?>
      <?php 
      	$my_divs = get_post_meta($post->ID, 'my_divs'); // Get the field data
      
      	foreach ($my_divs as $my_div => $name) // loop through each add_more
      	{ 
      		get_template_part('custom-div', $name); // display the template
      	}
      ?>
      <?php get_footer(); ?>

      Am I missing something, shouldn’t the plugin take care of that of do I have to write the code?
      thanks
      A

    • #4072
      Steve
      Keymaster

      Your code for custom-div-div_one.php is incorrect. You can’t wrap a div within php tags. just change it to this:

      <div class="infoBox one"></div>

    • #4078
      giec
      Member

      Ah, apologies for that. I’ve made the changes, but still nothing, in the sense that I can add and remove divs at the back end, but I can’t get the divs to appear dynamically (when I add one for example) in the text editor. Happy to zip up everything if it is easier, whatever you think it’s best.
      cheers

    • #4079
      Steve
      Keymaster

      Do you want these divs to appear on the front end or in the admin area?

    • #4082
      giec
      Member

      well, both, sorry maybe I didn’t explain things correctly.
      Basically I wanted to add, at the backend, the functionality to allow me to add HTML tags to the front end by using select boxes etc. So, say, I want to have two divs to be added to his page: I’ll use a select box (which I have added to the backend using this plugin) to allow me to add one or more divs to the text editor at the backend, and when I click “update” these divs will be added onto the page (front end).

      If you look at my screenshot here http://s1.postimg.org/qxcifziz3/wordpress_backend.png you’ll see the select boxes just below the text editor: when I’m happy with the number of divs I want to add to my page, there will be a mechanism – an “Add” button perhaps – that if pressed will add the number of specified divs to the text editor and consequently to the actual page.

      In essence I want to use this plugin to customize the back end so that an hypothetical user, who knows no HTML, will be able to rely on my customization (select boxes and whatever else) to add code to his page, allowing wordpress to act as a proper CMS.
      I hope it is clearer now, and sorry if it wasn’t before.

    • #4083
      Steve
      Keymaster

      This code will add a repeatable textarea where the user can add code. Then pull this field, and loop through it to display:

      piklist('field', array(
        'type' => 'textarea'
        ,'field' => 'my_divs'
        ,'label' => __('Add your code')
        ,'add_more' => true
      )
      

      There is no need for an “Add” button.

    • #4084
      giec
      Member

      Thanks Steve, I tried that,but it breaks my text editor, in that the tool bar that is supposed to appear on the top of the text editor has disappeared and the text I type in it is invisible, here is a screenshot http://postimg.org/image/m7mx5hnvv/

      I hope what I said made some sense Steve, that’s how I envisaged to use the plugin, but obviously I don’t know whether it will allow me to customize the backend in the way described. I mean adding select boxes, radio buttons etc is exactly what I need, but I have to have the possibility to make them do something – mainly allow users to add content to the front end pages, a bit like drupal I presume

    • #4085
      Steve
      Keymaster

      The image link is broken. Please repost.

    • #4091
      giec
      Member

      I think the site was down yesterday, I checked the image again and it works OK now, thanks

    • #4092
      Steve
      Keymaster

      @giec– Sorry, but I’m still a bit confused. What is creating the meta-box, “My Metabox”? Is this created by the select field?

    • #4093
      giec
      Member

      I would have thought the metabox was there because I’ve added a metabox folder inside the pklist folder in my theme, as per the tutorial. Aside from that, does it make sense what I’m trying to achieve with this plugin?

    • #4094
      Steve
      Keymaster

      I’m still not clear. Happy to chat on Skype if you like. Email me at [email protected] to schedule a time.

    • #4097
      giec
      Member

      Ah, OK cool, I will do in a few days as I’m away now
      thanks

Viewing 22 reply threads
  • You must be logged in to reply to this topic.