ThemeForest

Calling theme option for query_posts

47 posts
  • Has been a member for 2-3 years
  • Bought between 1 and 9 items
virgild says

I’ve been working with custom theme options but now I’m trying custom menu pages.

I managed to create options for basic things like footer content and ad boxes but I can’t figure out how to call a specific category id in a query post.

With standard options I would use

<?php query_posts("cat=<?php echo $theme_category;?>"); ?> <?php while (have_posts()) : the_post(); ?> <?php the_post_thumbnail( 'frontpage' ); ?> <?php endwhile ?>

but when I try that with an option from a custom menu page it doesn’t work.. I’m hoping someone can help me figure this out. I’ll REALLY appreciate it!!

2 years ago
685 posts
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Uruguay
  • Referred between 1 and 9 users
_rg_ says

Are you sure that code works?

You have a <?php inside another <?php… that couldnĀ“t work, must return a php error for sure…

Anyway, for get a particular cat using the $theme_category; var, you can do this:

<?php query_posts('cat='.$theme_category.''); if ( have_posts() ) : while ( have_posts() ) : the_post(); .. endwhile; else: .. endif; wp_reset_query(); // dont“forget to reset the query!!! ?>

And of course, you can use category slug spite of ID, using:

“category_name” spite “cat”

Take a look here:

http://codex.wordpress.org/Template_Tags/query_posts

2 years ago
47 posts
  • Has been a member for 2-3 years
  • Bought between 1 and 9 items
virgild says

Thanks for sharing Arriba. I tried the code but it doesn’t seem to work. It just displays all the blog posts. Maybe I’m doing something else wrong.. but how strange.. because it works when I call a regular theme option.

The code I posted above works because I used double quotes. It’s a neat trick :)

This is the code I wrote using your technique. I belive it’s right.


<?php query_posts('cat='.$theme_category.'');

if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<?php the_post_thumbnail( 'home' ); ?>

<?php endwhile; else: ?>

  <p><strong>...</strong>

 <?php endif; ?>

<?php wp_reset_query(); ?>

</p>
2 years ago
685 posts
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Uruguay
  • Referred between 1 and 9 users
_rg_ says

where comes from the var?:

$theme_category;

you already use for example something like this:

$theme_category = get_option(‘option_name’);

or not?

2 years ago
47 posts
  • Has been a member for 2-3 years
  • Bought between 1 and 9 items
virgild says

Thank you Arriba, it’s finally working :-)

For anyone else experiencing this issue, the code I used is..

<?php query_posts('cat='.$theme_category = get_option('category').'');

if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

....

<?php endwhile; else: ?>

....

 <?php endif; ?>

<?php wp_reset_query(); ?>
2 years ago
by
by
by
by
by