Advanced Custom Fields Add Class to Element - php

I'm using Advanced Custom Fields' flexible content area in a Wordpress theme that I'm developing. One of my sub_fields requires a textarea.
When I make my get_sub_field call from my template it is already wrapped in <p></p> tags. How do I go about adding a class to that paragraph?
Example:
get_sub_field('textarea');
Output:
<p>This is my textarea.</p>
Desired:
<p class="my-class">This is my textarea.</p>
Thanks for your help!

Go to your Textarea custom field settings and change "Automatically add paragraphs" to none.
So WP-admin-> Custom Fields -> Field group -> then your field group-> edit textarea-> look for "Controls how new lines are rendered"

You can add a second false argument to get_sub_field() to disable reformatting on a case-by-case basis in the template:
get_sub_field('textarea', false);

Related

Update widget archives dropdown label text

I’m using Archives widget dropdown from Admin panel on my blog listing page and I need to change the select label from "Select Month" to "Archives".
The original widget_archives_dropdown_args filter is inside wp-includes/widgets/class-wp-widget-archives.php file.
I have created the following function to update this label, but can make it work:
function ArchiveSelectTitle($archive_args){
$archive_args['type'&'monthly'] = __('Archives');
$archive_args['limit'] = 12;
return $archive_args;
}
add_filter('widget_archives_dropdown_args', 'ArchiveSelectTitle');
Any ideas how it should look like? Your help is very appreciated!
Unfortunately the widget_archives_dropdown_args filter only allows you to filter the type, format and show_post_count values. There is no filter available for the select label.
I would recommend that you set the widget title to 'Archives', and keep the label as is. The label on the select element is descriptive of the function of the dropdown, its purpose is to give the user an indication of what to do, so using the word 'Archives' there wouldn't really make sense.

BuddyPress add custom class to profile page buttons

I am trying to create a custom theme for BuddyPress and in the template the buddypress/members/single/member-header.php file at line 45 there are buttons rendered using <?php do_action( 'bp_member_header_actions' ); ?>
After a lot of searching around I found out that I should be able to use filters to add custom data to elements, the problem is that I can't find anywhere as to what filter to use or how to use such a filter to add a custom class to these buttons.
The buttons I am talking about are the buttons like "Add Friend", "Public Message" and "Private Message" and I would like to add the "btn" class.
Any help is greatly appreciated.
Check out these filters:
bp_get_add_friend_button
bp_get_send_public_message_button
bp_get_send_message_button_args
EDIT: Updated (see comments)

Custom link and name meta box in wordpress

I would like to create a metabox in the section of edit post menu. Like Tags for exemple, BUT instead of inserting tags I would like to put a link (ex. http://www.google.com) + name.
This link should go right to the end of my post content as a hyperlink with "Source: Name (hyperlinked by specified link)
Here is an example of what I am needing:
Title
This post is for example
Source: Google
Any help would be much appreciated. Thanks guys.
You can use the Custom Fields in Wordpress posts to add extre information to a post, then in your theme you can just grab the values. Here is what I use on my blog:
$custom_fields = get_post_custom($post_id);
if(!empty($custom_fields['article_source_url'][0]) && !empty($custom_fields['article_source_title'][0])){ ?>
<strong>Source</strong>: <?php echo($custom_fields['article_source_title'][0]); ?>
<?php }
Then in your wordpress post just add a Source URL and Title in the custom fields box:
You can use WP's Custom Fields to denote specific parameters for each page/post.
Then, in the template, just call them like this:
<?php
$custom_fields = get_post_custom();
var_dump($custom_fields);
?>
Note that they are arrays, so in case you have a field named URL, you'd need to call it like
echo $custom_fields['URL'][0];
This is done like this so you can have multiple values for the same field.
Also, in order to see the Custom Fields box, you need to go to the Screen Options (top right of the edit page) and enable them.

Wordpress conditional post layout

I need to display multiple styles of posts; News1 and News2. The problem i am having is that i need to display each post in a different style. IE for posts that are in News1 they need to have date and share buttons but for News2 i don't need this.
I have a custom field set up to section News2 off called "Archive Category" and can use the get_post_meta for this.
My problem is just the conditional statements that should be in the posts file.
If anyone can help it would be greatly appreciated.
Thanks
In single.php, get the custom field value, then according to the value, call different template part:
get_template_part( 'prefix', 'other-parts-of-the-file-except-extension' );
In the template part files, layout the single post/page differently.
To elaborate, the actual layout code shall be written in template part files. The single.php only checks the custom field value, and call different template part file according to the value.
Pseudo-code would be (in single.php or single-post.php or single-customposttype.php, whichever you're using):
<php
$value=get the custom field value; // replace this with your function to get the value
if($value=='News 1')
get_template_part('template', 'news1'); // then you'll put layout in template-news1.php
else
get_template_part('template', 'news2'); // layout in template-news2.php
?>

How to use PHP in the header of a drupal view?

I have a drupal view, which displays a content type filtered by a url argmuent (e.g. category). Now i'd like to add a link in top of my view, which allows my users to add a new node. In the add form the argument field should be prepopulated with the value from the filter.
I think to archive this, i have to install the prepopulate module and add some php-code to the header section of my view, which generates the link.
Any suggestions how to manage this?
If you are wanting to add php code to get the arguments passed to views in the views header section, do the following:
Make sure that the PHP filter is turned on; this is a module that can be enabled
In the header section use the following code:
$view = views_get_current_view();
// [0] is first arg, [1] is second etc.
$argumentOutput = $view-> args[0];
Remember to have the input format set to PHP code. This will get you the argument passed to views.
It would be a lot easier to override the template for the view and insert the code/markup there. Check out the Theming infomation inside the view to find out what to call your template.

Categories