Wordpress Themes - WP Forum at BFA
Click Here To DONATE! Support the theme development, get more attention and additional benefits based on your donation level. Your forum name will be highlighted.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Center area post/pages »

[SOLVED] Help modifying the loop with several parameters


Build custom WP THEMES, without
coding.
Click here for THEMEFRAME

From the author of Atahualpa, the #1 most
downloaded (700,000+) theme @ wordpress.org
  #1  
Old Jul 22, 2011, 08:52 PM
Tim F
 
66 posts · Jul 2009
Hi all! Sorry to ask this, I guess it's more a PHP question than strictly an atahualpa question but I've been trying to figure it out for a few hours and it is starting to do my nut in!

I have a loop at the top of my page to show only posts from category 3. I am trying to create a second loop underneath this that:

Shows one post only, that post being the latest sticky post if a sticky post exists, otherwise just the most recent post, but excluding category 3.

I am using the following code right at the bottom of 'Content above the loop' and it works perfectly to show one post, sticky if present, but have not yet been able to exclude category 3.

Code:
<?php $args = array(
	'posts_per_page' => 1,
	'post__in'  => get_option( 'sticky_posts' ),
	'ignore_sticky_posts' => 1	
);
if (is_front_page() && !is_paged() ) $posts = query_posts($args); ?>
I have tried

Code:
<?php $args = array(
	'posts_per_page' => 1,
	'post__in'  => get_option( 'sticky_posts' ),
	'ignore_sticky_posts' => 1
	'cat' => -3	
);
if (is_front_page() && !is_paged() ) $posts = query_posts($args); ?>
But this breaks the loop at the top of the page (I get Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in URL/functions.php(575) : eval()'d code on line 45)

and it also stops the second loop from working.

I also tried concatenating 'cat=-3' with $args but got a similar error.

Can anyone see anything wrong with my syntax or method for excluding category 3? Any suggestions greatly appreciated!
  #2  
Old Jul 22, 2011, 09:55 PM
Tim F
 
66 posts · Jul 2009
I should add that this works fine on its own to exclude cat 3 from the main loop:
Code:
<?php if (is_front_page() && !is_paged() ) $posts = query_posts($query_string . '&cat=-3&showposts=1'); ?>
  #3  
Old Jul 23, 2011, 06:29 AM
juggledad's Avatar
juggledad
 
21,702 posts · Mar 2009
OSX 10.8.5 WP 3.8.x Atahualpa 3.7.x Safari 6.x Firefox 25 XP
you are missing a comma after
HTML Code:
ignore_sticky_posts' => 1
because you added an element in the array, so it should be
HTML Code:
<?php $args = array(
	'posts_per_page' => 1,
	'post__in'  => get_option( 'sticky_posts' ),
	'ignore_sticky_posts' => 1,
	'cat' => -3	
);
if (is_front_page() && !is_paged() ) $posts = query_posts($args); ?>
p.s. I can't tell you how many times in my life I stared at a chunk of code only to have someone walk over and say 'don't you want a period there' or 'you need a comma there' ...sigh
__________________
If you like my help, please consider donating. I am happy to provide greater detail on this and other topics if you hire me. Please send detailed support requests to me as a private message, thank you.
Juggledad | Forum Moderator/Support
  #4  
Old Jul 23, 2011, 08:58 AM
Tim F
 
66 posts · Jul 2009
Thanks so much! Can't tell you how frustrating and satisfying it is to solve that so easily

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to Eliminate Previous-Next Box Between Before-Loop and Loop? LaneLester Center area post/pages 0 Nov 10, 2010 09:03 AM
SQL queries for option parameters gejba Atahualpa 3 Wordpress theme 5 Jan 20, 2010 11:58 AM
Modifying Logo area jumbopihu Header configuration & styling 4 Jan 17, 2010 08:52 AM
PHP modifying the underlying code markelshark Atahualpa 3 Wordpress theme 1 Nov 17, 2009 02:41 PM
Modifying the footer of the template seftonview Atahualpa 3 Wordpress theme 1 Feb 9, 2009 05:38 AM


All times are GMT -6. The time now is 11:43 PM.


Powered by vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.