Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

a php echo inside a loop query? WordPress

  • SOLVED

I'm trying to add a function to my theme options page. I have two loops, one showing all the latest posts, and one in the sidebar, to show only posts from a specific category. My idea was to have the user decide the category by adding its name in the theme options page. To try and make the category changable I've tried this:


<?php query_posts('category_name=<? if ($mmcp_catid) { ?><? echo $mmcp_catid; ?><? } else { ?>News<? } ?>&showposts=10'); ?>


..which is not working. Is it even possible to make this kind of tweak to the query? If so, what I am doing wrong?

Answers (2)

2011-01-13

Utkarsh Kukreti answers:

<?php query_posts('category_name=' . $mmcp_catid ? $mmcp_catid : 'News' . '&showposts=10'); ?>


LeTune comments:

Thanks for the reply dude, but can't seem to get it to work. I'll let you have a shot at it live, before asking Denzel, since you were first :) shoot me an email and I'll send you the login, [email protected]

2011-01-13

Denzel Chia answers:

Hi,

My version,


<php
$cat = $mmcp_catid;
if(empty($cat)){
$cat = 'News';
}
query_posts("category_name=$cat&showposts=10");
?>


Thanks.


Denzel Chia comments:

Sorry,

Typo error, use this.



<?php
$cat = $mmcp_catid;
if(empty($cat)){
$cat = 'News';
}
query_posts("category_name=$cat&showposts=10");
?>



Thanks.