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
}
?>
Related
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.
I have Developed WordPress Site Successfully, but i have doubt in Getting all the post by
Categories.
My Code is like this
new WP_Query("cat=54,71,72&order=ASC");
Default it is getting the first category id and the Post.
Thanks
If you want to get ALL your categories instead of a selected few, you don't need to query by category.
new WP_Query("order=ASC");
If you want to query a particular category, but you're not sure what's the category ID number, query it by category slug
new WP_Query("category_name=your-category-slug&order=ASC");
You can also use this code as well, just need to change the number of post, like as of now, below listed code is use for display 5 post only, so you have to change this limit.
<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><?php the_title(); ?></li>
<?php the_content();?>
<?php endwhile;?>
</ul>
What I need - The code to perform the following:
I am trying to setup a WordPress template that will display all the comments that have been posted to my blog. How do I pull all comments and have all the same formatting that is applied to comments under a single post? Such as the formatting that occurs when comments are displayed using the comments.php template.
Note I want to pull all the comments from my blog to a single page. I still want the comment pagination but instead of having 20 comments under post #1, 20 under post #2, etc. I want to have all 40 show up at one time on one page.
You want to use the get_comments() function.
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
See also the apply_filters() function to apply comment output filters to specific fields.
<?php echo apply_filters('comment_text', $comment->comment_content); ?>
EDIT:
For pagination, you can use the offset and number parameters of the get_comments() arguments:
<?php
$args = array(
'number'=>20,
'offset'=>0,
'status'=>'approve',
);
foreach (get_comments($args) as $comment) {
// ...
}
?>
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
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.