My PHP isn't great!
I have some metaboxes in a wordpress website that displays a column type layout. I can output the metabox content as follows:
<?php
// Group ID
$columns_values = rwmb_meta( 'columns_solutions' );
if ( ! empty( $columns_values ) ) : ?>
<section class="columns">
<?php foreach ( $columns_values as $columns_value ) {
// Grab the image
$columns_imgs = isset( $columns_value['_rtl_column_solutions_image'] ) ? $columns_value['_rtl_column_solutions_image'] : array();
foreach ( $columns_imgs as $columns_img ) {
// Set each image size for the responsive background
$column_image_lg = RWMB_Image_Field::file_info( $columns_img, array( 'size' => 'column-lg' ) );
$column_image_md = RWMB_Image_Field::file_info( $columns_img, array( 'size' => 'column-md' ) );
$column_image_sm = RWMB_Image_Field::file_info( $columns_img, array( 'size' => 'column-sm' ) );
$column_image_xs = RWMB_Image_Field::file_info( $columns_img, array( 'size' => 'column-xs' ) );
}
// Grab the title, oversized text and general text
$column_title = isset( $columns_value['_rtl_columns_title'] ) ? $columns_value['_rtl_columns_title'] : array();
$column_oversized = isset( $columns_value['_rtl_columns_oversized'] ) ? $columns_value['_rtl_columns_oversized'] : array();
$column_general_txt = isset( $columns_value['_rtl_columns_general_text'] ) ? $columns_value['_rtl_columns_general_text'] : array();
?>
<div class="columns-wrapper">
<div class="column">
<?php if(!empty($column_title)) { ?>
<div class="section-title">
<h2>
<?php echo $column_title; ?>
</h2>
</div>
<!-- /.section-title -->
<?php } ?>
<?php if(!empty($column_oversized)) { ?>
<div class="oversized">
<?php echo $column_oversized; ?>
</div>
<!-- /.oversized -->
<?php } ?>
<?php if(!empty($column_general_txt)) { ?>
<?php echo wpautop($column_general_txt); ?>
<?php } ?>
</div>
<!-- /.column -->
<div class="column">
<div class="image min-height cover bg-responsive" style="background-image: url(<?php echo LAZY_IMG; ?>);"
data-lg="<?php echo $column_image_lg['url']; ?>"
data-md="<?php echo $column_image_md['url']; ?>"
data-sm="<?php echo $column_image_sm['url']; ?>"
data-xs="<?php echo $column_image_xs['url']; ?>">
</div>
<!-- /.image -->
</div>
<!-- /.column -->
</div>
<!-- /.column-wrapper -->
<?php } ?>
</section>
<!-- /.columns -->
<?php endif; ?>
Output as below:
This is a clonable meta group, I would like to be able to swap the content and the image (left & right) with each odd and even foreach loop/array.
I feel so stupid, all I needed was to count the posts and output alternate html.
I wrapped my code above in this:
<?php $counter = "";
foreach ( $columns_values as $columns_value ) {
$counter +=1;
// all my var stuff here
?>
<?php if($counter == 1) { ?>
<div class="columns-wrapper odd">
<!-- HTML here for the first loop -->
</div>
<?php }
// If the second item in the loop
elseif($counter == 2) {
// Reset the counter
$counter = 0;
?>
<div class="columns-wrapper even">
<!-- Other HTML here for the second loop -->
</div>
<?php } //end the elseif $counter ?>
<?php } //end the foreach stuff ?>
Related
I have an HTML structure that I need to dynamically output.
I am using a counter within my loop to check for the first post, and applying the class headline-big and m-grid-item for the first post. Then I'm applying the second class headline-scroll for the subsequent posts.
The problem is, the 2nd, 3rd and 4th posts are not being nested inside headline-scroll they are each getting their own div.headline-scroll which is messing up site.
I need the 2nd, 3rd and 4th posts to be nested inside a single div.headline-scroll instead of each one of them being nested under a separate one.
This is the HTML for structure
<!-- / 1ST POST -->
<div class="headline-big">
<div class="m-grid-item">
...
</div>
</div>
<!-- / END OF FIRST POST -->
<!-- / 2ND, 3RD AND 4TH POST - ALL NESTED INSIDE div.headline-scroll -->
<div class="headline-scroll">
<!-- / 2ND POST -->
<div class="m-grid-item -medium">
...
</div>
<!-- / END OF 2ND POST -->
<!-- / 3RD POST -->
<div class="m-grid-item -small">
...
</div>
<!-- / END OF 3RD POST -->
<!-- / 4TH POST -->
<div class="m-grid-item -small">
...
</div>
<!-- / END OF 4TH POST -->
</div>
And this is the PHP
if ( $featured->have_posts() ) {
$i = 0;
while ( $featured->have_posts() ) {
$featured->the_post();
if ( $i == 0 ) :
?>
<div class="headline-big">
<div class="m-grid-item">
<?php endif; ?>
<?php if ( $i != 0 ) : ?>
<div class="headline-scroll">
<div class="m-grid-item -medium">
<?php endif; ?>
<?php the_title(); ?>
</div>
</div>
<?php $i++;
}
} else {
echo 'Add some posts';
}
I'm not sure if I could be able to answer your question well. But this is how I understand. If there is a question, please let me know and I will modify.
if ( $featured->have_posts() ) {
$i = 1;
while ( $featured->have_posts() )
{
$featured->the_post();
if( $i == 1)
{
?>
<div class="headline-big">
<div class="m-grid-item">
<?php the_title(); ?>
</div>
</div>
<div class="headline-scroll">
<?php
}
else
{
$small = array(3,4); //list of small classes
$class = ( in_array($i, $small)) ? '-small' : '-medium';
<div class="m-grid-item <?php echo $class; ?>">
<?php the_title(); ?>
</div>
<?php
}
$i++;
}
echo '</div><!-- end of headline-scroll -->';
} else {
echo 'Add some posts';
}
I've simplified it here with if conditions.
If it's the first post, create the headline-big div.
If it's the second post, create the headline-scroll div and the medium class div.
For all subsequent posts, just use the small div. Finally, outside the while loop, if we had more than 1 post, we need to add a closing div to close off the headline scroll.
if ( $featured->have_posts() ) {
$i = 0;
while ( $featured->have_posts() )
{
$featured->the_post();
if( $i == 0)
{
?>
<div class="headline-big">
<div class="m-grid-item">
<?php the_title(); ?>
</div>
</div>
<?php
}
else if($i == 1)
{
?>
<div class="headline-scroll">
<div class="m-grid-item -medium">
<?php the_title(); ?>
</div>
<?php
}
else
{
<div class="m-grid-item -small">
<?php the_title(); ?>
</div>
}
$i++;
}
if($i > 1){
?>
</div><!-- end of headline-scroll -->
<?php
}
} else {
echo 'Add some posts';
}
You never closed many of your DIV tags, and you were opening your div.headline-scroll inside a loop, so you were bound to get more than one. Try this instead maybe? Consistent indent and minimal PHP in your HTML will make things easier to debug, though you're hamstrung by Wordpress' awful functions.
<?php if (!$featured->have_posts()):?>
<p>Add some posts!</p>
<?php else: $i = 0; while ($featured->have_posts()): $featured->the_post();?>
<?php if (!$i):?>
<div class="headline-big">
<div class="m-grid-item">
<?php the_title(); ?>
</div>
</div>
<div class="headline-scroll">
<?php else:?>
<div class="m-grid-item -medium">
<?php endif; ?>
<?php the_title(); ?>
</div>
<?php $i++; endwhile;?>
</div>
<?php endif?>
I'm new to PHP and and using a Wordpress one-page theme where each section has a unique post ID. I want to add a sidebar only to a post with a specific ID. The code for that specific ID should add a few divs for styling as well as the sidebar. I've tried adding a simple if/else statement and putting the code with the extra divs and sidebar in the if, and the original code without the sidebar or extra styling in the else but my code results not only styling for the widget on each post, but also removes the other content from the post I'm targeting. This is the entire php file for the template. Any help is much appreciated!
<?php
/*
Template Name: Onepage
*/
?>
<?php global $smof_data; ?>
<?php get_header();?>
<?php
if ( ( $locations = get_nav_menu_locations() ) && $locations['primary'] && !disable_onepage() ) {
$menu = wp_get_nav_menu_object( $locations['primary'] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$pages_included = array();
foreach ( $menu_items as $item ):
if ($item->object != 'page') continue;
$menu_state = get_post_meta($item->ID,'menu-item-menu-state',true);
if ($menu_state == 'link') continue;
$pages_included[] = $item->object_id;
endforeach;
} else {
$pages_included[] = array();
}
$count = 0;
/* IF THERE IS AT LEAST ONE PAGE MENU ITEM */
if (!empty($pages_included)) :
$args = array(
'post_type' => 'page',
'post__in' => $pages_included,
'posts_per_page' => count($pages_included),
'orderby' => 'post__in',
);
$onepage_query = new WP_Query();
$onepage_query->query($args);
endif;
if ( $onepage_query->have_posts() ): while( $onepage_query->have_posts() ): $onepage_query->the_post(); $count++;?>
<?php // Some PHP stuffs
$page_template = get_post_meta(get_the_ID(),'_wp_page_template',true);
$page_template = basename($page_template,'.php');
/* ----------------------------- GET OPTIONS ----------------------------------- */
/* Title Options
----------------------------------------------- */
$subtitle = get_post_meta(get_the_ID(),'_wi_subtitle',true);
$subtitle = trim($subtitle);
$title_image = false;
$title_image_ids = get_post_meta(get_the_ID(),'_wi_title-image',false);
$title_image_id = '';
foreach ( $title_image_ids as $tii ) {
if ( !wp_get_attachment_image_src( $tii ) ) continue;
$title_image_id = $tii;
}
if ( $title_image_id ) {
$title_image = wp_get_attachment_image_src($title_image_id,'full');
$title_image = $title_image[0];
}
$hide_title = get_post_meta(get_the_ID(),'_wi_hide-title-area',true);
/* Page Background Options
----------------------------------------------- */
$page_background_type = get_post_meta(get_the_ID(),'_wi_page-background-type',true);
$page_background_color = get_post_meta(get_the_ID(),'_wi_page-background-color',true);
$page_background_image = get_post_meta(get_the_ID(),'_wi_page-background-image',true);
$page_background_image_size = get_post_meta(get_the_ID(),'_wi_page-background-image-size',true);
$page_background_image_position = get_post_meta(get_the_ID(),'_wi_page-background-image-position',true);
$page_background_pattern = get_post_meta(get_the_ID(),'_wi_page-background-pattern',true);
$page_background_pattern_retina = get_post_meta(get_the_ID(),'_wi_page-background-pattern-retina',true);
/* Separator Background Options
----------------------------------------------- */
$disable_separator = get_post_meta(get_the_ID(),'_wi_disable-page-separator',true);
$separator_content = get_post_meta(get_the_ID(),'_wi_separator-content',true);
$background_or_pattern = get_post_meta(get_the_ID(),'_wi_background-image-or-pattern',true);
if ( $background_or_pattern!='pattern' ) $background_or_pattern = 'background';
$background_images = get_post_meta(get_the_ID(),'_wi_background-image',false);
$background_image = '';
foreach ( $background_images as $bgim ) {
if ( !wp_get_attachment_image_src( $bgim) ) continue;
$background_image = $bgim;
}
$overlay_opacity = get_post_meta(get_the_ID(),'_wi_overlay-opacity',true);
$overlay_opacity = absint($overlay_opacity);
$clipmask_opacity = get_post_meta(get_the_ID(),'_wi_clipmask-opacity',true);
$clipmask_opacity = absint($clipmask_opacity);
$enable_parallax = get_post_meta(get_the_ID(),'_wi_enable-parallax-effect',true);
$parallax_class = ( $enable_parallax ) ? ' parallax' : '';
$padding = get_post_meta(get_the_ID(),'_wi_padding-top-bottom',true);
$predefined_pattern = get_post_meta(get_the_ID(),'_wi_predefined-pattern',true);
$retina_custom_patterns = get_post_meta(get_the_ID(),'_wi_retina-custom-pattern',false);
$retina_custom_pattern = '';
foreach ($retina_custom_patterns as $bgim ) {
if ( !wp_get_attachment_image_src( $bgim) ) continue;
$retina_custom_pattern = $bgim;
}
$custom_patterns = get_post_meta(get_the_ID(),'_wi_custom-pattern',false);
$custom_pattern = '';
foreach ( $custom_patterns as $bgim ) {
if ( !wp_get_attachment_image_src( $bgim) ) continue;
$custom_pattern = $bgim;
}
if ( $background_or_pattern != 'pattern' ) {
$background_type = 'image';
if ( $background_image ) {
$background_image = wp_get_attachment_image_src($background_image,'full');
$background_image = $background_image[0];
$background_size = 'cover';
} else {
$background_image = '';
$background_size = '';
}
$retina_background_image = $background_image;
} else { // $background_or_pattern == 'pattern'
$background_type = 'pattern';
if ( $custom_pattern ) {
$pattern = $custom_pattern;
if ( $retina_custom_pattern ) {
$retina_pattern = $retina_custom_pattern;
} else {
$retina_pattern = $custom_pattern;
}
$pattern = wp_get_attachment_image_src($pattern,'full');
$pattern = $pattern[0];
$retina_pattern = wp_get_attachment_image_src($retina_pattern,'full');
$retina_pattern = $retina_pattern[0];
} else {
$pattern = $predefined_pattern;
$retina_pattern = str_replace( '.png' , '_#2X.png' , $pattern );
}
if ( !$pattern ) $pattern = get_template_directory_uri().'/images/sidrbg/argyle.png';
if ( $pattern ) {
$background_image = $pattern;
$background_size = (array) #getimagesize($pattern);
if ( isset($background_size[0]) && isset($background_size[1]) ) {
$background_size = $background_size[0] . 'px ' . $background_size[1] . 'px';
} else {
$background_size = 'auto';
}
} else {
$background_image = '';
$background_size = '';
}
if ( $retina_pattern ) {
$retina_background_image = $retina_pattern;
} else {
$retina_background_image = $pattern;
}
} // image or pattern
?>
<?php if ( !$disable_separator ) :?>
<style type="text/css">
#page-separator-<?php echo esc_html($post->post_name);?> {
background-image:url(<?php echo esc_url($background_image);?>);
-webkit-background-size:<?php echo esc_html($background_size);?>;
-moz-background-size:<?php echo esc_html($background_size);?>;
background-size:<?php echo esc_html($background_size);?>;
padding-top:<?php echo absint($padding);?>px;
padding-bottom:<?php echo absint($padding);?>px;
}
#page-separator-<?php echo esc_html($post->post_name);?> .overlay {
opacity:<?php echo ($overlay_opacity/100);?>;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=<?php echo ($overlay_opacity);?>)";
filter: alpha(opacity=<?php echo ($overlay_opacity);?>);
}
#page-separator-<?php echo esc_html($post->post_name);?> .clipmask {
opacity:<?php echo ($clipmask_opacity/100);?>;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=<?php echo ($clipmask_opacity);?>)";
filter: alpha(opacity=<?php echo ($clipmask_opacity);?>);
}
#media (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi){
#page-separator-<?php echo esc_html($post->post_name);?> {
background-image:url(<?php echo esc_url($retina_background_image);?>);
}
}
</style>
<div class="<?php echo esc_attr('page-separator background-type-' . $background_type . $parallax_class);?>" id="<?php echo esc_attr('page-separator-' . $post->post_name);?>">
<div class="overlay"></div>
<div class="clipmask"></div>
<div class="container">
<div class="content">
<?php echo do_shortcode($separator_content); ?>
</div><!-- .content -->
</div><!-- .container -->
</div><!-- .page-separator #page-separator-$post->post_name -->
<?php endif; // enable/disable page separator ?>
<style type="text/css">
<?php if($page_background_color){?>
.wi-page#<?php echo esc_html($post->post_name);?> {
background-color:<?php echo sanitize_hex_color($page_background_color);?>;
}
<?php } ?>
/* --------- BACKGROUND PATTERN OPTIONS ------------ */
<?php if ($page_background_type == 'pattern'): ?>
<?php if($page_background_pattern){
$pattern = wp_get_attachment_image_src($page_background_pattern,'full');
$pattern = $pattern[0];
$background_size = (array) #getimagesize($pattern);
$background_size = $background_size[0] . 'px ' . $background_size[1] . 'px';
?>
.wi-page#<?php echo esc_html($post->post_name);?> {
background-image:url(<?php echo esc_url($pattern);?>);
-webkit-background-size:<?php echo esc_html($background_size);?>;
-moz-background-size:<?php echo esc_html($background_size);?>;
background-size:<?php echo esc_html($background_size);?>;
}
<?php } ?>
<?php if($page_background_pattern_retina){
$pattern = wp_get_attachment_image_src($page_background_pattern_retina,'full');
$pattern = $pattern[0];
?>
#media (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi){
.wi-page#<?php echo esc_html($post->post_name);?> {
background-image:url(<?php echo esc_url($pattern);?>);
}
}
<?php } ?>
/* --------- BACKGROUND IMAGE OPTIONS ------------ */
<?php elseif ($page_background_type == 'image'): ?>
<?php if($page_background_image){
$page_background_image = wp_get_attachment_image_src($page_background_image,'full');
$page_background_image = $page_background_image[0];
?>
.wi-page#<?php echo esc_html($post->post_name);?> {
background-image:url(<?php echo esc_url($page_background_image);?>);
-webkit-background-size:<?php echo esc_html($page_background_image_size);?>;
-moz-background-size:<?php echo esc_html($page_background_image_size);?>;
background-size:<?php echo esc_html($page_background_image_size);?>;
background-position:<?php echo esc_html($page_background_image_position);?>;
}
<?php } ?>
<?php endif; // page background type ?>
</style>
<?php
if ($post->ID == '4048') {
?>
<div <?php post_class('wi-page '.$page_template);?> id="<?php echo esc_attr($post->post_name);?>">
<?php if ( !$hide_title ){ ?>
<!-- TITLE -->
<div class="title-area">
<div class="container">
<div class="pad">
<?php if ( $title_image ) : ?>
<div class="image">
<img src="<?php echo esc_url($title_image);?>" alt="<?php the_title();?>" />
</div><!-- .image -->
<?php endif; // header_image ?>
<h2 class="title"><?php the_title();?></h2>
<?php if ($subtitle):?>
<h3 class="subtitle"><?php echo wp_kses($subtitle,''); ?></h3>
<?php endif;?>
</div><!-- .pad -->
</div><!-- .container -->
</div><!-- .title-area -->
<?php }
}else{ ?>
<div class="content-area">
<div class="container">
<div class="row-fluid"> <!-- added for styling -->
<div id="primary" class="span8"> <!-- added for styling -->
<?php the_content();?>
</div> <!-- added for styling #primary -->
<?php get_sidebar('video-sidebar');?>
</div><!-- .row-fluid -->
</div><!-- .container -->
<div class="clearfix"></div>
</div> <!-- content-area -->
</div><!-- .wi-page -->
<?php } ?>
<?php
endwhile; // have posts
endif; // have posts
if (!empty($pages_included)) :
wp_reset_query();
endif;
// in case onepage disabled but user wants to use onepage template for some usage
if ( disable_onepage() ):
if (have_posts()) :?>
<div class="container">
<?php while(have_posts()): the_post(); ?>
<article <?php post_class('article wi-single');?> id="post-<?php the_ID();?>">
<?php the_content();?>
<?php wp_link_pages( array( 'before' => '<div class="page-links-container"><div class="page-links"><div class="page-links-label">' . __( 'Pages:', 'wi' ) . '</div>', 'after' => '</div></div>', 'pagelink' => '<span>%</span>' ) ); ?>
</article><!-- .article -->
<?php endwhile;?>
</div><!-- .container -->
<?php endif;
endif; // if disable onepage
?>
<?php get_footer();?>
<?php
if ($post->ID == '4048') {
?>
<div <?php post_class('wi-page '.$page_template);?> id="<?php echo esc_attr($post->post_name);?>">
<?php if ( !$hide_title ){ ?>
<!-- TITLE -->
<div class="title-area">
<div class="container">
<div class="pad">
<?php if ( $title_image ) : ?>
<div class="image">
<img src="<?php echo esc_url($title_image);?>" alt="<?php the_title();?>" />
</div><!-- .image -->
<?php endif; // header_image ?>
<h2 class="title"><?php the_title();?></h2>
<?php if ($subtitle):?>
<h3 class="subtitle"><?php echo wp_kses($subtitle,''); ?></h3>
<?php endif;?>
</div><!-- .pad -->
</div><!-- .container -->
</div><!-- .title-area -->
<?php }
}else{ ?>
<div class="content-area">
<div class="container">
<div class="row-fluid"> <!-- added for styling -->
<div id="primary" class="span8"> <!-- added for styling -->
<?php the_content();?>
</div> <!-- added for styling #primary -->
<?php get_sidebar('video-sidebar');?>
</div><!-- .row-fluid -->
</div><!-- .container -->
<div class="clearfix"></div>
</div> <!-- content-area -->
</div><!-- .wi-page -->
<?php } ?>
You forgot to close in line number 3 ?>
I use this code to display user entered data.
But all data is displayed on 1 single line separate by comma.
I want to display all separate data in an individual < li > class
How can I achieve that?
<?php if ( $this->showPros() ): ?>
<div class="pros">
<h4><?php echo $this->__('Pros:') ?></h4>
<ul class="pros-ul">
<li class="pros-li">
<?php $isFirst = true ?>
<?php foreach( $this->getProsCollection() as $pros )
{
$name = $this->__( $pros->getName() );
echo ( $isFirst ? $name : ( ', '.$name ) );
$isFirst = false;
} ?><br />
</li>
</ul>
</div>
<?php endif ?>
Just wrap the $name in li tags:
<?php if ( $this->showPros() ): ?>
<div class="pros">
<h4><?php echo $this->__('Pros:') ?></h4>
<ul class="pros-ul">
<?php foreach( $this->getProsCollection() as $pros )
{
$name = $this->__( $pros->getName() );
echo ('<li class="pros-li">'.$name.'</li>');
}
?>
</ul>
</div>
<?php endif ?>
I would like to be able to have the html content of a wordpress page. I try to use this kind of code :
$my_id = 5369;
$post_id_5369 = get_post($my_id);
$content = $post_id_5369->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
But it returns empty an empty string whereas when I access to the page, the content is not empty. Indeed, there is php code inside the content of the page I would like to get. So, how I can do to get the content of this page knowing that there is php code inside?
data content :
<div id="content" class="oe">
<?php $loop = new WP_Query( array('post_type'=>'mcm')); ?>
<div id="slid" class="div-slider">
<?php
/* get value */
$appercu_collection = get_post_custom_values ( "o" );
if ($appercu_collection) { // si appercu
class Image {
public $link;
public $image;
}
/* init value */
$imageCollection = array ();
/* complet collection */
foreach ( $appercu_collection as $img ) {
$img_tmp = new Image ();
$img_tmp->image = wp_get_attachment_image_src( $img , 'medium' )[0];
array_push ( $imageCollection, $img_tmp );
}
display_slider ( $imageCollection );
}
?>
</div>
<div id="content-meta">
<div class="meta-detail-header"><?php echo get_post_custom_values ( "_at" )[0]; ?></div>
<div class="meta-detail-title"><?php the_title(); ?></div>
<div class="audio">
<div id="audio-inner">
<?php $au = get_post_custom_values("_au");
if ($au) {
$urlguid = wp_get_attachment_url ( $au [0] );
if ($urlguid) {
display_audio ( $urlguid );
}
}
?>
</div>
</div>
</div>
<div id="ex">
<?php
$newdebut = get_long_formatted_date( $date_debut[0] );
$newfin = get_long_formatted_date( $date_fin[0] );
?>
<div id="expo-temp-dates"><?php echo sprintf( __( 'From %s to %s' , 'wptouch-pro' ) , $newdebut , $newfin );?></div>
<?php
$tar = get_post_custom_values("_tarif");
if($tar) { ?>
<div id="exprice"><?php echo $tar[0]; ?></div>
<?php }?>
</div>
<div id="content-o" >
<!-- GET Content -->
<div id="content-description" class="detail-container">
<?php display_zoom_controls(); ?>
<?php echo wpautop( wptouch_the_content() ); ?>
</div>
<!-- GET BONUS -->
<div id="content-bottom-sticky">
<a href="<?php echo $url_guide;?>"
class="tappable-button tappable dark" role="Button"><?php _e( 'TUIDE' , 'wptouch-pro' ); ?></a>
</div>
</div>
<?php endif; ?>
<!-- inside intervalle -->
<?php endwhile;
wp_reset_postdata();?>
<?php if( ! $content) { ?>
<div id="title" class="title">
<h2><?php _e( 'N' , 'wptouch-pro' ); ?></h2>
</div>
<?php }?>
I finally resolve my problem by doing an ajax request to my page and get the content thanks to
wp_remote_get . Indeed, It was a page with a custom type post and custom fields.
Here is my code :
$resp = wp_remote_retrieve_body( wp_remote_get($url,$option));
$doc = new DOMDocument();
$doc->loadHTML($resp);
$element = $doc->getElementById('content');
$content = $doc->saveHTML($element);
$content contains the html content of the element with the id "content" of the page whose url is $url.
Currently my image gallery has 4 images per row. If the screen is minimized below the width of those 4 images, one image will drop to the next line and there will be a line break before the next row. Is there any way to make gallery continuous instead of having the break in images when the screen is resized? Ideally, I would like to start with 5 images per row, then if the viewer has a smaller screen, it will automatically adjust the number of images per row to fit whatever size window they are using.
Here is a link to the gallery: http://rabbittattoo.com/?gallery=gallery
And the PHP:
$pp_gallery_style = get_option('pp_gallery_style');
if($pp_gallery_style == 'f')
{
include_once(TEMPLATEPATH.'/gallery-f.php');
exit;
}
if(!isset($hide_header) OR !$hide_header)
{
get_header();
}
$caption_class = "page_caption";
$portfolio_sets_query = '';
$custom_title = '';
if(!empty($term))
{
$portfolio_sets_query.= $term;
$obj_term = get_term_by('slug', $term, 'photos_galleries');
$custom_title = $obj_term->name;
}
else
{
$custom_title = get_the_title();
}
/**
* Get Current page object
**/
$page = get_page($post->ID);
/**
* Get current page id
**/
if(!isset($current_page_id) && isset($page->ID))
{
$current_page_id = $page->ID;
}
if(!isset($hide_header) OR !$hide_header)
{
?>
<div class="wrapper_shadow"></div>
<div class="page_caption">
<div class="caption_inner">
<div class="caption_header">
<h1 class="cufon"><?php echo the_title(); ?></h1>
</div>
</div>
</div>
</div>
<!-- Begin content -->
<div id="content_wrapper">
<div class="inner">
<!-- Begin main content -->
<div id="gallery_wrapper" class="inner_wrapper portfolio">
<div class="standard_wrapper small">
<br class="clear"/><br/>
<?php
}
else
{
echo '<br class="clear"/>';
}
?>
<?php echo do_shortcode(html_entity_decode($page->post_content)); ?>
<!-- Begin portfolio content -->
<?php
$menu_sets_query = '';
$portfolio_items = 0;
$portfolio_sort = get_option('pp_gallery_sort');
if(empty($portfolio_sort))
{
$portfolio_sort = 'DESC';
}
$args = array(
'post_type' => 'attachment',
'numberposts' => $portfolio_items,
'post_status' => null,
'post_parent' => $post->ID,
'order' => $portfolio_sort,
'orderby' => 'date',
);
$all_photo_arr = get_posts( $args );
if(isset($all_photo_arr) && !empty($all_photo_arr))
{
?>
<?php
foreach($all_photo_arr as $key => $portfolio_item)
{
$image_url = '';
if(!empty($portfolio_item->guid))
{
$image_id = $portfolio_item->ID;
$image_url[0] = $portfolio_item->guid;
}
$last_class = '';
$line_break = '';
if(($key+1) % 4 == 0)
{
$last_class = ' last';
if(isset($page_photo_arr[$key+1]))
{
$line_break = '<br class="clear"/><br/>';
}
else
{
$line_break = '<br class="clear"/>';
}
}
?>
<div class="one_fourth<?php echo $last_class?>" style="margin-right:24px;margin-bottom:24px;margin-top:-20px">
<a title="<?php echo $portfolio_item->post_title?>" href="<?php echo $image_url[0]?>" class="one_fourth_img" rel="gallery" href="<?php echo $image_url[0]?>">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/timthumb.php?src=<?php echo $image_url[0]?>&h=370&w=350&zc=1" alt=""/>
</a>
</div>
<?php
echo $line_break;
}
//End foreach loop
?>
<?php
}
//End if have portfolio items
?>
</div>
<!-- End main content -->
<br class="clear"/><br/>
</div>
<?php
if(!isset($hide_header) OR !$hide_header)
{
?>
</div>
<!-- End content -->
<?php get_footer(); ?>
<?php
}
?>
Thank you in advance for you help!