Skip to content

Instantly share code, notes, and snippets.

@khaledMohammed000
Created February 1, 2017 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save khaledMohammed000/2dfa3e72ad8ecacc2e49c84274d0d023 to your computer and use it in GitHub Desktop.
Save khaledMohammed000/2dfa3e72ad8ecacc2e49c84274d0d023 to your computer and use it in GitHub Desktop.
Final code for Home page modification
<?php
/*
Plugin Name: AMP Home Page Modify
Version: 0.0.1
Author: Mohammed Khaled
Author URI: https://ampforwp.com/
Donate link: https://www.paypal.me/Kaludi/5
License: GPL2
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
//Example Use Case: excluding certain posts from certain categories
/* remove this line to use Use case 1
$q = array(
'post_type' => 'post',
'orderby' => 'date',
'ignore_sticky_posts' => 1,
//just replace -1,-7,-15 with appropriate ID of the categories
//you want to exclude and add a "-" before each and separate with comma
'cat' => '-1,-7,-15',
);
*/ // remove this line to use Example Use Case
//cut code from here and replace below inside funtion ampforwp_return_loop_args() between line 29-33
//Use Case 2: index for certain post type instead of "post" Eg : page
// learn more to Modify args @ https://developer.wordpress.org/reference/classes/wp_query/
function ampforwp_return_loop_args(){
//remove code between these comments and replace with your code here
$q = array(
'post_type' => 'page',
'orderby' => 'date',
'ignore_sticky_posts' => 1,
);
//remove code between these comments and replace with your code here
return $q;
}
function ampforwp_custom_home_output(){
add_filter('ampforwp_query_args', 'ampforwp_return_loop_args');
}
add_action('amp_init','ampforwp_custom_home_output');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment