Hot answers tagged

48

If by 'blog page' you meant a static page set as posts page in the Reading Settings, then you could check it by doing this: if ( is_front_page() && is_home() ) { // Default homepage } elseif ( is_front_page() ) { // static homepage } elseif ( is_home() ) { // blog page } else { //everyting else } When you use is_home() and is_front_page(),...


21

You can use the following in your themes functions.php file: function is_blog () { return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag()) && 'post' == get_post_type(); } And then put this in the file you are checking: <?php if (is_blog()) { echo 'You are on a blog page'; } ?> You can use Hooks in ...


14

If by 'blog page' you meant a static page set as posts page in the Reading: global $wp_query; if ( isset( $wp_query ) && (bool) $wp_query->is_posts_page ) { //static blog page } PS. This solution also works on template_redirect action


14

In WordPress 4.2 the editor was removed on whichever page was assigned to show Latest Posts for whatever reason. The following function below ( original solution found here by crgeary ) will re-add the editor and remove the notification: You are currently editing the page that shows your latest posts. Here's some information on the hooks used: ...


6

A reverse proxy could work, such as varnish or nginx. Using varnish as an example: backend blog { .host = "blog-server-ip"; } backend default { .host = "current-domain-ip"; } sub vcl_recv { if (req.rul ~ "^/blog/") { req.backend = blog; } }


6

You are using get_the_content() wrong, it can't take a ID, which is what get_option('page_for_posts') does return, and generally gets the content of the current post inside the loop, in which it has to be used. To get the actual content of that page you can do: $page_for_posts_id = get_option( 'page_for_posts' ); $page_for_posts_obj = get_post( $...


6

The function get_the_time is only designed to work either in the main WordPress loop or a custom loop using WP_Query, so the way you are using it won't work correctly. The following is the right way to use it, using a custom WP_Query loop: <?php // Get years that have posts $years = $wpdb->get_results( "SELECT DISTINCT YEAR(post_date) AS year FROM $...


6

This is because you call get_header() which already require your theme header.php, in which the meta tags are defined. You should learn how to use get_header() in the Wordpress Codex To summarize: You must rename your wp-blog-header.php file to header-blog.php and place it in your wordpress theme directory. Then you can require it using this function : ...


5

There is even an example in the WordPress codex here for this: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-3,-8' ); } } add_action( 'pre_get_posts', 'exclude_category' ); Just modify the ...


5

An AJAX request is a new request to the server, and it is a request to admin-ajax.php. That is not a single post page. Any logic that depends on is_single() or any other page level template tags like it, won't work. If your AJAX callback needs that sort of information you must pass it to that callback in your AJAX request-- something like: function ...


5

It's been a while, but I came across this topic while looking for a way to enable gutenberg editor on the Blog Page. Didn't find any clue in google, so I dived into wordpress code and found the solution. Here is the code: add_filter( 'replace_editor', 'enable_gutenberg_editor_for_blog_page', 10, 2 ); /** * Simulate non-empty content to enable Gutenberg ...


4

index.php and archive.php might be the same but don't have to be the same. index.php will display your blog post archive and in the absence of archive.php (or other more specific archive files) it will display your date, author, etc. archives as well. But it doesn't have to. You can, if you want, display your archived differently that your main blog index. ...


4

The very broad answer for why this doesn't work is that the internet is stateless. Basically each request for a page is a separate and unique instance from other page requests. Example Let's say post-1 is in category-1 and category-2. When Wordpress loads post-1 on single.php it has no way of knowing how the user arrived at the page. It only knows that ...


4

There are a couple of things I don't understand here, but I'll try answering them as I go along. You have a home.php, which I assume is your default homepage. You have one line of code in there, and that is to call a another page template. Here is you code <?php require dirname( __FILE__ ) . '/blog-page.php'; In blog-page.php you have the complete ...


4

A better way to to do this is to instead of a subdirectory, use a subdomain like blog.website.com. The reason for this is that a DNS record can be made to the other server for the subdomain, which is not possible with subdirectories. A subdirectory is possible, but you would have to use frames, a .htaccess redirect or another way which is totally not stable ...


4

You have custom filter in a plugin or in your theme that is messing with WP_Query. Your issue is that something is setting is_home to false. This is not default behavior, by default, is_home should return true in any custom instance of WP_Query. is_home is one of the contributing factors which is responsible for setting up sticky posts at the top in a ...


4

I'm pretty sure that is_singular() is going to return false when you are inside the WP loop, since there are more than one posts being looped through. Try is_single() or just look at the post object and examine the post_type attribute. add_filter( 'the_content', '_some_func', 15 ); function _some_func( $content ) { if( __check_paragraph_count_blog( $...


3

Create an empty page with the slug blog. Go to Settings/Reading and set that page as Posts page. Go to Settings/Permalinks and set the URL pattern to /blog/%postname%/. That should do it.


3

I don't know if I'm covering everywhere the post functionality is linked from, but adding the following code to functions.php should at least remove the comments links from the administration menu, the toolbar, and the dashboard: add_action( 'admin_menu', 'remove_admin_menus' ); add_action( 'wp_before_admin_bar_render', 'remove_toolbar_menus' ); add_action( ...


3

Create a page with a custom page template, then create a custom WP_Query object to return your last posts. You can get something like: <?php /* Template Name: Blog Page */ get_header(); $args = array( 'post_type' => 'any', #all post types 'posts_per_page' => 10 #get 10 posts ); $query = new WP_Query( $args ); if($query->have_posts()): ...


3

There are many options. Subscribe2 is very popular, although I've never been a fan. http://subscribe2.wordpress.com/ MailChimp and FeedBurner both offer RSS to Email delivery which can be used for this as well. JetPack includes a subscribe to new posts function as well: http://jetpack.me/2011/11/29/how-to-use-email-subscriptions-in-jetpack-1-2/


3

You need to use the_content instead of the_excerpt when you display your 'single' post. If you would post your code, you might get a more detailed answer.


3

To get the blog index page, I found that if ( !is_front_page() && is_home() ) { // blog page } is not working for me, I had to use the get_option('page_for_posts') function to identify the Blog Page post_id, my answer is if ( !is_front_page() && is_home() ){ if ( empty ( $post_id) ) { global $post; $post_id = ...


3

When you make a page the page for posts, it's no longer a "page" in the conventional sense. Refer to the Template Hierarchy for home page display- the quickest fix is to rename your blog template home.php, and WordPress will load that before index.php.


3

The is_active_sidebar('Test'); function works correctly if the correct slug is used. I think that the problem is that you are constructing the sidebar ID like this: $sidebarID = preg_replace("/[\s_]/", "-", strtolower($page->post_title)); Then prepending sidebar- to it ... register_sidebar(array( 'name' => $page->...


3

There are Conditional Tags for this: is_archive() and is_category() respectively. For a custom post type archives you could use is_post_type_archive(). There are many conditional tags available, see above linked codex page. To determine the blog archive you have to additionally check for the post type post, take a look at this question and the answers for ...


3

The first option (/blog/) is the easiest: create a new blank page called "Blog" navigate to "Settings > Reading" and choose this new page as the value in the "Posts Page" drop-down Now, when you navigate to the new "Blog" page (which should be at /blog/ unless there is something unusual about your setup), all Posts are displayed, the most recent first.


3

First things first, avoid defining functions inside functions. PHP doesn't have a problem with it, but it's usually a sign you're "doing it wrong" and it just leads to unnecessary headaches. Second, your foreach loop at the bottom is a little malformed. You need to define the <ul> outside the loop, and then append to $html - otherwise you just end up ...


3

The standard query for posts uses orderby => 'post_date' and order => 'DESC'. The best candidate for arbitrary sort of posts would be orderby => 'menu_order' and order => 'ASC'. The menu_order is not generally used for posts but it is safe to be used. As suggested by Pieter Goosen use action hook pre_get_posts: add_action( 'pre_get_posts', '...


3

There is no conditional tag for the blog page. You have to use both is_home() and is_front_page() to detect this page When you use is_home() and is_front_page(), you have to use them in the right order to avoid bugs and to test every user configuration: <?php if ( is_front_page() && is_home() ) { // blog listings } elseif ( is_front_page() ) { /...


Only top voted, non community-wiki answers of a minimum length are eligible