Im pretty new to playing around with what the loop can do and i have been looking for an answer for the last few days. So I have 2 pages services-page.php and contact-page.php both with custom templates. What i would like to know is it possible to set up the loop in page.php to get those custom templates with get_template_part() so when someone goes to the services page it goes to it and same with the contact page. So instead of having a loop on every different page I can just have it in page.php and bring in my different templates which goes to different pages. Hope that was clear, any help would be appreciated.
You are almost there with the get_template_part() but instead you would create a template part for your loop and include that on your templates. So create a php "part" that contains your loop and any other code you need.https://codex.wordpress.org/Function_Reference/get_template_part has an example with "loop.php" but you could create "loop-name.php" (where "name" can be anything you like) for your own loop and use this.
Related
I am relatively new to WP, and am trying to figure out if the following can be done, or if a plugin exists?
I am looking to save data (500K+ rows) into a SQL table (maybe a new table in WP database), and then render the results on a page (frontend) using some basic JS and CSS. Because of the size of data, I am not sure if I should use a plugin that imports from CSV/JSON and would it slow down the site.
Do I have to go all the way and create models and views and then render to an HTML, or is there an easy hack available?
As the last resort, I am also thinking of creating the table part using Flask and SQlite and use it as main domain, and WP blog as subdomain (don't know if it will impact SEO).
Request guidance from experts. TIA
There are plugins to handle table work. Use your favorite internet search engine to find them. You'll have to experiment with various plugins to get one that meets your needs if you go that route.
There two questions here.
One is how to render a table on the front end. If you do this yourself , your best bet is to create a plugin that defines a shortcode. When you write php code for that shortcode's handler, you will include code to read and render the table. You'll probably render it as an ordinary html <table>.
Then, you'll use WordPress's content editor to create a post, or a page, that contains your shortcode. When a visitor views the post or page, your shortcode handler runs and delivers the table you want.
The WordPress plugin API also gives you a way to enqueue css and Javascript to your pages. And, jquery is an inherent part of WordPress's page loads. WordPress also contains most of jqueryUI. That's handy, because there's a really nice jquery-based plugin called Datatables that will get your users some convenient features like pagination and sorting.
The second question is how to load that data into a table. The easy way would be to do it outside WordPress, with a SQL file or some other program to bulk-load it. But if you do it inside WordPress, you'll do it from an administrative page.
If you need to be able to add, update, or delete table entries from the front end, that's going to be some work.
Explaining all this in detail is far outside the scope of a Stack Overflow answer.
My wordpress theme has a static front page and NO blog page enabled. On the static front page there is a loop which shows all the (regular) posts.
I have generated successfuly a CPT named 'buch'.
I now have managed to show "buch" in the loop on category- and archive-pages.
Unfortunately my main aim still is and always has been to show 'buch' and 'post' within the loop on the static front page. I have so far searched the web, this forum and also intensely studied the code (hoping to find the loop in the templates).
Would anyone of you have some short solution maybe for the functions-file that´s rock-solid? Or an idea where to look for the loop in first place, with console, if even possible?
Situation: A page template contains pages with information about a topic and also runs a loop of posts about that topic - let's say: If is_page 'page1', show loop with tags about topic1 - If is_page 'page2', show loop with tags about topic2 ...
Wanted solution: I have +-25 pages about soccer teams that all need a loop with info about their specific team news(each team has a tag - not a category). But I only want to create 1 page template, because all the other information (the_content and some custom tags) is the similar for all pages.
Tried: I tried to fix this with get_template_part or get_query_var, but I cannot figure it out.
Any one can help me to get started?
You should probably use a custom field to associate your page with a team, then loop on it.
Check about Advanced Custom Field (ACF), it's a must have plugin.
I am trying to create a custom archive template for my categories. I have a parent category called
member-resources, which is a parent category for multiple other categories.
I do not want to access these categories by /category/member-resources.
According to wordpress documentation for template hierarchy, I need to create archive-member-resources.php and change the php code to display as needed.
However this template is not the one being rendered(archive.php is always being rendered), and if I try to access it by entering /member-resources I get a 404..
What am I missing ? thanks
[EDIT]
Excuse my wordpress skills as I have only been working with it for about a month..
I asked this question for a very simple reason. I worked on a project, in which I ended up with a massive archive.php file with alot of conditional logic such as :
if( is_category('events') ), render a side menu
if( is_category('news') ) , render something else
if( is_category('member-resources') ) render pagination
This is just an example, but I wanted to highlight that with different categories, I might want to call a completely different archive template( if at all possible ), rather than having a large file which is not very maintainable..
If this cannot be done, please provide me with a solution, so that on my next project, I wouldn't run into this problem again.
You should not use any type of archive page (archive.php, category.php, taxonomy.php etc) as a listings/index page. That is not what archive pages are intended for. Also, the template hierarchy specific to archive-xxx.php is for custom post types, not categories.
The main query on any archive page is quite specific and should not be tampered with on template level. It totally destroys pagination and common logic within the main query.
You should make use of a page template. Just simply copy your page.php, rename it to page-xxx.php, add the necessary page header and modify it as needed
For further reading
Page Templates
WP_Query
For a project of mine I need to define an alternative template for single posts.
To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.
(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).
Hope it makes a bit of sense.
Thanks for your advices and/or suggestions.
Angelo
I think the easiest way to do that is by registering a custom post type for the special posts that get this special "single.php" template. Then, you can simply write a new single template titled post-[custom post_type].php. Any post you register of this type will use that template.
OR...
If you don't actually need them to be posts, it's even easier if you publish them as pages. By default, pages let you assign a specific page template in the edit screen. So you could make any number of custom templates. Just make sure you add the special header:
/* Template Name: Custom Page */
...so WP knows it's a page template.