Adding media support to a timeline plugin (Wordpress) - wordpress

I have installed this plugin -> http://wordpress.org/plugins/wordpress-posts-timeline/ .
With this plugin you can create a post and it displays in a timeline. My problem is that images don't show when inserted in the post box.
I tried modifying the plugin code and put some get_attachment code inside the loop there but unfortunately didn't work.. I can get all images to show, but not by ID of the post.
Youtube support would be nice too, but maybe that gets clear if this question is answered.
Current state -> http://erwin.my89.nl/stage/sieh
// Edit
I have tried alot of code with wp_get_attachment stuff.
<?php
wp_get_attachment_image( $attachment_id, $size, $icon );
?>
&
<?php $uri = wp_get_attachment_image_src( $post->ID, 'medium' );
echo $uri[0];?>
But cant get it to work..
Thanks in advance.

The plugin is stripping HTML tags when building the content:
function timeline_text($limit){
$str = get_the_content('', true, '');
$str = strip_tags($str);
// etc...
You have to add <img> (and others) as an allowed tag on strip_tags():
$str = strip_tags($str, '<img>');

Related

Use a Wordpress Page as a stylesheet?

I'd like to be able to edit my WordPress theme's CSS by using a Page in the backend instead of the default style.css file. I've seen it done before as a page template but I can't seem to figure it out myself.
I'm using WordPress version 4.7.2 on a Multisite. I want the CSS to generate on theme activation, hence using a Page.
I apologize in advance if this is an easy fix and open to other ways to accomplish this. Thanks!
I highly recommend using a plugin, such as https://wordpress.org/plugins/wp-add-custom-css/ or use the WordPress Customizer "Additional CSS" field.
However, to answer your question, this was easy since it's a modified way that I make some pages I load with ajax. You will need to create a page template and that requires FTP and a code editor to create the page and then push it your theme folder (hopefully a child theme or this template will go away when you upgrade).
I named my CSS page template: css-page.php
It requires only the opening php tag.
CODE for template css-page.php
<?php
/**
*
* Template Name: CSS page
* Not a recommended idea.
*
*/
header("Content-type: text/css; charset: UTF-8");
ob_start("compress");
//minify CSS
function compress( $minify ) {
/* remove comments */
$minify = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $minify );
/* remove tabs, spaces, newlines, etc. */
$minify = str_replace( array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $minify );
return $minify;
}
//get the content
if (have_posts()) :
while ( have_posts() ) : the_post();
$content = get_the_content();
$content = wp_filter_nohtml_kses( $content );
echo $content;
endwhile;
endif;
ob_end_flush();
Then in your functions.php file in your child theme (or an include of that file or a custom plugin) paste in the following BUT change it where noted:
Change the value p='3134' to your page id where you're using this template. Change the id="something" to something else or remove it. Useful to have an id or a class for js manipulation.
For functions.php
//Get CSS page contents
function myprefix_page_css() {
echo '<link rel="stylesheet" id="something" href="'. site_url() .'/?p=3134" type="text/css" media="screen">';
}
add_action( 'wp_head', 'myprefix_page_css', 99 );

the_post_thumbnail not working with me

I'm not super familiar with wordpress, but I've been working on getting my layout written as a theme so I can use the wordpress platform. For some reason I can't get the_post_thumbnail function working.
so when use this
the_post_thumbnail(array(100,100));
its show me this error
Illegal offset type in
Have you enabled thumbnails in the functions.php?
In your functions.php, you should add this in order to enable featured thumbnails:
add_theme_support( 'post-thumbnails' );
And then call inside your loop, or inside your while:
<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large', true);
echo $image_url[0];
?>
It will return your featured image URL and then you can echo the $image_url[0] wherever you want.

get contents and permalink base on the specified page title on the query

below is a query where it supposed to get a contents from a page by a specified page title
<?php
$page = get_page_by_title( 'About Us' );
$content = apply_filters('the_content', $page->post_content);
the_content_rss('', TRUE, '', 100);
?>
Read More
and yes its successfully display a content and trim the content by 100, but the problem is the content and permalink is not the content and the permalink of the specified page that I pulled from the query, i mean, the content and permalink is different from the page Im pulling up. Any ideas whats going on? Im trying to play around with the code but seems nothing works at all and also im currently looking on the web for the possible solution but unfortunately, I find nothing.
PS: I just want to display the content and get the permalink of the specified page that im pulling up through the query above.
Could you try the following code?
<?php
$page = get_page_by_title( 'About Us' );
$content = apply_filters('the_content', $post->post_content);
echo substr($content,0,30);
?>
title="Read the whole post" class="rm">Read More
I already figured it out, thanks to everybody here..
my updated code is
<?php
$page = get_page_by_title( 'About Us' );
$content = apply_filters('the_content', $page->post_content);
echo wp_trim_words( $content, 100, '');
?>
Read More

How to show tag/skill type to a dynamic post in Wordpress theme Classica

I use this theme:
http://demo.themezilla.com/?theme=classica
Under the "recent projects" i want each posted portfolio post to display what kind of tag/skill-type it is connected to. This can be checked in the wp-admin page when you create a new portfolio post. I don't know what function i need to write in php to make this work.
Is there any easy way to solve this like when you show a posts excerpt?
<?php the_excerpt(); ?
I think you can use like this.
<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
If it's stored as a custom variable (appears below the post content when editing it in the admin panel), you can usually access it like so:
get_post_meta($post->ID, 'key_name_here', true);
Check out the get_post_meta() Code Page for more details on the function.
Use get_the_term_list() to get the skill-type and strip_tags() to remove the links
$terms = get_the_term_list( $post->ID,'skill-type', '', ', ','' );
$terms = strip_tags( $terms );

Wordpress shortcode not working

I built a very unique and javascript intensive theme for wordpress and now shortcodes do not work. I do not have any plugins installed, so it's not that. What did I drop from my wordpress template files that is required to use shortcodes (ie: [gallery]).
I understand how to make shortcodes, but how does WP take your post and replace "[gallery]" when it is spitting it back out for display?
EDIT:
here is what I'm currently working with:
$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
$i = 1;
foreach ($pagepull as $single_page){
echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">";
echo $single_page['post_content'];
$i++;
// more code that is irrelevant...
// more code that is irrelevant...
// more code that is irrelevant...
}
Ok, try this
$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
$i = 1;
foreach ($pagepull as $single_page){
echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">";
echo apply_filters('the_content',$single_page['post_content']);
$i++;
Wordpress take your content and apply filters to it. You must register a filter and let parse your content.
If your theme is not displaying your shortcodes, probabily you output the content of the post without let Wordpress filter it.
Calling the function get_the_content() for a post, does not run the filter for shortcodes (if any).
To have apply
<?php apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file )) ?>
Ref: http://codex.wordpress.org/Function_Reference/get_the_content
Note: many plugins register filters with the content to implement shortcodes!
My solution was replacing
<?= get_the_content() ?>
with
<?= the_content() ?>
which, as keatch already mentioned, applies filters before returning content.
Read this carefully about the_content
use this if you want the content inside a variable:
ob_start();
the_content();
$content = ob_get_clean();
now you could just do echo $content; or use regex or whatever you want to make the content look like how you want it.
I had the same issue.
Shortcodes depends on WP Loop, but that's a different issue. To make a long story short, I've added the_post(); at the page that should be showing the shortcode (for example articles.php).
Also, make sure that you are using the_content() in order to display the text (using $post->post_data for example won't show you shortcodes).
Please use the
ob_start();
in the starting of function and use
return ob_get_clean();
before closing the function.
Hope this will help full for you.
Cheers

Resources