I am somewhat new to both Wordpress and PHP, and I wanted to get advice on the best way to tackle my problem as I have had little luck doing it successfully so far.
There are two jobs I want to handle:
First of all, I want to have a conditional include on my home page that does the following;
Find a custom post type home_content (only ever going to be 1 post, which is ID 76 - if that helps)
Display 3 custom fields from that post... the values for today_on front_widget_a & front_widget_b
(I guess a secondary question would be - can I even pass shortcode through a custom field, because that's what those widgets are being generated from, is shortcode from a plug-in)
That's pretty much it. I've tried various combination of get_posts and get_post_meta without much success. Either I get some syntax errors I can't figure out (and trust me I've combed my code many times for missing semi-colons and the like). That or I get a result that makes no sense.
The second one is a bit more difficult.
Basically trying to turn a part of my Wordpress into a bit of a CMS-style feature. Basically, I have 2 additional custom post types, one called tag_page_layout and one called tag_page_data.
When a Tag in a post is clicked on, I want the Tag page to grab custom field 1 from the tag_page_layout, and then a couple custom fields worth of data from tag_page_data.
I probably wouldn't even need the two post types if I took the time to learn the PHP or HTML code for making tabs, but again, I'm using a plug-in for Wordpress shortcode (which, if you see above - I'm not even sure is going to work right - of course if its not I'm willing to make multiple of these 'layout' posts so each [tab:NAME] shortcode bit is in it's own post-content area.
So... the tag page will basically have a big bit of code that runs before the loop.... it knows its on a tag page so it starts loading Custom Field 1 from the tag_page_layout, which is essentially a bit of code that starts up a Tab-separated data presentation area. Then it's got to take the tag clicked and match it with the same tag ID from custom post type #2 - the tag_page_data group. Then it will grab the first 3 or so fields from that page, swap back to the layout post, throw another custom field from there to start another tab, and so on and so forth, until a [tab:END] and it runs the loop.
I could include all my various attempts and bits of code that never worked or half worked, but I've been around so many circles trying to construct this. Like I said, my coding knowledge is limited but I can usually feel my way around, however these finer points of trying to make Wordpress a little more CMS-like seem to be harder for me to grasp. Any help would be appreciated!
As far as using shortcodes in custom fields go, this should help you out, where XXX is your custom field name.
<?php
$var = apply_filters('the_content', get_post_meta($post->ID, 'XXX', $single = true) );
echo $var;
?>
This apply's the standard filters wordpress automatically runs on regular post content, allowing it to process your custom field and convert the shortcode.
Related
I'm using WP_Table_Lists in my custom plugin.
The tables are running fine, as are the bulk actions, the sortable columns and so on.
Looked up all around the internet but everywhere I find there's only pages showing how to create a custom field in posts screen, which is NOT what I need.
The function quick_edit_custom_box was a beacon of hope, but couldn't find anything to work on it.
I'm gonna use the quick edit box to make a field for tags (with autocomplete) to quickly edit one by one instead of having to wait to load and then come back.
I want to use some template for all the quick edit fieldsets instead of hard coding it all the way with AJAX / Javascript.
Is that possible?
I am working on multiple one field forms to display in the footer of a clients website. Each time the page refreshes (like an adroator) a different question should be displayed. My clients CMS is wordpress so I'm using Ninjaform to create forms.
I have created multiple ninjaforms and tried to implement their shortcode and/or their php and neither will display properly, it just displays the code.
Seems like it is some conflict but not quite sure. Would like to find a simpler solution if there is one.
Thanks in advance.
In order to get the result of a shortcode, you need to "execute" it, which the ad rotator is probably not doing.
If you can insert text into the adrotator using PHP, you can execute the shortcode and get the results with:
$result = do_shortcode('[shortcode...]');
You can then insert the result.
I see all sorts of people asking this but no solid answers. I want to take text from a textarea form where users can enter their bio and then insert it into the bio field in mysql. This might be fairly easy normally, but alas, it seems nearly impossible with WordPress. I have to use the "Php for posts and pages" plugin and for some reason, the php script I have cannot be found (404 error) no matter where I place it. Then I thought I would try to just make the form and php all on one WordPress page, but it apparently can't be done like on a normal php web page. Anyone have any experience doing this? Any approaches that are known to work?
You can make form using normal php and insert it into mysql.
You can do this by making page template in wordpress.
http://codex.wordpress.org/Page_Templates
I've went through the same process! :)
My solution was:
Installing a PHP insertor plugin (specifically this). It's lot easier than creating a template.
I used it like this (inserted into the post's source):
[insert_php] include('myphpfile.php'); [/insert_php]
Then the included PHP's contents will be processed and printed out inside the page's body (the article's main part), so you don't have to create the html, head and body tags.
Then came the problem with posting form data to a page like this. This was because some of my form's fields kinda conflicted with WP's variables.
Some of the conflicting field names I've noticed: info, name
Just have a look at your form' field names and replace them to something else, and everything will be fine! :)
PS.: It's possible to put the form and the form data "receiver" in the same PHP script. I've done so and it worked in this scenario.
PS. 2: Optionally, you can disable the annoying auto-paragraph-insertor wpautop stock WP plugin, as it's affecting the included PHP's output. There is a per-post wpautop disabler plugin: Toggle wpautop
I am not sure the correct terminology for the process that I am trying to describe. I don't even know which platform is underlying the technique. If you understand my description, please give the link to the site(s) and or the keyword name of the process. I think it is done by AJAX, but I am not certain. I use php as the backend code, I just need to find a way to dynamically display the results. Please give suggestions. I forgot the name of the sites that use this, and my link history expired.
TIA
Description:
The page would have a search form and options. After the user submits, the search is initiated, and the results appear inside the dedicated result area. The page does not refresh, just the info inside the result area.
The display area will show 20 (or whatever) results (lines). There will be next, and previous buttons. If you hit next, the next set of results will display.
I am writing a code that generates 20 results for each display. There is no set number of results, so the results might have a start/first page, but do not have an end page.
Each time the user hits 'next', the program would generate/load new results. It would also store previous results, so that when a user hits 'prev', the previous results can instantly come up.
What techniques/program are theses?
Having recently handled pagination with Code Igniter (php framework), the following links might help you and anyone else out:
http://tympanus.net/jPaginate/
http://codeigniter.com/forums/viewthread/93045/
Usability is important and AJAX pagination introduces some important questions that need addressing regarding pagination, the following article will give some usability guidelines for displaying results in a table:
http://thedesignvanguard.com/crud-r-for-read
Code Igniter Prototype Framework Ajax Pagination:
http://codeigniter.com/wiki/AJAX_Pagination_with_CI_Pagination_Library/
Since we're using jQuery, we chose the following, Codeigniter jQuery framework for AJAX pagination
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/
http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/
It is not AJAX for sure.
Nobody uses AJAX for the pagination.
And there are about zillion pagination examples over internet
The only thing is never described in articles is how to persist search options for the other pages.
But it's simple enough: http_build_query() can help you
You need to have a GET/POST form submitted via AJAX which contains the fields in the search term and page number.
If you are going to set the page size to 20 results, page_num=4 will show results from 61-80 results.
Usually search results are GET instead of POST (Ex: See Google search results ) along with the page_number as another attribute and value.
#IVAN .. good to know that the library came helpful..
About that searching option; check the recent commit in github
http://github.com/neotohin/CodeIgniter-Ajax-pagination-Library there is an additional parameter added for searching.
I think the simple code in readme is enough for understanding the mechanism.
You could use datatables
https://datatables.net/
https://datatables.net/examples/data_sources/server_side.html
With this plugin using jquery also you could use server sided page request , you just have to handle the plugin post using Ajax.
post automatically sends row , page offset column, search criteria you just have to provide the json encode return
and the plugin automatically has library in featuring pagination, search sort number of rows per page and the table formatting.
Needed are jquery, and the plugin css and js for this to work
let me know if you understood my explanation.
thanks (=
I know this is not a drupal forum but, as I’m not getting any response there, I decided to give it a shot here.
I’m creating a web site that accepts custom content from users. So, for that matter, this site has a form and a custom module. Instead of using admin theme, this form is placed inside custom template which is created to have a uniform look with the rest of the pages. As a result, creating form elements through hook_form is out of question. Here’s where my problems lie. As this form uses custom theme, I’m not sure as to what can I do to make drupal know that user is submitting new content data when the form is submitted?
Would I need to use same query string that of content submission page of admin page like - ?q=node/add/page for action attribute of the html form?
(OR)
the only way is to map the url to my custom function and invoke some sort of hook inside of it?
Thanks
You can literally create any markup you want for your form, all you need to do is use the #theme attribute when you define the form. With it you can set theme functions for the form itself and any of the elements.
It is a very bad idea, not to use Drupal's FAPI. It solves so many problems for you, and not using it would be the first step to take if you want to open up a security hole in your site. A development framework like Drupal is not of much worth, if you don't use it's APIs.
Edit:
First thing to do, is to go to Drupal's FAPI reference. You can learn almost everything about the FAPI there.
You could use a template if you want, is just basic Drupal theming, but I would advise against it. It would be a lot more maintainable if you created theming functions for all the elements and used that instead, you could just loop through all the elements and render them like Drupal does, instead of having to edit a template file each you need to change the form. It might be a but more work now, but there's a reward to that work: cleaner and more maintainable code.
In code it looks something like this:
$form['item'] = array(
...
'#theme' => 'theme_function',
);
Doing this, the element will be rendered using the "theme_function". You can see an example of such a theme function for textfields.