Hi im having problems with my post category list next page, when i clicknext it goes to a sample page.
my personalize permalink is: /%category%/%post_id%/%postname%/
my site: http://hgps.org.do/prevencion_salud/
while( have_posts() ): the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php echo avada_render_rich_snippets_for_pages(); ?>
<?php if( ! post_password_required($post->ID) ): // 1 ?>
<?php global $smof_data; if(!$smof_data['featured_images_pages'] ): // 2 ?>
<?php
if( avada_number_of_featured_images() > 0 || get_post_meta( $post->ID, 'pyre_video', true ) ): // 3
?>
<div class="fusion-flexslider flexslider post-slideshow">
<ul class="slides">
<?php if(get_post_meta($post->ID, 'pyre_video', true)): ?>
<li>
<div class="full-video">
<?php echo get_post_meta($post->ID, 'pyre_video', true); ?>
</div>
</li>
<?php endif; ?>
<?php if( has_post_thumbnail() && get_post_meta( $post->ID, 'pyre_show_first_featured_image', true ) != 'yes' ): ?>
<?php $attachment_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?>
<?php $full_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?>
<?php $attachment_data = wp_get_attachment_metadata(get_post_thumbnail_id()); ?>
<li>
<img src="<?php echo $attachment_image[0]; ?>" alt="<?php echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true); ?>" />
</li>
<?php endif; ?>
<?php
$i = 2;
while($i <= $smof_data['posts_slideshow_number']):
$attachment_new_id = kd_mfi_get_featured_image_id('featured-image-'.$i, 'page');
if($attachment_new_id):
?>
<?php $attachment_image = wp_get_attachment_image_src($attachment_new_id, 'full'); ?>
<?php $full_image = wp_get_attachment_image_src($attachment_new_id, 'full'); ?>
<?php $attachment_data = wp_get_attachment_metadata($attachment_new_id); ?>
<li>
<img src="<?php echo $attachment_image[0]; ?>" alt="<?php echo get_post_meta($attachment_new_id, '_wp_attachment_image_alt', true); ?>" />
</li>
<?php endif; $i++; endwhile; ?>
Related
So I have a function in functions.php and I want to call it in other parts of my wordpress site with shortcode, but the problem is that I don't know how to save results of my function into a variable. If anyone can help me I would be very grateful. This is the php code:
<?php
function get_slider() {
$args = array(
'post_type' => 'something',
);
$posts = get_posts($args);
echo $posts;
if( $posts ): ?>
<div class="custom-posts-grid">
<?php foreach($posts as $post): setup_postdata( $post ); ?>
<?php if( have_rows('poslovna_darila') ): ?>
<?php while( have_rows('poslovna_darila') ): the_row(); ?>
<div class="slider_slick">
<?php // vars
$image = get_sub_field('thumbnail_for_poslovna_darila');
$link = get_sub_field('url_poslovna_darila');
$count = count($posts);
?>
<div class="slide">
<a href="<?php echo $link; ?>">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" class="image-overlay-post" />
</a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif;
}
add_shortcode ('slick_slider' , 'get_slider'); ?>
The code returns array, but I need to get a value out of it or if it's possible the slider.
You can use an output buffer to return the string in your shortcode.
<?php
function get_slider() {
$args = array(
'post_type' => 'something',
);
$posts = get_posts($args);
//echo $posts;
ob_start(); // start the output buffer
if ( $posts ) : ?>
<div class="custom-posts-grid">
<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
<?php if ( have_rows('poslovna_darila') ): ?>
<?php while ( have_rows('poslovna_darila') ) : the_row(); ?>
<div class="slider_slick">
<?php // vars
$image = get_sub_field('thumbnail_for_poslovna_darila');
$link = get_sub_field('url_poslovna_darila');
$count = count($posts);
?>
<div class="slide">
<a href="<?php echo $link; ?>">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" class="image-overlay-post" />
</a>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php endif;
// return the contents of the output buffer as a string
return ob_get_clean();
}
add_shortcode( 'slick_slider' , 'get_slider' ); ?>
So I have a php page in wordpress and when I add a part of the code it doesn't work. So to explain a bit more. I have a php template and most of it works, but when I add some additional code at the bottom that doesn't show up.
<?php get_header(); ?>
<div class="main_color container_wrap_first container_wrap">
<menu id="nav">
<ul><?php
$category_id = 2;
while( $category_id < 7 ) { ?>
<li>
<a href="<?php echo get_category_link( $category_id ); ?>">
<?php
$cat_id = $category_id;
echo get_cat_name( $cat_id );
$category_id++;
?>
</a>
</li>
<?php } ?>
</ul>
</menu>
<?php
$args = array(
'post_type' => 'projekti',
'posts_per_page' => -1,
'category' => '4',
);
$posts = get_posts($args);
if( $posts ):
$i = 1; ?>
<div class="custom-posts-grid">
<?php foreach($posts as $post): setup_postdata( $post ); ?>
<?php if( have_rows('logotipi') ): ?>
<?php while( have_rows('logotipi') ): the_row();
// vars
$image = get_sub_field('thumbnail_for_logotipi');
$content = get_sub_field('project_name');
$link = get_sub_field('url_logotipi');
$count = count($posts);
?>
<div class="post-grid-logotipi">
<a href="<?php echo $link; ?>">
<div class="post-title-hover"><?php echo $content ?></div>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" class="image-overlay-post" />
</a>
</div>
<?php
$i++;
if( $i == 6 ):
$i++;
?>
<div class="sodelujmo-post-grid"><div class="sodelujmo-post"><p class="sodelujmo-text">Vam je všeč,<br>kar vidite?<br>...<p><div class="button-bg"><a class="sodelujmo-link" href="../u3nek/sodelujmo/">Sodelujmo</a>
</div></div></div>
<?php
endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<!-- after this nothing I add can be shown -->
</div>
</div>
I have no idea what is wrong. So if anyone encountered anything similar before do let me know.
I am trying to build a Flexible Content which contains 4 possible Layouts (a description, a hero image, a gallery 1col and a gallery 2col). So far I can get the Description and Hero Image subfields to display just fine but the Gallery subfield wont show up on the page. Don't know what I'm doing wrong. Here's the code:
<?php
while(the_flexible_field("flexible_content")): ?>
<?php if(get_row_layout() == "description"): // layout: Description ?>
<div class="proy-desc">
<h2><?php the_sub_field("text"); ?></h2>
</div>
<?php elseif(get_row_layout() == "hero_image"): // layout: Hero Image ?>
<div class="proy-img">
<?php
$image = get_sub_field('image');
elseif( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php ?>
</div>
<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_50p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php ?>
</div>
<?php endif; ?>
<?php elseif(get_row_layout() == "gallery_100p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_100p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
You did not close your if statement. See below:
<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_50p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php ?>
</div>
<?php endif; ?>
Change your section to this:
<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_50p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Your endif; was in the wrong spot. Everything else looks right, so give this a try.
i have this code
<?php $project_taxonomy_select = get_post_meta( $post->ID, '_ep_project_taxonomy_select', true );
$theCatSlug = get_term_by( 'id', $project_taxonomy_select[0], 'project_filter' );
$theCatSlug = $theCatSlug->slug;
echo $theCatSlug; ?>
how to put the php above in "project_filter=" inside my query in the below php code
<div id="project">
<?php $my_query = new WP_Query('post_type=project&posts_per_page=-1&project_filter=the php here');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a class="all project-item <?php echo $tax ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php if ( has_post_thumbnail()) { ?><?php $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id,'project-thumb-main', true); echo $thumb_url[0]; ?><?php } else { ?><?php echo esc_url(home_url('/')); ?>assets/img/no-project-thumb-main.jpg<?php } ?>">
<div class="magnifier">
<span class="text"><?php the_title(); ?></span>
</div>
</a>
<?php endwhile; wp_reset_query(); ?>
</div>
im using Custom-Metaboxes-and-Fields-for-WordPress
Please Help.. :)
You'd just use simple string concatentation:
WP_Query('post_type=project&posts_per_page=-1&project_filter='.$theCatSlug);
I am trying to alter my Wordpress theme to display the latest posts from a specific tag. It currently lists the latest posts overall.
Here is part of the code that it uses:
<?php
if ( is_home() ) {
$args=array(
'showposts'=> (int) get_option('aggregate_homepage_posts'),
'paged'=>$paged,
'category__not_in' => (array) get_option('aggregate_exlcats_recent')
);
if (get_option('aggregate_duplicate') == 'false') {
global $ids;
$args['post__not_in'] = $ids;
}
query_posts($args);
global $paged;
}
$i = 0;
?>
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$i++;
$et_is_latest_post = ( $paged == 0 && ( is_home() && $i <= 2 ) ) || !is_home();
?>
<div class="post entry clearfix<?php if ( $et_is_latest_post ) echo ' latest'; ?>">
<?php
$thumb = '';
$width = $et_is_latest_post ? 170 : 67;
$height = $et_is_latest_post ? 110 : 67;
$classtext = 'post-thumb';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if($thumb <> '' && get_option('aggregate_thumbnails_index') == 'on') { ?>
<div class="thumb thumbcont">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span class="overlay"></span>
</a>
<a class="thumb<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" href="<?php bloginfo('url'); ?>/<?php echo $category[0]->category_nicename; ?>"><?php echo $category[0]->cat_name; ?></a>
</div> <!-- end .post-thumbnail -->
<?php } ?>
<h3 class="title"><?php the_title(); ?></h3>
<?php get_template_part('includes/postinfo'); ?>
<p class="postsummery">
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,20);
?>
</p>
<span><?php esc_html_e('Read More','Aggregate'); ?></span>
</div> <!-- end .post-->
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation','entry'); ?>
<?php } ?>
<?php else : ?>
<?php get_template_part('includes/no-results','entry'); ?>
<?php endif; wp_reset_query(); ?>
While doing some research, I found some details of how to do this:
http://codex.wordpress.org/Template_Tags/get_posts
However, my very limited knowledge of PHP coding and lack of understanding how my current code works with the examples provided, I cannot find a way to do it. Can you guide me?
You simple add 'tag'=>the tag u wanted listed, after array( at line3
why well cause that's the array containing the arguments that then will be passed to the get posts function that makes a call to the database, the arguments that you got to choose from can be find here http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
And the full code would look like so
<?php
if ( is_home() ) {
$args=array(
'showposts'=> (int) get_option('aggregate_homepage_posts'),
'paged'=>$paged,
'tag'=>"the tag u want shown",
'category__not_in' => (array) get_option('aggregate_exlcats_recent')
);
if (get_option('aggregate_duplicate') == 'false') {
global $ids;
$args['post__not_in'] = $ids;
}
query_posts($args);
global $paged;
}
$i = 0;
?>
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$i++;
$et_is_latest_post = ( $paged == 0 && ( is_home() && $i <= 2 ) ) || !is_home();
?>
<div class="post entry clearfix<?php if ( $et_is_latest_post ) echo ' latest'; ?>">
<?php
$thumb = '';
$width = $et_is_latest_post ? 170 : 67;
$height = $et_is_latest_post ? 110 : 67;
$classtext = 'post-thumb';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if($thumb <> '' && get_option('aggregate_thumbnails_index') == 'on') { ?>
<div class="thumb thumbcont">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span class="overlay"></span>
</a>
<a class="thumb<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" href="<?php bloginfo('url'); ?>/<?php echo $category[0]->category_nicename; ?>"><?php echo $category[0]->cat_name; ?></a>
</div> <!-- end .post-thumbnail -->
<?php } ?>
<h3 class="title"><?php the_title(); ?></h3>
<?php get_template_part('includes/postinfo'); ?>
<p class="postsummery">
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,20);
?>
</p>
<span><?php esc_html_e('Read More','Aggregate'); ?></span>
</div> <!-- end .post-->
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation','entry'); ?>
<?php } ?>
<?php else : ?>
<?php get_template_part('includes/no-results','entry'); ?>
<?php endif; wp_reset_query(); ?>