halluzineyt
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Make curl/json work on wordpress<?php $result = wp_remote_get("https://api.instagram.com/v1/users/*********/media/recent/?access_token=*********&count=60", true); $decode = json_decode($result['body'], true); foreach ($decode->data as $post) { if(empty($post->caption->text)) { // Do Nothing } else { echo '<a class="instagram-unit" target="blank" href="'.$post->link.'"> <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" /> </a>'; } } ?>
Can you check this one?
Forum: Fixing WordPress
In reply to: Make curl/json work on wordpress<?php $result = wp_remote_get( "https://api.instagram.com/v1/users/***********/media/recent/?access_token=**********6" ); $result = json_decode($result); foreach ($result->data as $post) { if(empty($post->caption->text)) { // Do Nothing } else { echo '<a class="instagram-unit" target="blank" href="'.$post->link.'"> <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" /> </a>'; } } ?>
i tried this still doesnt work/
Forum: Fixing WordPress
In reply to: Echo/print Instagram images on html<?php $userid = "***"; $accessToken = "****"; $url = "https://api.instagram.com/v1/users/****/media/recent/?access_token=***"; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $result = curl_exec($ch); curl_close($ch); $result = json_decode($result); foreach ($result->data as $post) { echo '<p> <a class="fancybox" href="'.$post->images->standard_resolution->url.'" data-fancybox-group="gallery" title="'.$post->caption->text.'"><img src="'.$post->images->thumbnail->url.'" alt="SOME TEXT HERE"></p>'; } ?>
Found this do you know how can i make this work on wordpress?
Forum: Plugins
In reply to: [WordPress Simple Shopping Cart] Add to wp query<?php $title = the_title(); $price = get_post_meta($post->ID, 'price', true); echo print_wp_cart_button_for_product($title,$price); ?>
Im doing this i dont know why the title appears on the top of the button?
Forum: Plugins
In reply to: [WordPress Simple Shopping Cart] Add to wp queryThat code still need to pull the product name and product price, since its a wp query i cant provide it manually one by one right ? Do i put it in custom fields?
Forum: Plugins
In reply to: [WordPress Simple Shopping Cart] Add to wp queryFor example ill be querying category 1 so i will create a custom query where i can call the image and the exerpt only but not the content, now how can i insert the add to cart function there? For example i will query 5 posts from category one each having their own add to cart button?
<?php query_posts('cat=1&showposts=5'); ?> <?php while (have_posts()) : the_post(); ?> the image excerpt add to cart
Forum: Plugins
In reply to: [W3 Total Cache] WP-PostViews and W3 Total CacheHaving this problem too
Forum: Plugins
In reply to: [All-In-One Security (AIOS) – Security and Firewall] DDOS AttackYes it does made my load low so far i love it. This will do.
Forum: Fixing WordPress
In reply to: Using rewind_posts for displaying multiple categories@that will only display the first category you called from in_category, what i want to achieve is to display all of these categories 2 each and going randomly.
I found a solution but the problem is i cant list it by twos with the category title because they act like a whole one set of queries so i cant combine the cat title and the two posts from the query
Functions*
function get_posts_for_cat_ordered( $cats = array(), $posts_per_cat = 2 ) { if ( empty($cats) ) return false; $args = array('posts_per_page' => 99, 'category__in' => $cats, 'orderby' => 'rand'); $q = new WP_Query( $args ); $posts_ordered = array(); $done = 0; while ( $q->have_posts() ) : $q->the_post(); global $post; $cats = get_the_category(); $cat = array_shift( $cats ); if ( ! isset($posts_ordered[$cat->slug]) ) $posts_ordered[$cat->slug] = array('term' => $cat); if ( ! isset($posts_ordered[$cat->slug]['posts']) ) $posts_ordered[$cat->slug]['posts'] = array(); if ( count($posts_ordered[$cat->slug]['posts']) == $posts_per_cat ) { $done++; if ( $done == count($cats) ) return $posts_ordered; continue; } $posts_ordered[$cat->slug]['posts'][] = $post; endwhile; wp_reset_postdata(); return $posts_ordered; }
$cats = array(12, 13, 14); $posts_per_category = 2; $posts_ordered = get_posts_for_cat_ordered( $cats, $posts_per_category ); if ( ! empty($posts_ordered) ) { foreach ( $posts_ordered as $loop_data) { // Example category heading echo '<h2><a href="' . get_term_link($loop_data['term'], 'category') . '">' . $loop_data['term']->name . '</a></h2>'; global $post; foreach ( $loop_data['posts'] as $post) { setup_postdata($post); ?> <!-- Example post content --> <?php the_title(); ?><br /> <?php the_content(); ?><br /> <?php } wp_reset_postdata(); } }
Also it doesnt work on posts with two categories or more..
Forum: Fixing WordPress
In reply to: A lot of WP_Query on home page.ill be closing this topic now.
Forum: Fixing WordPress
In reply to: A lot of WP_Query on home page.For the forum and for wordpress community i found a new way i got this from wordpress answers made by a member called G.M
if functions.php create a function like this:
function get_posts_for_cat_ordered( $cats = array(), $posts_per_cat = 2 ) { if ( empty($cats) ) return false; $q = new WP_Query( array('posts_per_page' => 99, 'category__in' => $cats) ); $posts_ordered = array(); $done = 0; while ( $q->have_posts() ) : $q->the_post(); global $post; $cats = get_the_category(); $cat = array_shift( $cats ); if ( ! isset($posts_ordered[$cat->slug]) ) $posts_ordered[$cat->slug] = array('term' => $cat); if ( ! isset($posts_ordered[$cat->slug]['posts']) ) $posts_ordered[$cat->slug]['posts'] = array(); if ( count($posts_ordered[$cat->slug]['posts']) == $posts_per_cat ) { $done++; if ( $done == count($cats) ) return $posts_ordered; continue; } $posts_ordered[$cat->slug]['posts'][] = $post; endwhile; wp_reset_postdata(); return $posts_ordered; }
This function take an array of categories and a number of post you want retrieve for every category and return a multidimensional array with posts ordered per category.
After that use the function just created like so:
$cats = array(12, 13, 14); $posts_per_category = 2; $posts_ordered = get_posts_for_cat_ordered( $cats, $posts_per_category ); if ( ! empty($posts_ordered) ) { foreach ( $posts_ordered as $loop_data) { // Example category heading echo '<h2>' . $loop_data['term']->name . '</h2>'; global $post; foreach ( $loop_data['posts'] as $post) { setup_postdata($post); ?> <!-- Example post content --> <?php the_title(); ?><br /> <?php the_content(); ?><br /> <?php } wp_reset_postdata(); } }
Possible issues:
If a post has more than one category this code may not worked as expected. But a little change in the get_posts_for_cat_ordered function can solve this issue. However, if you don’t need this feature, leave code as is, because is more performant.
Another issues can happen if in the blog there is no enough posts for each wanted category inside the last 99 posts. This is for the ‘posts_per_page’ => 99 argument in the query used in the get_posts_for_cat_ordered function. I’ve used that number because is a reasonable high number, and if the blog has thousands of posts the fucntion will not affect performance.
Both these issues will not stop the function to work, but the showed posts can be less than expected if the described situations will occur.
Can you look at it seems to be working on mine.
Forum: Fixing WordPress
In reply to: Using rewind_posts for displaying multiple categoriesThats what i have now. Isnt that a lot of load for around 5 same queries? Am i still on the right track?
Forum: Fixing WordPress
In reply to: A lot of WP_Query on home page.Hello the rewind_posts doesnt seem to be following my first wp_query?
Forum: Fixing WordPress
In reply to: A lot of WP_Query on home page.Hello im having a bit problem with ending the statement
you called in_category so i have to end it with <?php } ?> but after that the <?php endwhile; endif; ?> is giving me errors
Parse error: syntax error, unexpected 'endif' (T_ENDIF) in C:\xampp\htdocs\----\----\----\-------\index.php on line 603
Can you help me on this last one thanks?!
Forum: Fixing WordPress
In reply to: A lot of WP_Query on home page.<?php $original = new WP_Query(); $original ->query('cat=12,13,14&showposts=2');?> <?php while ($original ->have_posts()) : $original ->the_post(); ?> <!-- See if the current post is in category 3. --> <?php if ( in_category('12') ) { ?> <?php the_content(); ?> <?php } ?> <?php rewind_posts(); ?> <?php while (have_posts()) : the_post(); ?> <?php if ( in_category('13') ) { ?> <?php the_content(); ?> <?php endwhile; ?> <?php rewind_posts(); ?> <?php if ( in_category('14') ) { ?> <?php while (have_posts()) : the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> <?php rewind_posts(); ?> <?php if ( in_category('15') ) { ?> <?php while (have_posts()) : the_post(); ?> <?php the_content(); ?> <?php endwhile; ?>
Will it look like this? Will this work?