I am using an options framework (NHP Theme Options) for my wordpress theme, I don't have a problem with things like adding things like 'if' statements, ex if option is selected 'echo' this information.
That alone allows for a lot of dynamic options. I added a wordpress editor box in my admin panel and I am a little lost on how I would output the information that is inside the box.
It's inside my theme options page inside an array,
array(
'id' => 'header-area',
'type' => 'editor',
'title' => __('Editor Option', 'my-opts'),
'sub_desc' => __('Can also use the validation methods if required', 'my-opts'),
'desc' => __('This is the description field, again good for additional info.', 'my-opts'),
'std' => 'headarea'
),
typically I use if statements, here is an example of how I output my options.
<?php if( my_opts_get('header-area') ) {
$fixed_header_css = 'top: 0;';
} else {
$fixed_header_css = 'top: 51px;';
} ?>
This is just an example, but I am a PHP novice and don't know how to output the editor array.
I know its not by using an if statement, I tried things like
<?php echo my_opts_get('header-area') ?>
I think that may be close, but I am obviously missing something
The answer was right under my nose, using this simple line of code was all I needed to output the data..
<?php echo moon_opts_get('header-present-area', 'home-area'); ?>
Related
I've been trying to create a custom tab for my website and am using UltimateMember plugin.
After bit of google I found some code snippet that can help me do it:
First we need to extend main profile tabs
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
);
return $tabs;
}
Then we just have to add content to that tab using this action
add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
function um_profile_content_mycustomtab_default( $args ) {
echo 'Hello world!';
}
But my question, to what file should I add this code to achieve what I need. It sounds very numb of me to ask this, but I'm seriously confused.
Thanks for any help.
Let me share my similar experience. First of all in this code :
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
);
You should use always
mycustomtab
as key which I see you've already used. So that's true.
Generally it works out when you put this code in your active theme's functions.php
But if it doesn't work out, consider adding this to core file um-filters-misc.php in the plugin core file folder for ultimate-member. Let me know if it works for you.
Not sure if anyone still needs help on this, but make sure to add a 'custom' key/value like this:
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
'custom' => true // <- needs to be added so it shows up on the profile page
);
The code example in the UltimateMember documentation -specifically for extending the Profile Menu using hooks- doesn't work because the sample code doesn't have that line.
Hi guys thanks for your help... im using this codes and works "good"... if a want to put shotcode the website print "blue screen" error... [ultimatemember form_id="15817"] (if i use "hello word" works perfect..
function um_mycustomtab_add_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'Seguimiento',
'icon' => 'um-faicon-pencil',
);
return $tabs;
}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );
// Action
function um_profile_content_mycustomtab_default( $args ) {
echo do_shortcode('[ultimatemember form_id="15817"]'); //this not work
}
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
here some screenshots tests
I'm trying to created a custom shortcode in wordpress but I can't get it working.
Here's the code I have so far:
function wp_test_video($atts) {
extract(shortcode_atts(array(
'X' => ''
'Y' => ''
), $atts));
return '[iframe src="http://www.example.com/test.php?X='.$atts['X'].'&Y='.$atts['Y'].'"]';
}
add_shortcode('test', 'wp_test_video');
Everytime I try and insert it into my functions.php file my site just breaks.
EDIT: The shortcode is now working but it seems to be acting differently from the same code inserted without the shortcode.
Here is an image of the compiled code from the shortcode in a post by itself:
http://i.imgur.com/4lM8jC5.jpg
Here is what a post looks like when using the shortcode to generate the same code:
http://i.imgur.com/gxk6k3C.jpg
The video is embedding but it's breaking out of the article wrapper causing none of widgets or comments to work (also appears to mess up the search bar at the top).
You forgot a comma after your first item in your array and forgot to assign the shortcode_atts to a variable. Don't use extract(), it's deprecated.
function wp_test_video($atts) {
$atts = shortcode_atts(
array(
'X' => '', // <-- This one
'Y' => ''
),
$atts);
return '[iframe src="http://www.example.com/test.php?X='.$atts['X'].'&Y='.$atts['Y'].'"]';
}
I've created a short code that I'm trying to pass an attribute into, but I don't seem to be receiving the value on the other end.
Here's what I've got below;
function list_display($atts) {
extract( shortcode_atts(
array(
'pageName' => 'No Page Received',
), $atts )
);
echo $pageName;
add_shortcode('list-briefings-display', 'list_display');
}
and the shortcode being used is
[list-display pageName="My Page Name"]
and I'm running a require_once from functions.php
require_once ( TEMPLATEPATH. '/includes/list-display.php' );
But what I'm seeing on the screen is 'No Page Received', can anyone think of something I might've missed?
There is more content being generated by the shortcode, which I have't included, that's rendering fine. So it just seems to be something to do with how I've passed the attribute.
Any help is appreciated.
function list_display($atts) {
$atts = shortcode_atts( array(
'pagename' => 'No Page Received'
), $atts );
extract($atts);
echo $pagename;
}
add_shortcode('list-display', 'list_display');
You'll probably want to use "return" instead of "echo" if you're using the shortcode within pages and posts.. Echo could cause it to send output to the screen a little too early and won't end up exactly where you may be expecting it to be.
There was also a little formatting issue in your code that I've corrected, mainly trying to use add_shortcode() from within the very same function you're trying to reference. I also changed the first parameter of add_shortcode() to the shortcode you were trying to use in your example.
I'm a php newbie and a first time poster.
I am working on a wordpress site where I need a discography.
I have successfully:
Created my custom post type : Albums
Added custom meta boxes and custom fields to admin post edit page
Made an archive page and echoed all the custom field meta.
http://squarerecording.com/albums/
One of my custom fields is a series of 5 checkboxes: the last line of each album on that archive page
array(
'name' => 'Services Rendered',
'desc' => 'field description (optional)',
'id' => $prefix . 'services',
'type' => 'multicheck',
'options' => array(
'R' => 'Recorded',
'Mi' => 'Mixed',
'Ma' => 'Mastered',
'P' => 'Produced',
'RMV' => 'Re-mastered for vinyl',
),
),
although I have successfully echoed the "Services Rendered" in a comma separated format, the order is different for each post (P,RMV,R,Mi,Ma-for the first one, P,Ma,Mi,R,RMV-for the second, etc.)
Here is the code for the archive page that outputs "Services Rendered":
<?php $key="sqr_services"; get_post_meta($post->ID, $key);
$sqr_services = get_post_meta( $post->ID, $key );
$comma_sep_services = implode(",", $sqr_services );
echo $comma_sep_services;
?>
My question is: What do I need to do so that they are listed in the same order that they appear on the edit page ( R,Mi,Ma,P,RMV)? Bearing in mind that they will not always ALL be checked.
I have tried messing around with unserializing but i don't know enough about it.
Any help or a point in the right direction would be greatly appreciated!
Thanks
This post might be of interest. It's one of the few solutions I've seen that doesn't involve editing Wordpress core files.
You could also try this modified get_post_custom function that orders the key/value pairs by meta id instead of the "date modified" order returned by get_post_custom.
A third option would be to sift through this answer.
Update: Silly Me! PHP can sort arrays any darn way you want, and it just gets a teeny bit tricky when that's not numerical or alphabetical. If alphabetization works for you, attempt the following:
$key="sqr_services";
get_post_meta($post->ID, $key);
$sqr_services = get_post_meta( $post->ID, $key );
asort($sqr_services);
foreach ($sqr_services as $key => $val) {
echo "$val\n";
}
If you want to learn yourself more complex array sorting, be my guest. Me? I'll stick to ABCs.
Update: Silly You!
In response to your comment about checking for and displaying individual values in your $sqr_services array, alls you needs to do is check in_array():
if (in_array('Recorded', $sqr_services)){echo 'Recorded';}
if (in_array('Mixed',$sqr_services)){echo 'Mixed';}
if (in_array('Mastered',$sqr_services)){echo 'Mastered';}
if (in_array('Produced',$sqr_services)){echo 'Produced';}
if (in_array('Re-mastered for vinyl',$sqr_services)){echo 'Re-mastered for vinyl';}
It's less flexible in that if you add a value to the array (add a new tax term), it won't start showing up until you check for it in your loop. I'm guessing that's not gonna be a problem, though, as this seems like a pretty finite set of options.
I am working on a site that calls the categories of a wordpress page and displays them in the right-side navigation using a php call. I am new to php and web programming in general. Is there a way I could split the categories into two sections using a particular php call or perhaps an if-loop.
Essentially, I want to display particular categories under custom sub-headings to better organize the site. Any help, I'm currently using the following script to display my categories:
<ul><?php wp_list_categories('show_count=1&title_li='); ?></ul>
Here is my site for reference: http://www.merrimentdesign.com
Try using your code above twice. Each time, you can use the other function arguments to limit the output to certain categories. See http://codex.wordpress.org/Template_Tags/wp_list_categories for the various ways to customize the output of the function.
For example you could use:
<ul><?php wp_list_categories('show_count=1&title_li=&child_of=100'); ?></ul>
// where 100 is the parent id of all of the categories you want to print.
<ul><?php wp_list_categories('show_count=1&title_li=&exclude_tree=100'); ?></ul>
// and then show everything, but children of 100
Or simply use the first string multiple times specifying different parent ids each time.
By far and away your best option is to use the new menu functionality within WordPress. It's dead straight forward to set up in your theme:
add_theme_support( 'menus' );
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'public-menu' => __( 'Public Menu' ),
'sidebar-public-menu' => __( 'Sidebar Public Menu' ),
'sidebar-members-menu' => __( 'Sidebar Members Menu' ),
'sidebar-staff-menu' => __( 'Sidebar Staff Menu' ),
'footer-menu' => __( 'Footer Menu' )
)
);
}
place that in your functions.php file (and obviously change it for your requirements).
Then in your template file - probably sidebar.php you'll want something like:
<?php wp_nav_menu( array( 'theme_location' => 'sidebar-staff-menu', 'container' => false ) ); ?>
And then go to the back end of WordPress (your wp-admin) and then go to Appearance > Menus and voila you're able to drag and drop your categories to your heart's content!
Helpful link: http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus
Read that, Justin Tadlock is awesome.
Good luck.