How do you embed the Wordpress Categories widget in a page/post outside the sidebar? - wordpress

Rather than use another widget I want to code the method to include the WP "Categories" widget directly within the content of a page or post.
Any ideas?

You can also use a plugin called Widgets on Pages and then just drag Categories into the newly created "sidebar" - then you just put the shortcode [widgets_on_pages] anywhere you want to use it.

To add wordpress post categories into the template file you need to use
<?php wp_list_categories($args); ?>
Default arguments are :
<?php $args = array(
'show_option_all' => ,
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => ,
'feed_type' => ,
'feed_image' => ,
'exclude' => ,
'exclude_tree' => ,
'include' => ,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'show_option_none' => __('No categories'),
'number' => NULL,
'echo' => 1,
'depth' => 0,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'category',
'walker' => 'Walker_Category' );
?>
or you can simply use it without parameters, in that case defaults will work.
<?php wp_list_categories(); ?>
you can read more about this function here

I think, you search for this.
https://wordpress.stackexchange.com/questions/36511/are-widgets-meant-to-be-used-outside-of-sidebars

Related

Get Wordpress Tags With 0 Posts Count

I'm trying to get some tags from wordpress database, tags that aren't assigned to any posts, so their post count is 0.
The code i use selects only the tags with 1 or more posts assigned...
<?php
$args = array(
'smallest' => 12,
'largest' => 24,
'unit' => 'px',
'format' => 'flat',
'orderby' => 'name',
'order' => 'DESC',
'exclude' => null,
'include' => null,
'topic_count_text_callback' => 'default_topic_count_text',
'link' => 'view',
'taxonomy' => 'post_tag',
'echo' => true,
'child_of' => null,
'show_count' =>1
);
?>
How can i get the tags with 0 posts assigned to show?
Set hide_empty to false in the arguments of the get_tags function.
get_tags(array('hide_empty' => false));
If you're using custom taxonomy, use get_terms function.
get_terms('custom_tags', array('hide_empty' => false));

How can i make wordpress blog pagination like this?

How can i make my wordpress blog pagination like this image below:
So that it will show page number as "Page (number)" and arrow sign is for next and previous blog page.
Please help me
Thank you
posting answer for badge.
the function used to get pagination is the following. The parameters set with have only current page number preceeded by 'PAGE'
$args = array(
'base' => '%_%',
'format' => '?paged=%#%',
'total' => 1,
'current' => 0,
'show_all' => false,
'end_size' => 1,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => __('<'),
'next_text' => __('>'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => 'PAGE',
'after_page_number' => ''
);
echo paginate_links( $args );

Wordpress: Select a sub category for a post, and show it on the main category

I have on my wordpress these categories :
- Main Category
- Sub Category
- Another Category
Then I create a post with only "Sub Category" selected.
When I'm showing the "Main Category" content, the post doesn't appear, so is there any solution to show all sub categories posts on the main category?
Thank's!
I think you can use this function:
wp_list_categories( $args );
$args = array(
'show_option_all' => '',
'orderby' => 'name',
'order' => 'ASC',
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'include' => '',
'hierarchical' => 1,
'title_li' => __( 'Categories' ),
'show_option_none' => __( 'No categories' ),
'number' => null,
'echo' => 1,
'depth' => 0,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'category',
'walker' => null
);
Link: http://codex.wordpress.org/Template_Tags/wp_list_categories

custom post type wp_dropdown_categories

How can i customize wp_dropdown_catagories to show custom posts. Let say posts created by woocommerce. Here is my code which shows blog posts. But I want custom posts in dropdown. How can I achieve that?
<?php $args = array(
'show_option_all' => 'All Catagories',
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 0,
'child_of' => 0,
'exclude' => '1,5',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 1,
'tab_index' => 0,
'taxonomy' => 'category',
'hide_if_empty' => false,
); ?>
<?php wp_dropdown_categories( $args ); ?>
Resolved this. Added taxonomy of woocommerce in above code. Just replace value for taxonomy in product_cat.
'taxonomy' => 'product_cat',

Wordpress Admin Query for pages

I am trying to replicate the query that is used in the admin section to display the pages in the exact same order as there. However when I write:
$args = array(
'showposts' => '-1',
'post_type' => 'page',
'orderby' => 'menu_order',
);
I cannot retrieve the same order as in the admin. I assume there is an inner JOIN query to select based on the parent page and the menu order. I want to replicate the exact same order in a custom meta box and enable the user to say that they are related.
Can somebody help me to achieve this? If it is not possible I can use a custom query to select them directly from the db.
Thank you all in advance!
Maybe you should try to make something with the order param like this
$args = array('showposts' => '-1','order'=> 'ASC','post_type' => 'page');
<?php
$args = array(
'authors' => '',
'child_of' => 0,
'date_format' => get_option('date_format'),
'depth' => 0,
'echo' => 1,
'exclude' => '',
'include' => '',
'link_after' => '',
'link_before' => '',
'post_type' => 'page',
'post_status' => 'publish',
'show_date' => '',
'sort_column' => 'menu_order, post_title',
'title_li' => __('Pages'),
'walker' => ''
);
wp_list_pages( $args );
?>
http://codex.wordpress.org/Function_Reference/wp_list_pages
The important part of your question is sort_column. This example shows sorting (sort_column) as menu_order which will take the WP page order from the backend and sort them by that value. Editing this order is easy with plugins such as the Simple Page Ordering one.

Resources