Skip to content

Instantly share code, notes, and snippets.

@ahmedkaludi
Forked from khaledMohammed000/index.php
Created February 1, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedkaludi/b61d24fb7693c7d9453801c9c6ee7f69 to your computer and use it in GitHub Desktop.
Save ahmedkaludi/b61d24fb7693c7d9453801c9c6ee7f69 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;
//Use Case 1: Exclude Specific Categories from Homepage
/* 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: Show posts from different Post types
function ampforwp_return_loop_args(){
// learn more to Modify args @ https://developer.wordpress.org/reference/classes/wp_query/
//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