Skip to content

Commit

Permalink
Cleaned the code that was messed up after @khaledMohammed000 's commit
Browse files Browse the repository at this point in the history
…718fd09

Cleaned the code that was messed up after @khaledMohammed000 's commit
718fd09
  • Loading branch information
ahmedkaludi committed Dec 15, 2016
1 parent 065bef9 commit 9dcc9f0
Showing 1 changed file with 67 additions and 109 deletions.
176 changes: 67 additions & 109 deletions templates/design-manager/design-2/index.php
Original file line number Diff line number Diff line change
@@ -1,117 +1,75 @@
<?php global $redux_builder_amp; ?>
<!doctype html>
<html amp>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<?php do_action( 'amp_post_template_head', $this ); ?>

<style amp-custom>
<?php $this->load_parts( array( 'style' ) ); ?>
<?php do_action( 'amp_post_template_css', $this ); ?>
</style>
</head>
<body class="amp_home_body">
<?php $this->load_parts( array( 'header-bar' ) ); ?>

<?php do_action( 'ampforwp_after_header', $this ); ?>

<main>
<!--Loop 1-->
<!--Get all the posts here-->
<?php
$args = array( 'post_type' =>'post',
'posts_per_page' => 20);
$our_required_post_ids = array();
$query_posts_before = new WP_Query($args);

if ( $query_posts_before->have_posts() ) : while ( $query_posts_before->have_posts() ) : $query_posts_before->the_post(); ?>

<?php array_push($our_required_post_ids,get_the_ID()) ;?>

<?php endwhile; wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

<!--FIltering them here-->
<?php
$i=0;
while($i<20){
$ID = $our_required_post_ids[$i];
$value = get_post_meta($ID);

if($value['ampforwp-amp-on-off'][0] === 'hide-amp'){
unset($our_required_post_ids[$i]);
}
$i++;
}
?>
<!--Filter Posts IDs here Ends-->

<!--loop 2-->
<!--Filter Posts from Query Starts here-->
<?php $args = array( 'post_type' =>'post',
'posts_per_page' => 20);
$query_posts = new WP_Query($args);
$count = 0;
if($query_posts->have_posts()) : while($query_posts->have_posts()) : $query_posts->the_post();?>

<!--Main Business Logic lies here-->
<?php if(in_array(get_the_ID(),$our_required_post_ids) && $count < 10) { $count++;?>
<?php $ampforwp_amp_post_url = trailingslashit( get_permalink() ) . AMP_QUERY_VAR ;

?>

<div class="amp-wp-content amp-loop-list">
<?php if ( has_post_thumbnail() ) {
?>
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
$thumb_url = $thumb_url_array[0];
?>
<div class="home-post_image"><a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"><amp-img src=<?php echo $thumb_url ?> width=100 height=75></amp-img></a></div>
<?php } ?>

<div class="amp-wp-post-content">

<h2 class="amp-wp-title"> <a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"> <?php the_title(); ?></a></h2>

<?php

if(has_excerpt()){
$content = get_the_excerpt();
}else{
$content = get_the_content();
}
?>
<p><?php echo wp_trim_words( $content , '15' ); ?></p>

</div>
</div>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<?php do_action( 'amp_post_template_head', $this ); ?>

<?php } ?>
<!--Main Business Logic Ends here-->
<?php endwhile; wp_reset_postdata(); ?>
<!--Filter Posts from Query Starts here-->

<!--Finally adding pagination links here-->
<div class="amp-wp-content pagination-holder">
<div id="pagination">
<div class="next"><?php next_posts_link( $redux_builder_amp['amp-translator-next-text'] . ' &raquo;', 0 ) ?></div>
<div class="prev"><?php previous_posts_link( '&laquo; '. $redux_builder_amp['amp-translator-previous-text'] ); ?></div>
<div class="clearfix"></div>
</div>
</div>
<?php endif; ?>
<!--Finally adding pagination links Ends here-->
<!--loop 2 Ends here-->
</main>
<style amp-custom>
<?php $this->load_parts( array( 'style' ) ); ?>
<?php do_action( 'amp_post_template_css', $this ); ?>
</style>
</head>
<body class="amp_home_body">
<?php $this->load_parts( array( 'header-bar' ) ); ?>

<?php do_action( 'ampforwp_after_header', $this ); ?>

<main>

<?php if ( have_posts() ) :
while ( have_posts() ) : the_post();

$ampforwp_amp_post_url = trailingslashit( get_permalink() ) . AMP_QUERY_VAR ;

?>

<div class="amp-wp-content amp-loop-list">
<?php if ( has_post_thumbnail() ) { ?>
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
$thumb_url = $thumb_url_array[0];
?>
<div class="home-post_image"><a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"><amp-img src=<?php echo $thumb_url ?> width=100 height=75></amp-img></a></div>
<?php } ?>

<div class="amp-wp-post-content">

<h2 class="amp-wp-title"> <a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"> <?php the_title(); ?></a></h2>

<?php $this->load_parts( array( 'footer' ) ); ?>
<?php do_action( 'amp_post_template_footer', $this ); ?>
<?php

if(has_excerpt()){
$content = the_excerpt();
}else{
$content = get_the_content();
}
?>
<p><?php echo wp_trim_words( $content , '15' ); ?></p>

</div>
<div class="cb"></div>
</div>

<?php endwhile; ?>


<div class="amp-wp-content pagination-holder">

<div id="pagination">
<div class="next"><?php next_posts_link( $redux_builder_amp['amp-translator-next-text'] . ' &raquo;', 0 ) ?></div>
<div class="prev"><?php previous_posts_link( '&laquo; '. $redux_builder_amp['amp-translator-previous-text'] ); ?></div>

<div class="clearfix"></div>
</div>
</div>

<?php endif; ?>
</main>
<?php $this->load_parts( array( 'footer' ) ); ?>
<?php do_action( 'amp_post_template_footer', $this ); ?>
</body>

</body>
</html>

0 comments on commit 9dcc9f0

Please sign in to comment.