• Hello,

    I have created a custom post type called team.
    Ive also created a shortcode to display the list of team members with no problems.

    How can I add an attribute to the shortcode to display a member by name? ( the page title)

    I’ve been playing around with the example given in the codex:

    function bartag_func( $atts ) {
    	$atts = shortcode_atts(
    		array(
    			'foo' => 'no foo',
    			'bar' => 'default bar',
    		), $atts, 'bartag' );

    http://codex.ww.wp.xz.cn/Function_Reference/shortcode_atts

    But not sure what to edit.

    Any help much appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Can you please post the code for your shortcode?

    Thread Starter rikardo85

    (@rikardo85)

    I’m currently using:

    add_shortcode( 'myteam', 'mysite_team_sc' );
    function mysite_team_sc() {
    
        if (get_option('my_team_grid_display') == '2') // if grid display has been selected.
        {
    	include( plugin_dir_path( __FILE__ ) . 'templates/my_team_grid.php');
        }
        else
        {
    	include( plugin_dir_path( __FILE__ ) . 'templates/my_team_list.php');
        }
    }

    The shortcode only includes other .php files. The change will need to be made there. Please put the code for templates/my_team_grid.php in a pastebin and post a link to it here.

    Thread Starter rikardo85

    (@rikardo85)

    I’ve altered the shortcode slightly, removing the php files:

    http://pastebin.com/ECgKMUrK

    Thank for helping

    OK, that helps. Now please explain more how you want the shortcode to perform.

    When you say you want to display a member by name, do you want the shortcode to display only one member, or do you want the member’s name in the list to show the member’s page when clicked, or something else?

    Thread Starter rikardo85

    (@rikardo85)

    I want the ability to show members by:

    – Name (page title)
    – Category (taxonomy)
    – limit to display

    e.g [myteam title=”member name” category=”taxonomy name” display=”2″]

    I’ve got a list of team members (custom post type) that appear when adding [myteam] to a page.

    But on some page I want the ability to just add one specific team member (using something like the parameters given in the shortcode above)

    Hope that makes sense.

    I can’t test the code but this should be close to what you want: http://pastebin.com/amjLJjii

    If you provide a member name (page title), only that page is displayed: category and display parameters are ignored.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Add attributes to shortcode for custom post types’ is closed to new replies.