Define number of images per row in PHP generated image gallery? - php

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!

Related

Add links to images gallery

I need to link some gallery images to different external webistes. After some research I'm not able to found a solution that isn't using a plugin. Is this possible in wordpress without using plugins? I can't install plugins for this project so any suggestion will be appreciated thanks.
Here is my code:
$args = array(
'post_type' => 'post',
'name' => 'partners'
);
$logo_img = new WP_Query( $args );
?>
<div class="container-fluid" id="">
<div class="row" style="margin-top:1em;margin-bottom:1em;">
<?php if( $logo_img->have_posts() ): while( $logo_img->have_posts() ): $logo_img->the_post();
$logo_gallery = get_post_gallery_images( $post->ID );
if( $logo_gallery ): ?>
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<?php foreach($logo_gallery as $logo ): ?>
<img class="img-fluid" src="<?php echo $logo; ?>" alt="" width="60" id="partner-logo" style="margin:0 .5em 0 .5em;"/>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
</div>
</div>
Depending on how many images we are talking about, if these images are named you could use some logic to create a URL based on the name, if they are not named and there aren't that many, you could rename them.
Here's an example;
<?php
// If there is a matching string, set a specific URL
if (preg_match('/site1/',$logo)) { $set = "yes"; $link = "https://website1.com"; }
if (preg_match('/site2/',$logo)) { $set = "yes"; $link = "https://website2.com"; }
if (preg_match('/site3/',$logo)) { $set = "yes"; $link = "https://website3.com"; }
// If there is no matching string, set a default URL
if ($set !== "yes") { $link = "https://default.com"; }
// Now encase your image in a URL
echo "<a href='$link'>
<img class='img-fluid' src='$logo' alt='' width='60' id='partner-logo' style='margin:0 .5em 0 .5em;'/>
</a>";
?>
By the way, id='partner-logo' - the id should be unique.

Change HTML for odd & even items in a foreach loop

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 ?>

conditional sidebar for certain post id Wordpress PHP

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 ?>

Open linked page instead of fancybox

I have a code that is for a gallery. The images in this gallery opens in a fancybox. I don't want to link this images to a fancybox but i want link this images to one specific page. This is the code that must be customized:
<?php
global $sr_prefix;
$gallery = get_post_meta($post->ID, $sr_prefix.'_medias', true);
$postid = $post->ID;
$maintitle = 'h2'; $subtitle = 'h5';
if (get_option($sr_prefix.'_blogentrieslayout') == 'masonry' || get_option($sr_prefix.'_blogentrieslayout') == 'bloglist') { $maintitle = 'h4'; $subtitle = 'h6'; }
if( empty($gallery) || get_option($sr_prefix.'_blogentriesdisplay') == 'featuredimage' || get_option($sr_prefix.'_blogpostgallerydisplay') == "list" ) {
?>
<?php if(has_post_thumbnail()) { ?>
<div class="entry-thumb entry-media blog-media">
<div class="imgoverlay">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('single-blog-image'); ?>
<div class="overlay"><span class="overlaycolor"></span><span class="overlayinfo">
<?php echo '<'.$maintitle.'>'; ?><strong><?php the_title(); ?></strong><?php echo '</'.$maintitle.'>'; ?>
<?php if (!get_option($sr_prefix.'_blogpostsdisabledate')) { ?>
<?php echo '<'.$subtitle.'>'; ?><?php the_time(get_option('date_format')); ?><?php echo '</'.$subtitle.'>'; ?>
<?php } ?>
</span></div>
</a>
</div>
</div> <!-- END .entry-media -->
<?php } ?>
<?php
} else {
$medias = explode('|||', $gallery);
$output_medias = '';
foreach ($medias as $media) {
$object = explode('~~', $media);
$type = $object[0];
$val = $object[1];
$output_medias .= "<li>";
if ($type == 'image') {
$image = wp_get_attachment_image_src($val, 'single-blog-image'); $image = $image[0];
$fancyimage = wp_get_attachment_image_src($val, 'full'); $fancyimage = $fancyimage[0];
$thisimage = '<img src="'.$image.'" alt="'.get_the_title($image[1]).'"/>';
if(get_option($sr_prefix.'_blogpostsdisablefancybox') !== "on") {
$output_medias .= '<div class="imgoverlay">'.$thisimage.'<div class="overlay"><span class="overlaycolor"></span></div></div>';
} else {
$output_medias .= $thisimage;
}
} else {
$output_medias .= '<div class="embeddedvideo">'.$val.'</div>';
}
$output_medias .= "</li>";
}
?>
<?php if(get_option($sr_prefix.'_blogpostgallerydisplay') !== "list" ) { ?>
<div class="entry-media blog-media">
<div id="slider-<?php echo $postid; ?>" class="flexslider-container post-slider">
<div class="flexslider">
<ul class="slides">
<?php echo $output_medias; ?>
</ul>
</div>
</div>
</div> <!-- END .entry-media -->
<?php } else { ?>
<div class="entry-media blog-media">
<?php the_post_thumbnail('single-blog-image'); ?>
</div> <!-- END .entry-media -->
<?php } ?>
<?php } ?>
Seems like you are using Wordpress.
First of all you have to look at this part
if ($type == 'image') {
$image = wp_get_attachment_image_src($val, 'single-blog-image'); $image = $image[0];
$fancyimage = wp_get_attachment_image_src($val, 'full'); $fancyimage = $fancyimage[0];
$thisimage = '<img src="'.$image.'" alt="'.get_the_title($image[1]).'"/>';
if(get_option($sr_prefix.'_blogpostsdisablefancybox') !== "on") {
$output_medias .= '<div class="imgoverlay">'.$thisimage.'<div class="overlay"><span class="overlaycolor"></span></div></div>';
You have if(get_option($sr_prefix.'_blogpostsdisablefancybox') !== "on") option, which i suppose can disable fancybox, maybe it's somewhere in WP admin panel.
Anyway, if I remember correctly, fancybox links it's events to particular class, in this case it's openfancybox class. You can remove this class and disable fancybox.
$output_medias .=
'<div class="imgoverlay">
<a href="'.$fancyimage.'" class="openfancybox" rel="gallery'.get_the_ID().'" title="'.get_the_title($image[1]).'">'.$thisimage.'
<div class="overlay"><span class="overlaycolor">
</span>
</div>
</a>
</div>';
Then you can just change $fancyimage variable to you desired URL.

Wordpress get content of page (with php inside)

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.

Categories