has_category WordPress - wordpress

I would like to check in the Wordpress loop for a category named Hyperlink and Quotes because I will not display those categories.
I checked the Wordpress site, but I am still stuck. What I got so far:
has_category(Hyperlink, Quotes); --> This doesn't work!
has_category(array(Hyperlinks, Quotes); ); --> This doesn't work either!

http://codex.wordpress.org/Function_Reference/has_category
It looks like the proper syntax would be has_category('Hyperlink'). I'm not sure if you left the quotes out by mistake or if you didn't know they needed to be there. They need to be there.
Also, it looks like has_category(array('Hyperlinks', 'Quotes')); would work as well.
HTH,
=C=

Related

Custom image field with drupal(7) views 3

I've created custom theme look for one of my fields in views, and added field field_field_services_text_link[0]['rendered']['#markup'];?>. I tried to do same with my another image field, but it doesnt works. I used field_field_services_image[0]['rendered']]['uri']; ?>, but something wrong in this code. Any ideas how to solve it?
To troubleshoot this, perhaps the following would help. Paste it in your theme file instead of what you have above
<?php print_r($field_field_services_image); ?>
the print_r function will show you the structure of the array ($field_field_services_image) you're trying to work with and can show you whether the structure is exactly as you'd expect. Perhaps there's a problem somewhere in the [0]['rendered']... portion, and you can check that. It may be empty somewhere, etc...
You could always see whats being output with a var dump or even better, the devel module.

Wordpress automatically adding site url to href, though href not empty

So I'm trying to debug a somewhat confusing problem. I'm using a Wordpress plugin for a Topspin store that uses colorbox to popup a window to display more information about an item. Here's the site: okgo.net/store. In the backend code for this page a div block is created containing links that that should look like this:
<a class="topspin-view-item" href="#!/77022">
The php that does that is as follows:
<a class="topspin-view-item" href="#!/<?php echo $item['id']; ?>">
The problem is that what is being spat out at the end is not that. It looks like this:
<a class="topspin-view-item" href="http://okgo.net/video-store/#!/89712">
I've understood from another post on here that the default behavior of Wordpress is to fill empty hrefs (ie href="") with the site url. So my guess is that Wordpress is for some reason interpreting this as an empty href? Except that that doesn't seem quite right either.
I've played around with this a bit. One thing that happens is that if I remove the has from the above PHP the siteurl is not output at all. That of course breaks my code.
Any ideas? Any help would be warmly appreciated.
The way we ended up fixing this for those who may be interested is by simply adding the following line of code to the jQuery handler that dealt with the on submit event:
event.preventDefault()
Perhaps this will be of help to someone...

Insert a plugin manually into wordpress page

I am working in worpress front page.
I want to add a plugin to the page at a specific location manually but adding the code to the page myself.
I basically want to include a plugin in a certain page on a certain location. So I'm create a div...
<div id="plugin-holder">
**Plugin-will-appear-here-with-this-code**
</div>
Don't anyone know how this is done please?
Thanks
If you're wanting a plugin to appear somewhere, you'll be looking for "shortcode" functionality.
This is actually surprisingly easy to code, check out the examples in the Codex under Shortcode API - ie:
function bartag_func( $atts ) {
// ... do more things here ...
return "text to replace shortcode";
}
add_shortcode( 'bartag', 'bartag_func' );
Once you've called these functions you can use [bartag] in code and it will run your function and replace the shortcode with the generated text your function returns.
If you're adding shortcode functionality to your site, it generally makes most sense to code a really simple plugin and put it in that. The reason why this works best is that, over time, it's really easy to forget and upgrade a theme by mistake (or even change to a new theme) and thus break your site by losing your custom code in your former functions.php. Surprisingly, this is pretty easy to achieve and only requires some specially formatted comments at the top of your plugin file and a little common sense in coding - there are many tutorials and "how to"s around!
Here's a useful shortcode tutorial: http://www.reallyeffective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part-1/
You should add the relevant plugin code to functions.php.
I suspect you'll want to use some conditional tags, like is_home() to pinpoint your location. But maybe not, depending on what you are trying to do,
Also, if you're trying to to insert from a pre-existing plug-in, make sure you remove the register_activation_hook or activate_pluginname action.
If your plugin supports a sidebar widget you can simply "widgitize" the div tag that you wish to insert the plugin into.. Google the term and you are gonna find many resources.

Modifying the menu navigation to include the domain

Some background if you want to see why I'm doing what I'm doing:
I have a client who wanted a new blog done with Wordpress on a separate subdomain. Their existing website is on Drupal, which I have had 0 experience with prior to this. They have a pretty extensive navigation on that site (multiple levels), so rather than create duplicates of nav menus that would need updated on both wordpress and drupal, I am using YQL to pull in the whole navigation onto the Wordpress website. I know this isn't great for SEO, but at this point I'm not worried about that.
The issue I have is that all of the links on the Drupal website do not include the http://domain.com so that none of the links work on the blog site, because they're going to relative pages on that subdomain that don't exist.
So in summary, what I'm trying to accomplish:
I need each href that Drupal is generating to begin with 'http://domain.com'. Currently they just start with '/pagename'. I have no clue what Drupal version the site is on nor on how to find it, sorry. The site is using Drupal's Nice Menu plugin as well. I've been digging through the files for a couple of hours now, and can't figure out where I need to make the change. Please help! Thanks
Edit: dobeerman mentioned using custom_url_rewrite_outbound to settings.php. This seems to accomplish close to what I want. I tried adding this to the end of settings.php:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
global $user;
$path = 'http://www.reillypainting.com/'.$path;
}
However, the end result of an href in the menu becomes this example:
href="/http%3A/%252Fwww.reillypainting.com/services/sell/rent-your-house"
So the other code generating Drupal's menu is trying to escape the :// and it's also still adding a / to the beginning of the href. Anyone know how to avoid this?
Drupal has function custom_url_rewrite_outbound you can add to settings.php
Use this code:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
$options['absolute'] = 1;
}

Wordpress: apply_filters & add_action to the_content = EVIL?

I asked this question over in the actual tutorial, but not sure I'll get an answer anytime soon as it's almost 2 months old... so I'll take a gander here...
Tutorial is here: Build a WordPress Plugin to Add Author Biographies to your Posts
To sum up the tutorial and what the problem is, The tutorial adds an Author Bio on to the end of the content like so (the short version):
function x($content) {
return $content . "Author Bio";
}
add_action('the_content','x');
The Problem:
When someone uses:
$z = apply_filters('the_content', 'some content here');
echo $z;
The Author Bio will end up applied to $z and if $z is echoed out in the middle of some page… the Author Bio would be in the middle of some page… correct? (it's correct because I've tested it...)
Is there a better way to apply something to the end/under/below the_content hook? other than add_action(‘the_content’, ‘some_function’) because this to me seems evil...
or is apply_filters(‘the_content’, ‘some content here’) not the norm or something developers shouldn't be using inside their WordPress templates…? (which seems pretty much the norm, at least upon Google-ing formatting "the_content" outside the loop)...
Using apply_filters('the_content','some content here'), while it may not be 'the norm' (I don't know. I haven't seen it before, but if I needed formatted text, that's what I'd do), is a perfectly valid use of filters to get some text formatted like the content. Unfortunately, there's no better way to append something to content from a plugin. That is just the way these things work.
However, there's a (less than optimal) way of circumventing this. As part of the setup/install process for your plugin, have the user insert a custom function call, action, or filter into their theme. I know several plugins that do this, so it's not all that uncommon. Something like this:
do_action('my_super_awesome_bio_hook');
Would allow you to hook in without worrying about adding a bio to unexpected (and unintended) content. Even better would be inserting a filter:
echo apply_filters('my_super_awesome_bio_filter_hook','');
That would allow your plugin to modify the bio, but also allow the one using the plugin to override it if necessary (like on pages where they're just using excerpts, like search results, etc.).
Hope this helped.
Also, one minor addendum: you should be using add_filter, not add_action to append the Author Bio. add_action still works, but it's a filter you want to be using.
I bumped into a similar issue with a widget I'm dev'ing. I just found this:
http://codex.wordpress.org/Function_Reference/wpautop
Which I'm now going to use instead of add_filters('the_content'). I want the WYSIWYG formatting but I don't want things append to my content because it's not traditional content anymore.

Resources