SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict martinfamily2005's Avatar
    Join Date
    Jul 2010
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I show only posts from ONE SINGLE category

    I have tried the query_posts method, using the category ID and the category name, but I can not get this to work.

    If you go to my page, you will see a slideshow at the bottom, in the footer, that pulls ALL posts on the site, but I need it to only display posts from one category, "reviews". This slideshow is under the "Begin reviews" section in the code. I have attached the footer.php below.
    FYI: This is the Mensa theme

    I tried to use the category id, which is 7, but nothing. I tried to change the"featured1" to "reviews", and I even used

    query_posts('category_name=reviews');

    But it is not showing any posts. It works fine with no values in there at all, it just pulls all posts from all categories, which is not what I want. I need this to only display ONE category's posts.

    Here is the settings.php file from the theme. I think maybe some changes in here might work, but i don't want to make them without some guidance. Also, i do not want to change the way the main slideshow in the header works....it pulls from all categories. I only want to change the one in the footer to pull from a single category (ID=7, name=reviews). Thanks.

    footer.php
    Code:
    <div class="break"></div>
    
    	</div>
    	<!-- END body -->
    
    </div>
    <!-- END wrapper -->
    </div>
    <!-- BEGIN bottom -->
    <div id="footer">
    
    <!-- BEGIN wrapper -->
    <div class="wrapper">
    
    <div align="center">
    <img src="<?php bloginfo('template_url'); ?>/assets/images/partners.png" alt="PLEASE VISIT OUR PARTNERS"/></div>
    
    	<!-- BEGIN top -->
    	<div id="top">
    
    		<div class="box">
    			<div class="name">
    				<a href="#"><img align="center" alt="top" src="<?php bloginfo('template_url'); ?>/assets/images/comingsoon.png"/></a>
    				<a class="title">Partner #1</a> <br/>
    				<a class="title2">Coming Soon</a>
    			</div>
    			<div class="text2">
    				<p>This is where the partner synopsys will be located for this partner when completed.</p>
    				<a href="#" class="more">Read More >></a>
    			</div>
    			<div class="break"></div>
    		</div>
    		<div class="box">
    			<div class="name">
    				<a href="#"><img alt="top" src="<?php bloginfo('template_url'); ?>/assets/images/comingsoon.png"/></a>
    				<a class="title">Partner #2</a> <br/>
    				<a class="title2">Coming Soon</a>
    			</div>
    			<div class="text2">
    				<p>This is where the partner synopsys will be located for this partner when completed.</p>
    				<a href="#" class="more">Read More >></a>
    			</div>
    			<div class="break"></div>
    		</div>
    		<div class="box">
    			<div class="name">
    				<a href="#"><img alt="top" src="<?php bloginfo('template_url'); ?>/assets/images/comingsoon.png"/></a>
    				<a class="title">Partner #3</a> <br/>
    				<a class="title2">Coming Soon</a>
    			</div>
    			<div class="text2">
    				<p>This is where the partner synopsys will be located for this partner when completed.</p>
    				<a href="#" class="more">Read More >></a>
    			</div>
    			<div class="break"></div>
    		</div>
    
    	</div>
    	<!-- END top -->
    
    </div>
    <!-- END wrapper -->
    
    <!-- BEGIN wrapper -->
    <div class="wrapper">
    
    	<!-- BEGIN reviews -->
    	<div id="reviews">
    
    		<a class="prev" href="#"><img class="l" alt="featured title" src="<?php bloginfo('template_url'); ?>/assets/images/left.gif"/></a>
    
    		<div class="items">
    
    			<?php
    			$tmp_query = $wp_query;
    			query_posts('cat=' . get_cat_ID(dp_settings('featured1')));
    			if (have_posts()) :
    			while (have_posts()) : the_post();
    			?>
    
    			<div class="feat">
    				<a class="featuredimg" href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'full', 'alt="' . $post->post_title . '"'); ?></a>
    				<div class="text">
    					<h2><a href="<?php the_permalink(); ?>"><a>Review: </a><?php the_title(); ?></a></h2>
    					<?php  the_excerpt(); ?>
    				</div>
    				<div class="break"></div>
    			</div>
    
    			<?php
    			endwhile;
    			endif;
    			$wp_query = $tmp_query;
    			?>
    
    		</div>
    
    		<a class="next" href="#"><img class="r" alt="featured title" src="<?php bloginfo('template_url'); ?>/assets/images/right.gif"/></a>
    
    	</div>
    	<!-- END reviews -->
    
    </div>
    <!-- END wrapper -->
    
    <!-- BEGIN wrapper -->
    <div class="wrapper">	
    
    <p id="info">&#169; 2010 The Billboard Family<br />All Rights Reserved
    <br /><br />
    
     	→ <a href="/?page_id=94">Submit A Review</a><br />
    					 	→ <a href="/?page_id=118">Terms & Conditions</a><br />
    
    					 	→ <a href="/?page_id=47">Partners</a><br />
    					 	→  <a href="/?page_id=31">Contact Us</a></p> 
    
    </div>
    
    	<!-- END wrapper -->
    
    <!-- END bottom -->
    
    </body>
    
    </html>
    settings.php
    Code:
    <?php
    
    $themename = "Personal Memo";
    $shortname = "personalmemo";
    
    $settings = array(
    
    	'featured1' => 'Featured',
    
    	'about'=>'Hi! My name is Paul and I am a Designer and Blogger from Brisbane. This is my creative outlet. <a href="#">more &#187;</a>',
    	'facebook'=>'',
    	'youtube' => 'H5h95s0OuEg',
    
    	'mail_url'=>'http://wpcorner.com/contact/',
    	'rss_url'=>'http://wpcorner.com/rss/',
    	'twitter_url'=>'http://www.twitter.com/',
    	'facebook_url'=>'http://www.facebook.com/',
    	'stumbleupon_url'=>'http://www.stumbleupon.com/',
    	'twitter'=>'<ul>
    	<li>
    		What is your Religion and is it making you a better person?
    		<p><a href="#">2 days ago</a></p>
    	</li>
    	<li>
    		What is your Religion and is it making you a better person?
    		<p><a href="#">2 days ago</a></p>
    	</li>
    	<li>
    		What is your Religion and is it making you a better person?
    		<p><a href="#">2 days ago</a></p>
    	</li>
    	</ul>'
    
    );
    
    # Settings
    
    function s_lang($text) {
    	return $text;
    };
    
    $options = array (
    
    	array(	"name" => s_lang("Featured Content Settings"),
    			"type" => "header"
    	),
    
    	array(  "name" => s_lang("Featured Category Name"),
                "id" => $shortname."_featured1",
                "std" => $settings['featured1'],
                "type" => "text"),
    
        array(	"name" => s_lang("Left Sidebar Settings"),
    			"type" => "header"
    	),
    
        array(  "name" => s_lang("About Me"),
                "id" => $shortname."_about",
                "std" => $settings['about'],
                "type" => "textarea"),
    
         array(  "name" => s_lang("Facebook Widget Code"),
                "id" => $shortname."_facebook",
                "std" => $settings['facebook'],
                "type" => "textarea"),
    
        array(  "name" => s_lang("Featured Video (Youtube Video ID)"),
                "id" => $shortname."_youtube",
                "std" => $settings['youtube'],
                "type" => "text"),
    
        array(	"name" => s_lang("Right Sidebar Settings"),
    			"type" => "header"
    	),
    
    	array(  "name" => s_lang("Mail URL"),
                "id" => $shortname."_mail_url",
                "std" => $settings['mail_url'],
                "type" => "text"),
    
        array(  "name" => s_lang("RSS URL"),
                "id" => $shortname."_rss_url",
                "std" => $settings['rss_url'],
                "type" => "text"),
    
        array(  "name" => s_lang("Twitter URL"),
                "id" => $shortname."_twitter_url",
                "std" => $settings['twitter_url'],
                "type" => "text"),
    
        array(  "name" => s_lang("Facebook URL"),
                "id" => $shortname."_facebook_url",
                "std" => $settings['facebook_url'],
                "type" => "text"),
    
        array(  "name" => s_lang("StumbleUpon URL"),
                "id" => $shortname."stumbleupon_url",
                "std" => $settings['stumbleupon_url'],
                "type" => "text"),
    
        array(  "name" => s_lang("Twitter Widget Code"),
                "id" => $shortname."_twitter",
                "std" => $settings['twitter'],
                "type" => "textarea"),
    
    );
    
    function mytheme_add_admin() {
        global $themename, $shortname, $options;
        if ( $_GET['page'] == basename(__FILE__) ) {
    		if ( 'save' == $_REQUEST['action'] ) {
    			foreach ($options as $value) if ($value['type']!='header') update_option( $value['id'], $_REQUEST[ $value['id'] ] );
    			foreach ($options as $value) {
    			if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    			header("Location: themes.php?page=settings.php&saved=true");
    			die;
    		} else if( 'reset' == $_REQUEST['action'] ) {
    			foreach ($options as $value) delete_option( $value['id'] );
    			header("Location: themes.php?page=settings.php&reset=true");
    			die;
    		}
        }
    	add_theme_page($themename." Settings", "Theme Settings", 'edit_themes', basename(__FILE__), 'mytheme_admin');
    }
    
    function mytheme_admin() {
    
        global $themename, $shortname, $options;
    
        if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
        if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
    ?>
    <style type="text/css">
    th {
    	text-align: left;
    }
    td {
    	padding: 1px 5px !important;
    }
    .header td {
    	padding: 20px 0 10px !important;
    }
    .header td p {
    	padding: 4px 5px !important;
    	font-size: 12px !important;
    	font-weight: bold !important;
    	background-color: #073447 !important;
    	color: #ffffff;
    	margin: 0 !important;
    }
    .submit {
    	padding-top: 40px;
    }
    </style>
    <div class="wrap">
    <h2><?php echo $themename; ?> Settings</h2>
    
    <form method="post">
    
    <table class="form-table">
    
    <?php foreach ($options as $value) { 
    
    if ($value['type'] == "text") { ?>
    
    	<tr>
    	<th scope="row" style="width: 30&#37;"><?php echo $value['name']; ?>:</th>
    	<td>
    	<input style="width: 50%" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" />
    	  <?php echo $value['note']; ?>
    	</td>
    	</tr>
    
    <?php } elseif ($value['type'] == "textarea") { ?>
    
    	<tr>
    	<th scope="row" style="width: 30%"><?php echo $value['name']; ?>:</th>
    	<td>
    	<textarea style="width: 80%; height: 70px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php if ( get_settings( $value['id'] ) != "") { echo htmlentities(stripslashes(get_settings( $value['id'] ))); } else { echo stripslashes($value['std']); } ?></textarea>
    	  <?php echo $value['note']; ?>
    	</td>
    	</tr>
    
    <?php } elseif ($value['type'] == "select") { ?>
    
        <tr>
    	<th scope="row"><?php echo $value['name']; ?>:</th>
    	<td>
    	<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
    	<?php foreach ($value['options'] as $option) { ?>
    	<option value="<?php echo $option; ?>" <?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
    	<?php } ?>
    	</select>
    	    <?php echo $value['note']; ?>
    	</td>
        </tr>
    
    <?php
    } elseif ($value['type'] == "header") {?>
    
    	<tr class="header"><td colspan="2"><p><?php  echo $value['name'] ?></p></td></tr>
    
    <?php
    }
    }
    ?>
    
    </table>
    
    <p class="submit">
    <input name="save" type="submit" value="Save changes" />
    <input type="hidden" name="action" value="save" />
    </p>
    </form>
    <form method="post">
    <p class="submit" style="border: 0;">
    <!-- <input name="reset" type="submit" value="Reset" /> -->
    <input type="hidden" name="action" value="reset" />
    </p>
    </form>
    
    <?php
    }
    
    add_action('admin_menu', 'mytheme_add_admin');
    
    foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
    
    # Set Values
    foreach ($settings as $k=>$v) {
    	$var = $shortname.'_'.$k;
    	if (!empty($$var)) $settings[$k] = stripslashes($$var);
    }
    
    ?>

  2. #2
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haven't read everything since I'm about to go to bed right now, but I suppose you're looking for get_posts rather than query_posts, more info here:

    http://codex.wordpress.org/Function_Reference/get_posts
    Dan G
    Marketing Strategist & Consultant

  3. #3
    SitePoint Addict martinfamily2005's Avatar
    Join Date
    Jul 2010
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c2uk View Post
    haven't read everything since I'm about to go to bed right now, but I suppose you're looking for get_posts rather than query_posts, more info here:

    http://codex.wordpress.org/Function_Reference/get_posts
    I have actually tried that as well. It seems to me that the way the theme is setup is causing this not to work. I have tried all the known tricks, etc that I could find, but I can not get this to do what I need it to do. I am open to any suggestions at this point.

  4. #4
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by martinfamily2005 View Post
    I have actually tried that as well. It seems to me that the way the theme is setup is causing this not to work. I have tried all the known tricks, etc that I could find, but I can not get this to do what I need it to do. I am open to any suggestions at this point.
    it should work regardless of how the theme is set up. if you could single out the part where you tried this one, I can help.
    Dan G
    Marketing Strategist & Consultant

  5. #5
    SitePoint Addict martinfamily2005's Avatar
    Join Date
    Jul 2010
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c2uk View Post
    it should work regardless of how the theme is set up. if you could single out the part where you tried this one, I can help.
    It has been a while since I did that, to be honest. Trying to recreate what I did before will be pretty tricky. Grrrr. This is racking my brain...it should be pretty easy. Additionally, the link you gave me does show the get_posts tag but does not show how to pull posts from only a single category.

  6. #6
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, it does, the very first example shows how to do this with the category id.
    Dan G
    Marketing Strategist & Consultant

  7. #7
    SitePoint Addict martinfamily2005's Avatar
    Join Date
    Jul 2010
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That shows one post, and a list of other posts, with an offset. That seems like more than I am looking for. IDK. I need a break from this site for a little while. My brain hurts.

  8. #8
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure, but it shows you how to select a single category, which is what you asked. now, all you need to do is look for the arguments that can be passed in this function and adjust them according to your specific needs.

    if that's too much for you, you're better off hiring a Wordpress developer, note I'm not one as should be clear from my signature.
    Dan G
    Marketing Strategist & Consultant

  9. #9
    SitePoint Addict martinfamily2005's Avatar
    Join Date
    Jul 2010
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, got it resolved.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •