Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A Random Quote in the Sidebar
- If you're keen on literature or religious, you might want to have some of your favorite quotes in the sidebar—it's not a waste of space if you use the area with purpose. So, if you're going to list a random quote in your sidebar on each page view, you can use the following code snippet to create the post type and use the following query to create a loop in your sidebar:
- <?php
- /*
- * Create new post type called "Quotes"
- * (refer to the `register_post_type` function to
- * learn more about creating custom post types).
- */
- function quote_post_type() {
- $args = array(
- 'label' => 'Quotes',
- 'public' => true
- );
- register_post_type( 'quotes', $args );
- }
- add_action( 'init', 'quote_post_type' );
- // Setup arguments.
- $args = array(
- // Get the "quotes" psot type.
- 'post_type' => 'quotes',
- // Randomize the order.
- 'orderby' => 'rand',
- // Get only one item.
- 'posts_per_page' => 1,
- );
- // Instantiate new query instance.
- $my_query = new WP_Query( $args );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement