0
votes

If this is my shortcode in WordPress:

[catlist name='mycategory', template='category-display-template' excerpt='yes']

How can I get the name value to display in my WordPress page? I were thinking of something in the lines of <?php echo $name ?>

Any help would be appreciated.

The plugin code looks like this - here is an extract of the code:

function catlist_func($atts, $content = null) {
            $atts = shortcode_atts(array(
                            'id' => '0',
                            'name' => '',
                            'category_name' => '',
                            'orderby' => 'date',
                            'order' => 'desc',
                            'numberposts' => '5',
                            'date' => 'no',
                            'author' => 'no',
                            'dateformat' => get_option('date_format'),
                            'template' => 'default',
                            'excerpt' => 'no',
                            'exclude' => '0',
                            'excludeposts' => '0',
                            'offset' => '0',
                            'tags' => '',
                            'content' => 'no',
                            'catlink' => 'no',
                            'comments' => 'no',
                            'thumbnail' => 'no',
                            'thumbnail_size' => 'thumbnail',
                            'post_type' => '',
                            'post_parent' => '0',
                            'class' => 'lcp_catlist',
                            'customfield_name' => '',
                            'customfield_value' =>'',
                            'customfield_display' =>'',
                            'taxonomy' => ''
                    ), $atts);

            $catlist_displayer = new CatListDisplayer($atts);
            return $catlist_displayer->display();

    }

add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') );

It is similar to the code provided by Oleksandr Bernatskyi

How do I call the 'name' in this page I have placed the text Need to call it here in the code below where I want the name to be inserted...

$lcp_display_output .= '<a href="'.get_permalink($single).'" title="'.get_the_title($single).'" class="medium magenta awesome">Read More &raquo;</a> '.Need to call it here.' <a href="'.get_category_link($single).'" title="'.get_the_title($single).'" class="medium magenta awesome">Category &raquo;</a><div class="category-clear"></div>';

or the name is actually the "category of the page"

  1. How can I get the name to display either "name" or "category name"
  2. How can I link to the category page?

I am using this wordpress plugin http://wordpress.org/extend/plugins/list-category-posts/

------------------ Or a simplified solution to what I want to accomplish might be this ------

This is the shortcode of how I call the function in the plugin:

[catlist name='Alfa Romeo' template='category-display-template' excerpt='yes' thumbnail='yes' numberposts='1' author='yes' category_name='Alfa Romeo' URL='http://3d-car-shows.com/category/alfa-romeo/']

[catlist name='BMW' template='category-display-template' excerpt='yes' thumbnail='yes' numberposts='1' author='yes' category_name='BMW' URL='http://3d-car-shows.com/category/bmw/']

Now on the plugin page if there were a easy way to pull in the Manual created "category name" and the "URL" value from the shortcode I willbe able to link to custom created pages...

Something like this

<a href="<?php echo $category_name ?>"><?php echo $URL ?></a>

Thanks.

1
Is this shortcode provided by a plugin? - Annika Backstrom
There is a tutorial on how to do this somewhere in the Wordpress Codex. I can't find it right now but it's good - Pekka
Yes Adam it is part of a plugin - Gerald Ferreira
Gerald, so are you trying to modify this plugin and print the $name value, or do you need to access its value outside of shortcode function, say in your template code? - user186994
Ok, let me check this plugin. - user186994

1 Answers

1
votes

Gerald, you can use this template code for List Category Posts plugin to extract category name and build a link to category page:

// Post link
$lcp_display_output .= '<a href="'.get_permalink($single).'" title="'.get_the_title($single).'" class="medium magenta awesome">Read More &raquo;</a> ';

// Category name & link
$lpc_category_id = $this->catlist->get_category_id();
$lpc_cat_link = get_category_link($lpc_category_id);
$lpc_cat_name = get_cat_name($lpc_category_id);

$lcp_display_output .= esc_html($lpc_cat_name);
$lcp_display_output .= ' <a href="'.$lpc_cat_link.'" title="'.$lpc_cat_name.'" class="medium magenta awesome">Category &raquo;</a><div class="category-clear"></div>';