Jump to content
Sign in to follow this  
shmokes

Code to show custom posts on front page breaks feature slider.

Recommended Posts

shmokes

I created a website to review children's iPad apps. At first I wrote everything as posts, but soon realized some important advantages to creating custom post types and taxonomies. So I did that, but now my reviews weren't showing up on my home page stream (because they're not posts anymore, but rather "books", "educationals", and "games"). Anyway, I added some code to functions.php in base (I've copied the code I used to the end of this post), which added my custom post types to the main page stream, but it broke my features slider which now just shows the message: "No feature posts matched this pages criteria" I'm too green with php to know what's wrong. Can anybody look at my code and see what's wrong? Also, in case any Pagelines devs happen across this post, "pages" in the message my features slider is returning, should have an apostrophe in it. Here's the code I added to functions.php: add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'post', 'books', 'educationals', 'games', 'attachment' ) ); return $query; }

Share this post


Link to post
Share on other sites
shmokes

Okay . . . I took a wild guess and it turned out to solve the problem. I added a custom post type called "feature" to the php, and now everything worked out. Well, first I tried 'features', which didn't work, but . . . now it's going. Anyway, now my code looks the same as above except the one line which looks like this: $query->set( 'post_type', array( 'post', 'books', 'educationals', 'games', 'feature', 'attachment' ) ); It seems to be working, so I guess (hope) I did it right. If anyone sees anything wrong, please let me know.

Share this post


Link to post
Share on other sites
shmokes

Ugh . . . I take it back. That fixed the features slider, but it added the features to the main stream below the slider as well. Of course, those items are already in the main stream, so now they are doubled up in the main stream. For example I have a review of the book The Monster at the End of This Book, and it is a custom post type called Books. It appears in the main stream twice, once as a Book, and once as a Feature. And, of course, it shows up in the Features slider as well. You can see what I'm talking about at http://bestkidipadapps.com Any suggestions?

Share this post


Link to post
Share on other sites
Rob

Well, first thing is that Featured Slider, Boxes and other Pagelines drag and drop components are themselves Custom Post Types, so you doubtlessly are creating a series of conflicts. You may just want to reinstall the functions.php and start this process again. How did you create the custom post types? There are plugins that work well with Pagelines themes.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
shmokes

That snippet of code is the only thing custom thing I've added to functions.php, so I could easily pull that out and return it back to its original state. I created the custom post types with the Custom Post Type UI plugin. That seemed to go just fine, except that my custom posts didn't show up on my front page, hence my attempt at customization.

Share this post


Link to post
Share on other sites
Rob

This may or may not help, but you may want to try a plugin called "Custom Press" which I've used with great success.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
shmokes

Can you elaborate on how it might help? As far as I can tell, I have no problem generating custom post types. I just need to make it display on the main page. Does this plugin have a feature that would automate that for me?

Share this post


Link to post
Share on other sites
kastelic

Here's what worked for me.

	//Adds some custom post types to home page loop
	
		add_action('pagelines_inside_top_theloop' ,'enable_hotels');
		function enable_hotels(){
			if (is_home()){
				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //fixes pagination
				$args = array(
					'post_type'=> array( 'post', 'books', 'educationals', 'games'),
					'paged'=> $paged
				);
				query_posts($args);
			}
		}
	
	
	

Share this post


Link to post
Share on other sites
shmokes

Thanks so much. Little by little the tweaks are being worked out and the mechanics of my site are almost complete. I had two breakthroughs today, both with the help of generous strangers contributing their time and knowledge. I'm knocking on wood while I say it, but everything looks to be working properly now with your code in place. Now I need to sit down and spend some time staring at it until I grok everything the code does. Thanks again.

Share this post


Link to post
Share on other sites
shmokes
Kastelic, I have two very quick questions related to this. I am trying to understand the code, so hopefully before long I can begin answering questions more than asking them. First question: I don't understand the 'hotels' part of the code you gave me. At first I thought there must be some hotels function in Pagelines, but based on some code you gave me in another thread (http://www.pagelines.com/forum/discussion/12828/how-to-make-templates-for-custom-post-types#Item_3) I'm now wondering if maybe you named the function 'enable_hotels' out of habit, but maybe it would make more sense if it was called 'enable_cust_post' or something. Go easy on me if I'm way off-base, lol. My second, completely unrelated question is: Where can I learn about post tags for this forum? I'd like to be able to do things like put code in those yellow quote boxes and add formatting to my text to make my posts easier to read. Thanks again for your help.

Share this post


Link to post
Share on other sites
catrina
"enable_hotels" is just an example name to put in there. It can be anything you want, but it has to be the same throughout, which is why "enable_hotels" shows up twice in this snippet of the code: [code]add_action('pagelines_inside_top_theloop' ,'enable_hotels'); function enable_hotels(){[/code] By post tags, are you referring to blocks where code can be placed so that it stands out from other text?

Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites
shmokes
Yes. I am, for example, referring to exactly what you did in your post that put the code in a yellow block. Other tags would be useful too, like to make text bold/italic or for making anchor text rather than putting full URLs in my posts. In short, I'd like to use good manners while posting on this forum.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×