Hi, i'm in desperate need of some help here. I have an options page where i can type in a category as seen in the screenshot http://i33.tinypic.com/rhiqkm.png and I want this category to be echoed where it says "$my_new_category" . And if I don't type in a category in the options page, i want it to use a default category, so I setup an else statement. I'm getting Parse error: syntax error, unexpected $end. When I take out the else statement I don't get that error but the new category that i type in doesn't get echoed. Any help would be appreciated! <? /* This code retrieves all our admin options. */ global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } ?> <? if ($my_new_category) { ?> <?php if (have_posts()) : $my_query = new WP_Query('category_name=<? echo $my_new_category; ?>&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <? } else { ?> <?php if (have_posts()) : $my_query = new WP_Query('category_name=<? echo $my_new_category; ?>&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <? } ?> PHP:
Not entirely sure what you were trying to do, but try this <?php if (have_posts()) { $my_query = new WP_Query('category_name='.$my_new_category.'&showposts=2'); if ($my_new_category) { while ($my_query->have_posts()) { $my_query->the_post(); } } } ?> PHP:
Thank for the help Jay. So this is how i got it setup now <? if ($my_new_category) { ?> <?php if (have_posts()) { $my_query = new WP_Query('category_name='.$my_new_category.'&showposts=2'); if ($my_new_category) { while ($my_query->have_posts()) { $my_query->the_post(); } } } ?> <? } else { ?> <?php if (have_posts()) : $my_query = new WP_Query('category_name=<? echo $my_new_category; ?>&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <? } ?> PHP: Now with that code i'm not receiving any errors but when i type in a category in the options menu it doesn't reflect. Instead it shows the default category. Any ideas as to why?
I am also using this code to retrive the data from the admin options <? /* This code retrieves all our admin options. */ global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } ?> PHP:
Just so you guys have a better understanding, here is what I'm trying to do. this is the wordpress code that was given <?php if (have_posts()) : $my_query = new WP_Query('category_name=category1&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> PHP: What I want is to have the category name change when i change it in the options panel. So i was thinking of doing something like this <?php if (have_posts()) : $my_query = new WP_Query('category_name=<? echo $my_new_category; ?>&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> PHP: And if i decided not to input a category i wanted there to be a default category so i was thinking of setting it up like this.. <? } else { ?> <?php if (have_posts()) : $my_query = new WP_Query('category_name=default&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> PHP: hope this clarifies things a bit
I set it up using the 'if' statement only to see if that would atleast work because i don't know how to setup the else statement. I'm not getting any errors but the category i typed in the options panel doesn't show up. Here is the full code <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <!--[if IE]> <link href="<?php bloginfo('template_url'); ?>/iehacks.css" rel="stylesheet" type="text/css" /> <![endif]--> </head> <body> <!---------- Begin Header ----------> <?php get_header(); ?> <!---------- End Header ----------> <!---------- Begin Main ----------> <div id="main"> <div id="header-divider-line"> </div> <div id="title"><?php bloginfo(’name’); ?> </div> <div id="main-photo"><?php include (ABSPATH . '/wp-content/plugins/content-slide/slideshow.php'); ?> </div> <div id="main-photo-bottom"> <div id="portfolio-button"><a href="#"><img src="wp-content/themes/wordpress1/images/portfolio-button.gif" border="0"></a> </div> </div> </div> <!---------- End Main ----------> <!---------- Begin Content/Posts ----------> <div id="content"> <div id="content-top"> <div id="content-header"> </div> <div id="content-tab"> <div id="content-tab-title">Moments </div> </div> </div> <div id="content-post-container"> <!---------- Begin Posts ----------> <? /* This code retrieves all our admin options. */ global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } ?> <div id="single-post-container"> <? /* If a title has been provided, we'll use that. */ if ($my_new_category) { ?> <?php if (have_posts()) : $my_query = new WP_Query('category_name='.$my_new_category.'&showposts=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="post-thumbnail"><?php $postimageurl = get_post_meta($post->ID, 'image', true); if ($postimageurl) { ?> <div class="postimage"><a href="<?php the_permalink(); ?>"><img src="<?php echo $postimageurl; ?>" alt="" width="138" height="138" class="thumb" /></a></div> <?php } ?> </div> <div class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </div> <br /><br /> <div class="post-description"><?php content('20'); ?> </div> <div class="post-data"> <?php the_time('l, F jS, Y') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?> </div> <div class="clear"></div> <?php endwhile; ?> <?php endif; ?> </div> <div class="clear"></div> <!---------- End Posts ----------> </div> </div> <!---------- End Content/Posts ----------> <!---------- Begin Footer ----------> <?php get_footer(); ?> <!---------- End Footer ----------> </body> </html> PHP: