Tagged: page post wordpress attitudepro
- This topic has 5 replies, 2 voices, and was last updated 9 years, 3 months ago by Theme Horse Support Team.
-
AuthorPosts
-
August 11, 2015 at 2:31 am #27147craig.haydonParticipant
Hi Guys,
We are using the Attitude Pro theme and were wondering if its possible to setup a “page” (lets call it page-lifestyle.php) that lists only posts from a specific category?
Essentially the page would like identical to the home page except the posts are filtered.Example:
http://www.mysite.com/interiors (list posts with category “interiors”)
http://www.mysite.com/design (list posts with category “design”)
http://www.mysite.com/lifestyle (list posts with category “lifestyle”)Is this doable? If so.. how would one go about setting up?
August 11, 2015 at 5:46 am #27154Theme Horse Support TeamKeymasterHi craig.haydon,
We cannot provide any support on the custom file that you have created. You need to hire a developer to fix it.
Thank you!
August 11, 2015 at 5:49 am #27155craig.haydonParticipantHi Theme Horse Support Team.
I haven’t created a custom file, i am wanting to work within the bounds of the theme.
ThanksAugust 11, 2015 at 6:18 am #27156Theme Horse Support TeamKeymasterHi craig.haydon,
<?php $args = array( 'posts_per_page' => 5, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true ); $posts_array = get_posts( $args ); ?>
You can use the above code and add the category name in
'category' => ''
View this link https://codex.wordpress.org/Template_Tags/get_posts
If you want to show different page with different category then you can create a template and then customize the code. Create a template and customize the code.
First of all create a child theme and then customize the code. Otherwise your customized code will be lost while updating to new version.
It needs lots of coding so you need to hire a developer. If you are good at coding then you can customize the code too.
Thank you!
August 14, 2015 at 1:19 am #27279craig.haydonParticipantHi TH,
Unfortunately the get_posts (from above) didn’t work. (or at least i wasn’t able to get to work).
This is what i did to fix my question, and perhaps it will help other newbies like me.
1) created a new page template. (copy page.php and rename to page-template-page-blog.php)
2) added text (line 3) to the above new file (so its shows in WP admin). “* Template Name: Page with blog posts(cat=slug)”. You really can call it anything. The text that you enter here is what shows in WP admin (dashboard) in the page -> template (dropdown)
3) changed description to ‘* Displays posts in page based on slug’. This isn’t really necessary… but will help to remind you later what it does 🙂
4) modified content-extensions.php (its under library > structure) function attitude_theloop(){, so it now looks like this:function attitude_theloop() { global $post; if( is_page() ) { if( is_page_template( 'page-template-blog-image-large.php' ) ) { attitude_theloop_for_template_blog_image_large(); } elseif( is_page_template( 'page-template-blog-image-medium.php' ) ) { attitude_theloop_for_template_blog_image_medium(); } elseif( is_page_template( 'page-template-blog-full-content.php' ) ) { attitude_theloop_for_template_blog_full_content(); } elseif( is_page_template( 'page-template-page-blog.php' ) ) { $categ = $post->post_name; query_posts( "category_name=$categ&posts_per_page=10" ); attitude_theloop_for_archive(); } else { attitude_theloop_for_page(); } } elseif( is_single() ) { attitude_theloop_for_single(); } elseif( is_search() ) { attitude_theloop_for_search(); } else { attitude_theloop_for_archive(); } }
5) back in wp-admin, go to the page you want to change, and change its template to ‘Page with blog posts(cat=slug)’.
There’s probable an even easier or better way to do this, but this is what worked for me… 🙂
Enjoy
August 14, 2015 at 7:05 am #27298Theme Horse Support TeamKeymasterThanks for sharing with us craig.haydon
Thank you!
-
AuthorPosts
- You must be logged in to reply to this topic.