WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Random Post Link] Add specific Category

[Plugin: Random Post Link] Add specific Category

  • Hi,

    I would love to be able to limit the results to a specific category. Is this possible with this plug in?

    Thank you in advance!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sure. Just add this to your theme’s functions.php:

    function my_random_post_args($args) {
        $args['category_name'] = 'my-category-slug';
    
        return $args;
    }
    add_filter('random_post_args', 'my_random_post_args');

    Of course, replace 'my-category-slug' with your category slug.

    hey,

    any chance of specifying the category for each random link? basically i have ‘music’ and ‘videos’ as categories and it would be great if i could have a separate random post link for each cat :/

    @scribu I tried posting in the code into the functions.php. However, it ended up disabling my blog b/c it caused an error in the functions file. Do you replace the “my-category-slug” only? Or do you change anything else? I think I may be implementing this code incorrectly in my functions.php file.

    this is my code:

    <?php
    if ( 
    
    function_exists('register_sidebar') ) {
        register_sidebar(array(
    		'name' => 'Wide Sidebar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Left Sidebar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Right Sidebar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Left Footbar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Mid Footbar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Right Footbar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Random Post Link] Add specific Category’ is closed to new replies.