I need to link to a category in my wordpress site. The following code works, somewhat:
<?php
// Get the ID of a given category
$category_id = get_cat_ID( 'People' );
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>
My problem is that it includes /category/ in the url, which isn't how my permalink structure is designed. Does anyone know a way around including /category/ in the url it outputs?
I don't understand what you want to do. Look here Template Tags/wp list categories « WordPress Codex for the template tag for category menus that will include whatever category base you have set. If you want to output the link to a category on the category page itself, then use:
<a href="<?php bloginfo('url'); ?>/<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" title="<?php echo $category[0]->category_nicename; ?>">
<?php $category = get_the_category(); echo $category[0]->category_description; ?></a>
I found a plugin that does work with 2.9:
http://wordpress.org/extend/plugins/wp-no-category-base/
I'm going to leave the question open, though, for those who may know how to solve the problem without a plugin.
Related
I am using <?php the_category(); ?> to display the categories of my post.
It was displaying but my problem is the permalink it produce.
the category link give this for example: http://samplesite.com/category/funpage/
what I want is to remove the category in the link and just produce: http://samplesite.com/funpage/
also, I am using custom post type UI to create post.
anyone can help me please?
You can use get_the_category() function and get all categories for that post and display using loop.
<?php
foreach((get_the_category()) as $category) {
?>
<a href='url you want to pass add here '><?php echo $category->name; ?></a>
<?php
}
?>
I am using the "advanced custom fields" plugin and need to have it so that a custom field is pulled in for the category pages. I can get these to come in on pages, but the category pages are giving me a lot of trouble... 'video' is the name of the custom field I want to pull in.
This is the code I am currently using:
<?php echo get_field('video', 'clear-creek'.$wp_query->queried_object->term-4); ?>
or just a standard version like this which works on the regualar pages...
<?php the_field('video'); ?>
but it's not working... can someone please help steer me in the right direction?
Thanks!
If you are on a category's archive page, you would use this:
<?php echo get_field('video', 'category_'.get_query_var('cat')) ?>
If you are on a custom taxonomy instead, you would use this:
<?php $queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
echo get_field('video', $taxonomy . '_' . $term_id); ?>
This will dynamically get the taxonomy's slug and ID, and build out your get_field based on that information.
Can help somebody. I spent several hours to find solution but without results
I tried to display the list of categories on homepage wordpress blog thru following code
<?php $category = Mage::registry('wordpress_category') ?>
<?php if ($category): ?>
<?php echo $category->getId() ?>: <?php echo $category->getName() ?>
<?php endif; ?>
But the method
Mage::registry('wordpress_category')
always return null.
I found that, i should probably be using the Fishpig_Wordpress_Block_Category_View. But i dont know where i should put it.
The following code will retrieve the current category when viewing a category page in your blog:
<?php Mage::registry('wordpress_category') ?>
This is not what you need. To view a list of categories, you could create a custom collection using the following:
<?php $categories = Mage::getResourceModel('wordpress/post_category_collection') ?>
A better way would be to use the category widget block:
<block type="wordpress/sidebar_widget_categories" name="wp.categories" template="wordpress/sidebar/widget/categories.phtml" />
You can create this in PHP using the following code:
<?php echo Mage::getSingleton('core/layout')
->createBlock('wordpress/sidebar_widget_categories')
->setTemplate('wordpress/sidebar/widget/categories.phtml')
->toHtml() ?>
The above code uses the default template, however, feel free to use your own custom template.
Hi Guys Need help with this very badly.
Need to add shortcode to output in the area circled in white in the picture below.
And the input area is under video description. And from my understanding ive have confirmed that the name for that text area is description_value.
I have looked through every documentation and tried all filters and do_shortcode variations to no avail. Please help i have spent 3 days non stop doing this. Puting the codes in my function.php and so many others. It still does not parse [shortcodes] it just displays text "[shortcodes]". please refer to picture below
Thank you.
This is outputing on the page. I have
<div class="describe-feat">[postexpirator]</div>
This is in a file called grid-gallery.js
<h2><%= item.title %></h2></div><div class="view-gallery">\
<div class="describe-feat"><%=item.desc%></div>\
<% if(item.imgnum){ %><span class="item-num"><%= item.imgnum %></span><% } %>\
This is in custom post editor in wordpress admin area
<textarea name="description_value" class="option-textarea">[postexpirator]</textarea>
https://www.dropbox.com/s/almn09e1dwmeywb/shortcodxe.jpg
It's because, you are missing do_shortcode function for parsing shortcode.
Assuming you just want to target a single value, you could just do this inside the loop.
<?php echo ( do_shortcode( get_post_meta( $post->ID , 'Your textarea Key Name' , true ) ) ); ?>
If your post has multiple values for that custom field, then you can set the above to false.. and loop over the array...
<?php $values = do_shortcode( get_post_meta( $post->ID , 'Your textarea Key Name' , false ) ); ?>
<?php if($values && is_array($values)) : ?>
<?php foreach( $values as $meta) : ?>
<p><?php echo $meta ?></p>
<?php endforeach; ?>
<?php endif; ?>
Just want to add that if you won't use the_post() no shortcode will work,
I had this issue when trying to enable shortcode on CutomFields on a new page type, and nothing worked until activating WP loop with the_post() .
I am trying to pull excerpts and custom fields from specific posts, I have tried using post titles and post id but I am only succeeding in pulling every single post using this query. For example I have this code trying to pull just the title for the post with id 182
<?php $map = new WP_Query();
$map->query('post_id=182'); ?>
<?php while ($map->have_posts()) : $map->the_post(); ?
<?php the_title(); ?>
<?php endwhile; ?>
It pulls the title of every single post using this method and I can not figure out how I am going to have multiple loops like this each pulling content from just one specific post. Can someone please explain where I went wrong?
I've had luck with WP_query('p=182').
If you know the post ID then you can use get_post($post_id); like so
$post_id = 182;
$my_post = get_post($post_id);
$title = $my_post->post_title;
echo $title;
echo $my_post->post_content;
ckeckout codex