tormorten
Forum Replies Created
-
Forum: Hacks
In reply to: Increasing Post per page LimitHave you checked for any errors?
A good pointer in such situations is to turn
WP_DEBUG
totrue
in yourwp-config.php
. Usually it will tell you how it’s feeling if something is hurting.Forum: Hacks
In reply to: Changing the excerpt to first paragraph and first imageFor this you would need to remove the default trimming filter in WordPress.
You could try this:
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); add_filter( 'get_the_excerpt', function( $excerpt ) { $string = substr($excerpt,0, strpos($excerpt, "</p>") + 4); return $excerpt; } );
I have not tested it, but it should do something close to what you’re asking.
Forum: Hacks
In reply to: Insert the_title(); into shortcodeHi,
Try using
get_the_title()
instead.the_title()
prints it’s contents,get_the_title()
does not.Forum: Hacks
In reply to: get_permalink post id outside loopHi,
Using the
get_queried_object_id()
-function is indeed an option here. Beer in mind that this will fetch the ID even if its a term/archive/other.You could do it like this:
<?php if( isset( get_queried_object()->ID ) ) : ?> <script type="text/javascript" charset="utf-8" >var bShareOpt = {url: "<?php echo get_permalink( get_queried_object()->ID ); ?>"};</script> <?php endif; ?>
You should also check out the
wp_localize_script()
-function, which can be used to pass parameters from PHP to your Javascript.Forum: Hacks
In reply to: Swipe to next/previous postsI’ve used the TouchSwipe library on several occations for this kind of stuff.
Have you checked it out?
Forum: Hacks
In reply to: how can I display blog items on a php page outside of wordpress?Hi,
Try using
the_time()
instead of the date.And,
start_wp()
has been deprecated for a long time. Usesetup_postdata($post);
instead.Forum: Hacks
In reply to: how can I display blog items on a php page outside of wordpress?Hi,
You can include WordPress’ core functions (and the query methods) by including
wp-blog-header.php
, in your caseblog/wp-blog-header.php
. This will allow you to use WordPress’get_posts()
function. Hence enabling you to get your 3 posts outside of WordPress.Either that, or you can query the database for the table
wp_posts
and specifying the post typepost
using PHP’s mysql/mysqli-functions.A third option would be to use your sites RSS-feed (https://yoursite.com/blog/feed) and parsing it (perhaps with SimplePie)
Forum: Plugins
In reply to: [Font Awesome Field] Looks good. Perhaps also for custom post types?Hi Jack,
Thanks for your feedback.
You can limit the post types it it availiable for by inserting this snippet into your theme:
add_filter( 'fa_post_types', 'my_fa_post_types', 20, 1 ); function my_fa_post_types( $post_types ) { return array( 'my-custom-post-type-slug' ); }
By default the plugin is set to look for all public post types.
Hope this helps.
Tor Morten
Forum: Plugins
In reply to: [Font Awesome Field] Metabox only on pages.Hi,
You can put this snippet in your theme’s functions.php:
add_filter( 'fa_post_types', 'my_fa_post_types', 20, 1 ); function my_fa_post_types( $post_types ) { return array( 'page' ); }
Forum: Hacks
In reply to: Building plugin update apiHi,
You could see how it is done in this plugin updater. I use this myself, and it works with all of my plugins together.
https://github.com/YahnisElsts/plugin-update-checkerForum: Hacks
In reply to: Can I get the date/time of a post's updated taxonomy?Since a taxonomy doesn’t have a “last changed”-field, you’d actually have to query the posts in the taxonomy to figure out if anything has changed.
Forum: Hacks
In reply to: Can I get the date/time of a post's updated taxonomy?Hi,
You could do it by finding the most recent post in the taxonomy term.
$posts = get_posts('post_type=any&showposts=1&orderby=date&taxonomy=term');
Forum: Hacks
In reply to: Add user page to custom menue pageWell, unless you are creating a post type, nothing of the sort exists for those pages. Unless you want your post type to display as a sub menu item. You can do this by setting the
show_in_menu
argument inregister_post_type()
to the slug of the parent. E.g.users.php
Forum: Hacks
In reply to: About hooksBasically they’re asking you to create a little piece of code that displays content for 20 seconds, and then it should be removed. Also they want it done via a hook.
For example:
add_action( 'wp_footer', 'remove_content_timer' ); function remove_content_timer() { ?> <script type="text/javascript"> setTimeout(function() { // run the necessary javascript to remove the content }, 20000); // run function after 20000ms </script> <?php }
Forum: Hacks
In reply to: remove editor option for userrole author (and lower)You could do it by actually checking the current users role by so:
add_action( 'admin_init', 'dio_removals' ); function dio_removals() { $current_user = wp_get_current_user(); if ( in_array( 'author', $current_user->roles ) ) { // remove post types remove_post_type_support( 'post', 'editor' ); // remove meta WP version remove_action('wp_head', 'wp_generator'); } }