I'm building a website in WordPress using the Advanced Custom Fields plugin alongside metaslider, I want the user to be able to select a metaslider from a dropdown list by using a custom field.
I know that you can add a slider in via the WYSIWYG however I want to make a seamless way of doing this, it's probably not as simple as I'd like it to be.
The website consists of projects and will have several sliders all will be appropriately named and I want to make it foolproof for the user.
I've searched online and can't seem to find anyone else who has wanted/tried to to this.
Ask an questions you have if i haven't been clear!
Any help would be greatly appreciated.
It's okay, I figured out how to do it!
You can select a field type of "post object" then add a "post type" of Meta Slider then the user has a dropdown box where they can select which slider they want to display on the page.
Metaslider shortcode id in ACF:
$slider_object['value']->ID
Try:
<?php $slider = get_field_object('slider_item'); ?>
<?php echo do_shortcode('[metaslider id="'.$slider['value']->ID.'"]'); ?>
Related
I am currently trying to add an additional input field where users are able to specify an aria-label inside the already existing link field within Advanced Custom Fields in Wordpress. I’ve attached an image to give a visual representation of what I am looking to do.
Link Modal
Then on the frontend you would use something like $link[aria-label] to get it from the link array.
Any help to achieve this would be amazing. Thank you!
You can try if that field already exists in the ACF link.
Store that link value in a variable and print_r it and check. Check the below code.
<?php
$link = get_field('YOUR-FIELD-NAME');
print_r($link);
?>
I am frankly new to wordpress but programm in PHP.
Task:
I have a form (don't wanna use a form plugin) and want to include this form on either 1. Sidebar or 2. within content of any Page except one (Contact-page).
I want to programm the Widget, Shortcode or Plugin bymyself. I don't need a tutorial how to programm this.
Question:
What do you advise me to use: a shortcode, plugin, widget or a "hack" in the template (f.e. if ($page!=="contact"){...}
The answer should consider
Ease and flexibility of use
Short time to develop
Speed of Rendering
Thanks for advise of experienced Wordpress Users/Developpers.
PS: the form is very simple maybe there is even another fast way you know how to do this.
Try This
1)first to fall you make a page templates of contact page.(make copy of page.php than only change the name of templates)
2)than that template in you make your custom form.
3)that page template you apply in your contact page.
Make a template-myForm.php file, and populate it with following:
<?php
/**
* Template for displaying search forms for My Web Site
*
*/
?>
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<!-- your form content-->
</form>
Add to site <?php get_template_part( 'template', 'myForm' ); ?> where you want a custom search form. I used it for search form, so it was easy to make it into widget also. I used separate template file for site search, and searcform.php for search widget. If you are aiming at different kind of form tag, you have to create that a Widget.
It is a class Your_Widget extends WP_Widget, which for you can find tutorials on your own, or just check out PHP code file: wp-includes/class-wp-widget.php in your Wordpress copy and extend it. Me personally use tutorials. I find it more simple.
So, to summ up, you would have two copies of your form - one to show as a template part, and an another one for sidebar or other registered widget area. If it is identicall in both versions, using this solution you would have to remember to keep changing it in two places (which is again simpler than hard-coding).
For me beeing not a native English speaker and just a part time Wordpress coder, this is what I offer. More integrated and PHP-programming-friendly solution, find in Wordpress forums, here on stackoverflow and Wordpress.org site.
I also am aware this is not exactly what you are looking for - not using shortcode. I hope this will kick you off into Wordpress world, and you will find how to offer a custom form to your users!
Good luck!
I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!
The only way to set a category to a new post seems to be to select the appropriate one via a check-box before submitting it.
At best, you can set a default category as an option in case no box has been checked by the user.
This is really a problem for me as my admin menus are and have to be the categories themselves.
As I mentioned, in my WordPress admin I have a custom menu listing category names. Clicking on one leads directly to the generic "add a new post" page.
What makes it less generic is that I have inserted the category ID within this link, like this: "wp-admin/post-new.php?cat=5".
At this point,I would like not to check a category from a box before submitting the new post. Instead, I want WordPress to use the variable provided in the URL and submit the category ID accordingly when my new post is ready to be published.
Is it possible?
Which file would I have to edit in order to achieve this?
Any other idea that would lead to the same result?
You can use an extension that you will develop. It is better than trying to modify Wordpress core files.
I did something that may help you in one of mine. Using this :
if(is_admin()){
add_action('post_submitbox_misc_actions', 'plugin_add_custom_box');
}
function plugin_add_custom_box(){
?>
<div class="al2fb_post_submit">
<div class="misc-pub-section">
<?php
echo '<input type="checkbox" id="plugin" name="plugin_action" value="1"/>';
echo '<label for="plugin">';
_e("Label", 'myplugin_textdomain');
echo '</label> ';
?>
</div>
</div>
<?php
}
This add a custom checkbox. Using the same name for the checkbox here than checkboxes already displayed by Wordpress and checking it analysing your URL, you will probably be able to store the category you want without modifying core files.
I am trying to add a button to my WordPress template. Basically, I have the post and then there is the Related Posts Thumbnails widget that appears. I want the button to go between the text of the post and the related posts thumbnail widget. The code in my 'Single Post' that contains all of this is as follows:
<div class="post-content">
<?php the_content(__('<em><strong>More:</strong> Read the rest of this entry...</em>', 'life-is-simple')); ?>
</div>
I know the Related Posts Thumbnails plugin falls within this code because it's at that place when I 'Inspect Element' on Google Chrome. I can't find how to edit the order of things within that div though. Any help would be greatly appreciated, thanks!
EDIT
Clarification: I am using the Life Is Simple WordPress theme although it has been custom editing quite a bit (mostly on the CSS side of things though).
That plugin is probably appending the output to the_content with a filter .
That means , that the output is being added to the_content automatically. it is a common behaviour.
You need to look at the plugin´s admin interface to see if you can have an alternative way (I believe there is ) which is using a template tag. in that case, you should put the template tag after the div where the the_content() is .
EDIT I :
After a small dig, - in fact there is - you need to put
<?php get_related_posts_thumbnails(); ?>
Then the plugin should know by itself not to append to the_content.
For parameter passing, or if something is not working, go read their APi or help files.
You'll probably need to edit single.php or archive.php in your theme. If nothing is occuring there that looks familiar, it's probably using a loop. In which case you might find what you are looking for either in loop.php, loop-single.php, or loop-archive.php depending on what type of page you are on and how the theme was constructed. Add your button near where you find Read the rest of this entry...
With more information (such as what theme you are using), one might be able to help more as well.