Parse error: syntax error, unexpected end of file

I just want to add to the two answers given on this matter. It is important to know that if you use if($the_query->have_posts() ) : you will need to close that with endif; otherwise you will also get the same parse error as described.

Widget that shows categories with posts numbers

There is no coding involved here. WordPress has already a build in widget for this function. If you go to the “Widgets” screen. you’ll see that there are a widget called Categories You can drag and drop that to your sidebar where you need to display the widget. When you’ve done that, the widget will … Read more

Update post title from external file?

Sometimes I use this code when I want to run WordPress externally. update.php function find_wordpress_base_path() { $dir = dirname(__FILE__); do { //it is possible to check for other files here if( file_exists($dir.”/wp-config.php”) ) { return $dir; } } while( $dir = realpath(“$dir/..”) ); return null; } define( ‘BASE_PATH’, find_wordpress_base_path().”https://wordpress.stackexchange.com/” ); define(‘WP_USE_THEMES’, false); global $wp, $wp_query, … Read more

Add field to user meta table in database when link is clicked

Personally, I would store the post IDs (as opposed to URLs). Something like: function wpse_143643_add_user_bookmark() { if ( ! empty( $_GET[‘bookmark’] ) && is_singular() && is_user_logged_in() ) { if ( ! $bookmarks = get_user_meta( $user_id = get_current_user_id(), ‘bookmarks’, true ) ) $bookmarks = array(); $bookmarks[] = get_queried_object_id(); $bookmarks = array_unique( $bookmarks ); update_user_meta( $user_id, ‘bookmarks’, … Read more

Post list display year wise

I don’t like recommending a plugin, but this plugin does exactly what you need, and it is the easiest way to go. Just before I start, I would like to state that I don’t have any affiliation regarding the plugin or its authors, nor am I marketing or trying to market the plugin in any … Read more

Display an authors post on a single page only when they are logged in

Check if a user is logged in using is_logged_in. If a user is logged in modify the query using pre_get_posts filtering posts by the current author ID. if ( is_user_logged_in() ) : function filter_posts_by_author( $query ) { global $current_user; get_currentuserinfo(); $query->set( ‘author’, $current_user->ID ); } add_action( ‘pre_get_posts’, ‘filter_posts_by_author’ ); // … loop else : echo … Read more