Chun
Chun

Reputation: 2270

Creating Wordpress Slider Post Filter Options

I'm creating a slider for my Wordpress theme and I want to create some options on the admin interface to filter posts by category, tag, random or most recent. I'm also developing a theme's options page based on a tutorial as well and to call these options I'm using: <?php echo get_option('category_name'); ?>. So now what I'm trying to do with this code I just referred is to create some filter options in order to change the posts displayed on the Slider on the Admin interface. Here's the relevant code to show posts on the slider:

<?php
$carouselPosts = new WP_Query();
$carouselPosts->query('showposts=12');
?>
<?php while ($carouselPosts->have_posts()) : $carouselPosts->the_post(); ?>

And here's how I'm creating the theme admin options page:

<p><strong>Display by category, write the category name:</strong><br />
    <input type="text" name="category_name" size="45" value="<?php echo get_option('category_name'); ?>" />
</p>

Now, I don't know much of php, I really don't and I know that this isn't the right way to do it, but what I'm trying to do is create something like this:

$carouselPosts->query('category_name=<?php echo get_option('category_name'); ?>&showposts=12');

As I said I know this is not the right way to do it, but it is the easier way to explain what I'm trying to accomplish here. Here's the link of the slider tutorial if it is helpful: Tutorial Link

Upvotes: 1

Views: 266

Answers (1)

user488187
user488187

Reputation:

Actually, it's pretty close. Use:

$carouselPosts->query('category_name=' . get_option('category_name') . '&showposts=12');

You use <?php ?> only when you are trying to insert PHP into HTML. Otherwise, you can just use the PHP as-is.

Upvotes: 2

Related Questions