How do I use this API? I can extract some data, but not all of it... I'm a bit lost and I can't find any examples in the documentation. I'm using gapi.class.php.
I have code such as:
$ga = new gapi('user','pwd');
$ga->requestReportData('id',array('browser'),array('pageviews','visits', 'timeOnSite'));
var_dump($ga);
foreach($ga->getResults() as $result)
{
print_r($result);
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
echo 'Time On site: ' . $result->getTimeOnSite() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
The above is working, but then I also want to get other data such as goals... I see this: http://code.google.com/intl/es-ES/apis/analytics/docs/gdata/dimsmets/dimsmets.html
but I'm not really sure how to call each function, or property... I'm really lost, any examples would be appreciated!
GAPI uses magic get methods. You put in the dimensions and metrics that you want and get them using the magic get methods.
For example:
$ga = new gapi('user','pwd');
$ga->requestReportData('id',array('browser'),array('pageviews','visits', 'timeOnSite'));
foreach($ga->getResults() as $result)
{
print_r($result);
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
echo 'Time On site: ' . $result->getTimeOnSite() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
array('browser') is the dimension and array('pageviews','visits', 'timeOnSite') are the metrics. $result->getPageviews() is the magic get method for the pageviews metric.
So, refer to the list and put in the dimensions and metrics you want then return them using the magic get methods of getYourdimension or getYourmetric. Note that get is lowercase and the dimension or metric begins with a capital letter.
See the documentation for more information:
Access metrics and dimensions using magic get methods
With GAPI, when data is returned from Google it is automatically converted into a native PHP object, with an interface to allow the 'get' the value of any dimesion or metric.
For example, if you request the metric 'uniquePageviews' and the dimesion 'pagePath' you can do the following:
foreach($ga->getResults() as $result)
{
echo $result->getUniquePageviews();
echo $result->getPagePath();
}
Related
am just confused why such a small difference can make a big problem.
here is the working code with just digits entered into it.
$user_info = get_userdata(70);
echo 'Username: ' . $user_info->user_login . "\n";
this code shows username: sarah
and now same but this time with code inside of it
$number = the_author_meta('ID');
echo $number; // echos 70
$user_info = get_userdata($number);
echo 'Username: ' . $user_info->user_login . "\n";
and with the code below it just shows userame: thats it.
MAke sure you read your code. At this line:
$user_info = get_userdata($number);
You miss a r in the variable $number
Here's the problem:
Replace "the_author_meta" with "get_the_author_meta"
the_author_meta just immediately outputs to the screen the information you're trying to retrieve. That's why it outputs '70'.. If you get rid of the echo in front of it, it'd STILL output that 70.
get_the_author_meta actually returns the value and assigns it to a variable, like you're expecting.
$aaaaaa = $author_id=$post->post_author;
$user_info = get_userdata($aaaaaa);
echo 'Username: ' . $user_info->user_login . "\n";
echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
echo 'User ID: ' . $user_info->ID . "\n";
echo get_user_option( 'rc_banned', $user_info->ID);
I've seen some variations of this question around, but I've as of yet been unable to tweak them into what I'm looking for.
In a Wordpress post, if an image is uploaded with a caption the image will be output wrapped in a div (with class wp-caption). Perfect.
However, if there is no caption the image is wrapped in a paragraph tag. I'd like to replace this with a div.
So if an image is uploaded without a caption, it is wrapped in a div as well — something like class="wp-nocaption".
My first try was to modify the media.php file. I changed this section:
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
to this:
if ( 1 > (int) $width || empty($caption) )
return '<div ' . $id . 'class="wp-nocaption ' . esc_attr($align)
. '" style="width: ' . ($width) . 'px">'
. do_shortcode( $content ) . '</div>';
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '" style="width: ' . ($width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
Which I hoped would do the same thing for a non-captioned image as a captioned one, except the div would have a different class.
But that didn't work. Does anyone have any idea why?
I also found some articles suggesting using a preg_replace function.
http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
https://wordpress.stackexchange.com/questions/7090/stop-wordpress-wrapping-images-in-a-p-tag
I tweaked their functions, attempting to replace paragraph tags that wrap an image wrapped in a link with div tags.
function filter_ptags_on_images($content) {
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU',
'/<div class="wp-nocaption">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/div>/iU',
$content);
}
add_filter('the_content', 'filter_ptags_on_images');
But this doesn't work. I've been reading a lot but still can't wrap my head around the php concept of "backreference". I know the replace section of my function is wrong, but I'm not sure how to fix it.
If you have any suggestions as to what I'm doing wrong on either way would be very much appreciated!
Thank you so much!!
I am trying to get field_1 value into the input text and I tried this code but it doesn't work.
function bbg_add_reg_field() {
$field_1= $_POST["signup_username"];
echo '<input name="field_1" id="field_1" value="$field_1" type="text">';
}
add_action( 'bp_before_registration_submit_buttons', 'bbg_add_reg_field' );
The echo value shown inside the input text is $field_1
The value should be a name, say for example peter.
In PHP you can interpolate a string (add variables to a string with $var) only when it is a double quoted string.
From the PHP Documentation
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';
Instead you could do this
echo '<input name="field_1" id="field_1" value="' . $field_1 . '" type="text">';
oh and don't forget htmlspecialchars
echo '<input name="field_1" id="field_1" value="' . htmlspecialchars($field_1) . '" type="text">';
You could also achieve the same using PHP Heredoc. Which goes like this
echo <<<EOF
<input name="field_1" id="field_1" value="$field_1" type="text">
EOF;
i am using this to automatic display the rss in the header.php
automatic_feed_links();
in the header appears feed=rss2 and feed=comments-rss2
now i just want to disable the comments-rss2 since i dont use comments in the theme.
if i use remove_action( 'wp_head', 'feed_links', 2 ); both are removed from the head.
I just want to remove the comments-rss2 -
couldnt find any reference how to this.
anyone know?
feed_links function in wp-includes/general-template.php contains echo command for both feed and not be able to disable with argument. Comment out // this line: (wp-includes/general-template.php #1614 for wp3.1)
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
To get a list of a content type's cck fields, I was hoping to use:
drupal_get_schema('content_type_mycontenttype');
but that leaves out fields with multiple values. Is there a simple call to use to get such a list?
Take a look at the content_fields function, and if doesn't that have the information you need, there is _content_type_info.
Additionally, once you have the field information, you can extract the table storage and column names using content_database_info.
For Drupal 7, check out the field_info_instances function to retrieve a list of fields for a particular node content type.
Here is an example usage that will retrieve all the fields for a node content type.
$my_content_type_fields = field_info_instances("node", "my_node_content_type");
I've used something like this before to do a quick list of CCK Field information for a content type:
$mytype = 'article';
$contentinfo = _content_type_info();
$output .= "<ul>";
foreach($contentinfo['fields'] as $field) {
if ($field['type_name'] == $mytype) {
$output .= '<li id="field-' . $field['field_name'] . '">' . $field['widget']['label'] . '<br>';
if ($field['widget']['description']) {
$output .= $field['widget']['description'] . '<br>';
}
$output .= '<ul>
<li>Content Types: ' . $field['type_name'] . '</li>
<li>Type: ' . $field['type'] . '</li>
<li>' . $field['field_name'] . '</li>
</ul>';
}
}
$output .= '</ul>';