New answers tagged

1

Solution: Use a temporary file – with a unique file name After a lot of jumps and crawling into the dirtiest corners of PHP, I rephrased the question to just: How can one trick PHP into returning TRUE for file_exists( $file )? as the code in core just is file_exists( apply_filters( 'comments_template', $template ) ) Then the question was solved ...


2

I have wrestled with this before and my solution was — it can knock itself out requiring file, as long as it doesn't do anything. Here is relevant code from my Meadow templating project: public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) { try { $env->loadTemplate( ...


3

Not sure the following solution is better than the solution in OP, let's just say is an alternative, probably more hackish, solution. I think you can use a PHP exception to stop WordPress execution when 'comments_template' filter is applied. You can use a custom exception class as a DTO to carry the template. This is a draft for the excepion: class ...


0

Static pages: Valid? Yes. You absolutely can add static pages that have nothing to do with a blog aside from using WordPress "routing" API out of the box and the database. Styles, Script: How? Simply add your custom styles and scripts to your theme. Then register and enqueue them. You can add your own Page Templates. Since WP 3.4 the actual page template ...


2

1 If you look at the source code of get_the_title you will see that there is no difference between the two ways of writing the same thing, because if you call it without a parameter it is supposed to be the current ID. 2 There is no substantial difference between the two loops you use. All go through the same amount of items and do the same thing with it. ...


1

You could do this with custom shortcodes or in some plugins with saved layouts. Many pagebuilder give the option to save predefined layouts. Try out this plugin if you want to create the predefined layouts programmatically. https://github.com/WebDevStudios/WDS-Simple-Page-Builder


0

If you're already experienced with HTML & CSS, then I'd suggest starting by building pages the way you'd like them and then looking at https://codex.wordpress.org/Template_Tags to see how you can replace key sections of the pages dynamically from WordPress.


2

/YOUR_THEME/page-templates/ will only work for custom page templates assigned on the admin page edit screen, not for page-$slug or page-$id named templates. The correct filter hook in my view is page_template, but you don't (I assume!) want to throw out any other possible templates for your pages, not least because you're bound to have some pages on your ...


0

WordPress will recognize template files in /YOUR_THEME/page-templates/: https://developer.wordpress.org/themes/basics/organizing-theme-files/#page-templates-folder


-1

Edit: Use glob() to find the templates and hook into pre_get_posts() Add this to your functions.php function my_awesome_templates ( $query ) { // Only filter the main query on the front-end if ( is_admin() || ! $query->is_main_query() ) { return; } // Get an array of all files that match the pattern 'page-*.php' from your ...


0

Why not build a blog style website first? If you're new to WordPress, it's better to start with something relatively easy, where there are lots of tutorials for. Practicing will give you the skills to reach for something higher, like the list of ambitions you give. If you need all those things you say right now, you're better of with buying a decent ...


1

Something went wrong with your installation. As commented by @Sumit get_header() is a core function and cannot be undefined. To troubleshoot: Reinstall WordPress and enable WP_DEBUG in wp_config.php: define( 'WP_DEBUG', true ); If it is on a live site you might want to use this instead: define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false ...


4

That's because the main query is being discarded and replaced with your custom query. You've not told your custom query to look for that tag, so why would it? You might also notice your pagination is broken for the same reason, you've not told the new query which page you're on, so why would it pull the right page? What's more, that main query is expensive! ...


1

Within the wp_get_document_title() function we have: // If it's a search, use a dynamic search results title. } elseif ( is_search() ) { /* translators: %s: search phrase */ $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); so you could hook into the ...


1

In author.php: <?php get_template_part('custom-author-file'); Alternatively, rename your custom-author-file.php to author.php. The URL being used in this case isn't relevant, as a template doesn't determine the URL used, it's the other way around. However, I suspect there is more to your question you haven't explained



Top 50 recent answers are included