Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom Post Order
Tagged: custom order, customizing home page., post id, Post Order
- This topic has 9 replies, 3 voices, and was last updated 9 years, 2 months ago by Brad Dalton.
-
AuthorPosts
-
June 22, 2015 at 11:58 am #157178James DMember
Hello:
I have a site that I am migrating over to my Genesis Theme; Modern Portfolio Pro.
I am going to include links to the existing site and the migration site that I am working on so that you can see the difference.
The original site is http://theAmericanPresidents.org , and just as you would suspect has a listing of posts based on the each president. I was able to customize the order of the posts, so that the presidents show up in their numeric order 'George Washington first, Barack Obama last.
I am able to do this in the original non-genesis them by using this plug in. 'Simple Custom Post Order'
Unfortunately, this does not seem to work with the Modern Portfolio them and the new version of the site. Perhaps because the posts are controlled by a widget?
The working site 'builder.theAmericanPresidents.org' does not respond that plugin 'Simple Custom Post Order'. I thought perhaps it could be controlled by setting the POST ID for each blog post. But I don't know where to find it.
Basically I am looking for a way to keep all these blog posts on main page using their featured image as a thumbnail, and make it so that order does not change, regardless of whether I update the individual posts.
Thanks
Jim
http://builder.ThAmericanPresidents.orgJune 22, 2015 at 12:41 pm #157181Brad DaltonParticipantJune 22, 2015 at 1:10 pm #157185James DMemberOh boy, that is above my pay grade. I don't know what that means.
Just when I think I am understanding this stuff, I realize that I have no idea how most of this stuff works.
Jim
June 22, 2015 at 1:22 pm #157187Brad DaltonParticipantUsing a code editor, add to the end of your functions file.
function modify_query_order( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', 'modify_query_order' );
June 22, 2015 at 2:31 pm #157204James DMemberuhmm. yeah... I added that code to the very end of my functions.php
function modify_query_order( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'modify_query_order' );and it broke my site.
June 22, 2015 at 2:39 pm #157206James DMemberThis is the last few lines of the php code. By the way, I am really out of my element with php. I can find my way through css without too much problem, but the php stuff loses me.
Here is the code as I pasted it in my file from the * Register Widget Area * on down:
//* Register widget areas
genesis_register_sidebar( array(
'id' => 'home-about',
'name' => __( 'Home - About','mpp' ),
'description' => __( 'This is the about section of the homepage.','mpp' ),
) );
genesis_register_sidebar( array(
'id' => 'home-portfolio',
'name' => __( 'Home - Portfolio','mpp' ),
'description' => __( 'This is the portfolio section of the homepage.','mpp' ),
) );
genesis_register_sidebar( array(
'id' => 'home-services',
'name' => __( 'Home - Services','mpp' ),
'description' => __( 'This is the Services section of the homepage.','mpp' ),
) );
genesis_register_sidebar( array(
'id' => 'home-blog',
'name' => __( 'Home - Blog','mpp' ),
'description' => __( 'This is the Blog section of the homepage.','mpp' ),
) );
function modify_query_order( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'modify_query_order' );
I am getting errors in Dreamweaver on these 3 lines
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
Jim
June 22, 2015 at 5:31 pm #157226coralseaitMemberYou are missing your closing brace on your if block:
this
if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘orderby’, ‘title’ ); $query->set( ‘order’, ‘ASC’ );
should become
if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘orderby’, ‘title’ ); $query->set( ‘order’, ‘ASC’ ); }
Notice the if block closing brace.
Also, very important, but your ticks are wrong if that's exactly what you pasted in. You have to be very careful about the quoting when pasting from websites. You'll get back ticks or wrong tick instead of just ticks (single quote). You'll probably just need to go through and change every bad tick to the correct one (for example around orderby, title, order, ASC
Note, this is a very common problem when pasting code directly from forums / browsers.
June 23, 2015 at 2:11 am #157264Brad DaltonParticipantThe code works. Did you use a code editor or the theme editor to add the code?
June 24, 2015 at 10:29 am #157415James DMemberI guess I was missing a brace.
Someone above says my 'ticks' are wrong. Sorry I don't know what a 'tick' is.
I was editing the code in dreamweaver 2015
jim
June 24, 2015 at 10:36 am #157416Brad DaltonParticipantYou need to use a PHP code editor like Notepad++ for Windows or Text Wrangler for Mac and paste the code into the file using FTP.
-
AuthorPosts
- The topic ‘Custom Post Order’ is closed to new replies.