Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this plugin that displays category featured image thumbnails for each post via shortcodes.. like so,

[categorythumbnaillist 3] (3 being the category of course)

I would like it to only show posts with the tag "news".. only if you set the tag value to "news" via the shortcode. So if you entered in...

[categorythumbnaillist 3 tag="news"]

Then it should only show posts with the news tag in it. If no tag is entered, it should then display the posts for the respective category like the plugin already does.

Here is the code I made for displaying the results.

$args=array(
      'showposts'=> 5,
      'category'=> $listCatId[1],
      'orderby'=> $categoryThumbnailList_OrderType,
      'order'=> $categoryThumbnailList_Order
       );

$myposts = get_posts( $args);
$output = '<div class="categoryThumbnailList">';
foreach($myposts as $post) :

I tried to read and understand Wordpress's shortcode API, but I just couldn't seem to wrap my head around it.

There are more functions from the plugin, So I have provided the full plugin code here: http://pastebin.com/QHrB8xUn

Any help to getting my plugin shortcode to filter results by the tag news (if entered) would truely be appreciated. :)

share|improve this question
    
Have a look at the shortcode_atts() function –  bungeshea_ Dec 3 '12 at 20:07
    
I've been looking at the link you provided trying to implement attributes into my plugin, but nothing seems to be working. My plugin doesn't even use the "add_shortcode" line, and it's real hard to figure out where to put the code to filter out thumbnails by tag.. let alone how to do it at all. :( With that being said, your link did somewhat put me in the right direction. But it will probably take me weeks figuring out how to only show posts with the tag "news".. only if you set the tag value to "news" via the shortcode. And where to put it in my actual plugin. Thanks for the help tho Shea –  I am not a Frog Dec 3 '12 at 20:55

1 Answer 1

up vote 1 down vote accepted

That plugin you have is not using the WordPress Shortcode API as it should be. There is not a single add_shortcode to be found. It has basically cooked up its own shortcode 'feature' by hooking a preg_replace_calback into the_content

define("categoryThumbnailList_REGEXP", "/\[categorythumbnaillist ([[:print:]]+)\]/");

define("categoryThumbnailList_TARGET", "###CATTHMBLST###");

function categoryThumbnailList_callback($listCatId) {

And:

function categoryThumbnailList($content) {
        return (preg_replace_callback(categoryThumbnailList_REGEXP, 'categoryThumbnailList_callback', $content));
}

And:

add_filter('the_content', 'categoryThumbnailList',1);

That is not really the way to do this. The normal shortcode functions aren't going to work correctly.

The callback function, categoryThumbnailList_callback, is only expecting an ID value, $listCatId, so what you are doing is going to take rewrite. You might be able to hack it by parsing that $listCatId value to extract your extra information-- try var_dump($listCatId); at the top of that function and see if you have anything usable. I'd have to install and run this to be able to write good code, but my recommendation is to rewrite the plugin to use the API correctly.

That plugin is listed as being for "WordPress 2.9 and up" so maybe it is just an old plugin, which would be another reason to rewrite.

share|improve this answer
    
Thanks a lot. I ended up using a new plugin with shortcodes that did what I want. It's taking a long time for me to modify it... but it's deff. worth it. Thanks for the suggestion. :) –  I am not a Frog Dec 3 '12 at 23:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.