I have a basic php script that gets my last 30 instagram pictures. It just uses the media/recent endpoint url.. That works fine.
Looks like this
$userid = "ID";
$accessToken = "ACCESSTOKEN";
// Gets data
function fetchData($url){
$ch = curl_init();
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);
return $result;
}
// Pulls and parses data.
$result = fetchData("https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}&count=30");
$result = json_decode($result);
And echo the output like this:
<?= $post->images->standard_resolution->url ?>
But how can I put the endpoint url's in a array and be able to echo comments and likes in the same way..
I've tried using instaphp, but it's really slow and creates an access token for each visit..
If you have the full result set, you should be able to get things this way:
Likes:
<?= $post->likes->count ?>
<?= $post->likes->data->username ?>
<?= $post->likes->data->full_name ?>
<?= $post->likes->data->id ?>
<?= $post->likes->data->profile_picture ?>
Comments:
<?= $post->comments->count ?>
etc
Check out the documentation for the response: http://instagram.com/developer/endpoints/users/#get_users_media_recent
Related
Im trying to file_get_contents from a website but it outputs strange characters like ��}�r�H��ߙ�y��M���n�'2I��"�^ÏjI-[D������T��8�w��|��-Y
<?
echo file_get_contents("http://mp3yum.top");
?>
Is there any way to scrape some content from this site.
You need to use the CURL before calling to the external source.
$data = get_url('http://mp3yum.top');
echo($data);
function get_url($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
Output Screen:
I have looked all over Google, trying to figure this out. I've made some progress but still stuck. I'm pretty new to ACF and custom post types. I have a custom post type of Attorneys that I setup through WCK. That post type has a field group with field names of attorney_photo, attorney_name and attorney_areas_of_practice. With the code below, I can get the attorney_name and attorney_areas_of_practice (repeater field) to display, but not the attorney_photo. I have the info displaying correctly on each attorneys specific page, but I need this page to be a listing of all the attorneys. Not sure what I am doing wrong with the image part.
<?php get_header(); ?>
<?php
$args = array(
'posts_per_page' => 30,
'order' => 'ASC',
'orderby' => 'title',
'post_type' => 'attorneys'
);
query_posts($args);
if ( have_posts() ) :
?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="attorney-preview">
<?php $photo = get_post_meta($post->ID,'attorney_photo', true); ?>
<img src="<?php echo $photo; ?>" />
<p><strong><?php echo get_post_meta($post->ID,'attorney_name', true); ?></strong></p>
<ul>
<?php
while ( have_rows('attorney_areas_of_practice') ) : the_row();
$attorney_area_of_practice = get_sub_field('attorney_area_of_practice');
echo "<li>" . $attorney_area_of_practice . "</li>";
endwhile;
?>
</ul>
</div><!-- .attorney-preview -->
<?php endwhile; ?>
<?php endif; ?>
<?php
wp_reset_query(); // Restore global post data stomped by the_post().
?>
<?php get_footer(); ?>
When you add image field through ACF plugin there are some options of return value. For example return value is: image object or return value is: image url, in your case return value might be selected as image object, not image url. That is why here with your code is being returned an array rather than only url. To get only image url from this array, please write as following a bit change:
<?php $photo = get_post_meta($post->ID,'attorney_photo', true); ?>
<img src="<?php echo $photo['url']; ?>" />
Try this
<?php query_posts(array('posts_per_page' => 30,'order' => 'ASC','orderby' => 'title','post_type' => 'attorneys'));
if (have_posts()) : while (have_posts()) : the_post();
$attorney_photo = get_post_meta($post->ID, 'attorney_photo', true);
$attorney_name = get_post_meta($post->ID, 'attorney_name', true); ?>
<div class="attorney-preview">
<img src="<?php echo $attorney_photo; ?>" />
<p><strong><?php echo $attorney_name; ?></strong></p>
<ul>
<?php
while ( have_rows('attorney_areas_of_practice') ) : the_row();
$attorney_area_of_practice = get_sub_field('attorney_area_of_practice');
echo "<li>" . $attorney_area_of_practice . "</li>";
endwhile;
?>
</ul>
</div><!-- .attorney-preview -->
<?php endwhile; endif; ?>
<?php
wp_reset_query(); // Restore global post data stomped by the_post().
?>
zero.php
<?php
$q = $_GET['id'];
echo = $q
?>
this code is not working, Help me!
I am not using .htaccess in this.
Try this.
<?php
$q = $_GET['value'];
echo $q;
Your syntax is significantly off.
Have you tried?
<?php
$q = $_GET['id'];
echo $q;
?>
and of course this is assuming that there is a GET parameter called id it is being passed so a even better solution would be to check to see if it is defined first.
<?php
if (isset($_GET['id'])) {
$q = $_GET['id'];
echo $q;
} else {
echo "ID PARAMETER NOT SET";
}
?>
Edited: Answered below.
I'm using the following query to paginate my posts on a Custom Page template that pulls a Custom Post type. this exact code works on Author.php, but this custom template Page, "Filmmaking" does not show the pagination. I have a simple, tried and true pagination function after my loop. Why would it work for author.php, but not for page-filmmaking.php?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$film_query = array(
'post_type' => 'filmmaking', // Custom Post Type
'paged' => $paged, // Set it up to be paged so you can use pagination
'posts_per_page' => 2, // How many to show per page
);
// The Query
$the_query = new WP_Query( $film_query );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
Answer: Get rid of if has_posts.
Working Code:
<?php
/**
* Template Name: pagination test
*/
get_header(); ?>
<?php //get_sidebar(); ?>
<div id="page-left">
<?php
$wp_query = new WP_Query();
$wp_query->query(array(
'post_type'=>'filmmaking',
'paged' => $paged,
'posts_per_page' => 2,
));
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php previous_posts_link('« Nyare') ?>
<?php next_posts_link(' Äldre »') ?>
</div><!-- page left -->
<?php get_footer(); ?>
I am trying to read an excel file and render it as a html table. I would like to get the style that has been applied in excel to a cell and render it in html as well. For example, some cells may have text in BOLD, how do I get that information and use it in the most efficient way?
This is the code I have so far (I am trying out PHPExcel the first time so I am eager to hear any comments or improvements I can make to this):
if ($_GET["xls"]) {
require_once("classes/PHPExcel.php");
$objPHPExcel = PHPExcel_IOFactory::load( dirname(__FILE__) . "/demo.xls" );
$sheetData = $objPHPExcel->getSheetByName('Sheet1')->toArray(null,true,true,true);
?>
<?php if ( count($sheetData) < 0) : ?>
<table class="table striped">
<?php foreach( $sheetData as $y => $row ) : ?>
<tr>
<?php foreach ( $row as $x => $cell) : ?>
<?php if ( $x === "A" ) : ?>
<th><?php echo $cell; ?></th>
<?php else : ?>
<td><?php echo $cell; ?></td>
<?php endif; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php
}
Why not take a look at PHPExcel's existing HTML Writer: that already handles merged cells, cell formatting (including borders), font styles, etc.
It seems that the following code works:
$objPHPExcel->getSheetByName('Sheet1')->getStyle("B13")->getFont()->getBold()