sam
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Output post count per category on a custom taxonomy archiveTo those interested in achieving the same thing, I figured it out using @bcworkz’s advice on a related Topic.
Luckily I only needed to output the number of posts for four categories whose posts are displayed on a taxonomy term archive page. I just added them as new
WP_Query
objects and echoed them with the$found_posts
property in their corresponding<span>
.Thank you so much for your assistance @thaikolja. The objective was to simply have Secondary Title read the
<i>
tag without affecting all of the words entered in the field. Say, if I only wanted to italicize an album title within a phrase, I would put thereinThis is an example Secondary Title that has an <i>Italicized Album Title</i> and the rest aren't
, which will then show up on the single/actual post instead of the default title written asArtist Name - Italicized Album Title
.I was able to finally achieve this through the ACF plugin’s text field functionality. It outputs the alternative title while recognizing the
<i>
tag wherever it is placed in the text field. I, however, decided to keep Secondary Title as I have several existing posts that have been assigned one (all required no italicization).What you do for the community is truly commendable. I appreciate every input you responded me with and your patience throughout! I find that code you wrote particularly useful for posts with titles already in headline form and needing italicization on certain words. I for sure will have some use for that.
Forum: Developing with WordPress
In reply to: Configuring a site’s default home URL within a single post@threadi and @bcworkz, thanks for your input. I am marking this Topic as resolved as I found out taxonomies in fact get suggested as destination URLs together with posts and pages when hyperlinking a word or a phrase. I just got so used to typing
/artists/artist-name
right away I completely missed utilizing the core functionality of linking to a taxonomy page by simply choosing the same from the suggestions in the dropdown. All along I thought custom taxonomies don’t show up there. I confirm that the automatically suggested taxonomy page URL even corresponds to the language I am writing in. Thus, I didn’t have to modify the home URL within a single post at all, just had to look closely!Hi @thaikolja, thank you for going as far as writing such a complicated code to help! I tried implementing the same. Set the Title format to
%title%
and entered the Album Title in the Secondary Title field in the Editor, which did result in the actual post displaying the post title with the Album Title automatically italicized. This is fantastic if we only wanted to do an automatic italicization of certain words in a headline already in sentence case. However, this is not what we’re aiming for when writing track or album reviews. Also, italicizing any word in a headline is already possible through the default title field by adding the<i>
tag.To clarify, track/album reviews are titled this way (using the default title field):
Artist Name - "Song Title"
(for track reviews) orArtist Name - Album Title
(for album reviews)This has been the practice for a long time, but going forward we want the title to change into a headline in sentence case when the single post (the actual post) is viewed:
Artist Name - "Song Title"
(original title) →Artist Name releases new song "Song Title"
(on actual post)Artist Name - Album Title
(original title) →Oddity pervades Album Title, the latest album by Artist Name
(on actual post)Using the plugin Secondary Title is a great help to achieve that, except that we cannot seem to italicize any word (particularly when it comes to Album Titles) inside the field as needed.
Your solution is actually a great feature, although I think it could develop into a whole new plugin where a user is to put in the field a word or words they want automatically italicized/stylized instead of providing a completely alternative title.
We already are able to italicize Album Titles using the
<i>
tag in the default title field when writing news stories, which require headlines by default and where Secondary Title is no longer needed. We only have a problem especially with album/EP reviews, because we need it (Album Title) to be italicized, without affecting the other words in the secondary title as illustrated above.That said, I think this can be achieved with a script that allows
<i>
or<strong>
or any styling tags to be put “anywhere” inside the Secondary Title field in that when one enters therein, for example,Oddity pervades <i>Album Title</i>, the latest album by Artist Name
, it gets read as a command to italicize whatever is enclosed by the tags, to the exclusion of all other words.I appreciate your effort in making this plugin more flexible and your patience in addressing my query. Really looking forward to getting this to work!
Hi @thaikolja, sorry you had to write all that ?? your inputs are definitely not useless! I’d say you got it right this time, except that I must emphasize that we do not intend to italicize all of the Secondary Title but only certain words as needed (like when an album title is mentioned). In your example, we would like the Secondary Title to show as
Metallica reissues Master of Puppets
or only whenever italicization is necessary.
The italicized word or words could be anywhere in the Secondary Title:
Listen to Metallica's Master of Puppets reimagined to the style of Radiohead's The Bends
which would only be possible if <i> gets recognized therein.
I am comfortable with some code should you provide me with any and I look forward to trying it out. I truly appreciate your help.
Hi @thaikolja, thanks for the detailed and easy-to-follow guide, however, we might not be on the same page I’m afraid. I’ve had a look at the plugin’s documentation before creating this topic as I did not find the solution.
What I’m trying to italicize is only a certain word in the Secondary Title and not all of it. Our default title for an article, for example, goes like “Metallica – Master of Puppets“, which, when opened, we want to display as a headline in sentence case, like “Metallica reissues Master of Puppets” and not “Metallica reissues Master of Puppets” like your advice would result in. Additionally, we don’t want to display this as
%secondary_title%: %title%
as we want the Secondary Title to replace the default title when the actual post is viewed.Hi @thaikolja, I enter it in the Secondary Title field, enclosing the word I want italicized, but it does not seem to have an effect to the word at all, so I thought maybe it’s not yet possible. I only intend to italicize a certain word within the Secondary Title and not the whole Secondary Title.
Hi Shea, thanks for your reply. This snippet is used so that only posts that are associated with a category, a tag, or a custom taxonomy term are queried by my theme’s slider shown on the current archive page or page. For example, I have a category called Music News, when its archive page is visited, only posts with that category are queried by the slider. The same is true for tags and taxonomies. The site already behaves like that even without the snippet, but the slider queries all posts when it’s deactivated. When this snippet is active with Polylang, however, when I add new categories/tags/tax terms, they get assigned to all existing posts. When either is deactivated, the problem goes away. I have the snippet turned on now and set to Only run on site front-end, this way I am able to add categories/tags/tax terms via the admin menu without them getting added to old posts. I noticed that adding new categories/tags/tax terms while in the Editor with this setting, however, causes them to be added to old posts. That’s the problem because I’m forced to manually add new categories/tags/tax terms through the admin menu instead of adding them as needed while writing, which is additional work.
I found a better way to dynamically display posts pertaining to an artist by incorporating the Display Posts shortcode into the taxonomy-artists.php template and getting the current artist’s slug. However, the shortcode still only recognizes the category and tag rules, not the taxonomy (“artists”) and term (e.g., “black-hibiscus”) ones.
I found a better way to dynamically display posts pertaining to an artist by incorporating the Display Posts shortcode into the taxonomy-artists.php template and getting the current artist’s slug. However, the shortcode still only recognizes the category and tag rules, not the taxonomy (“artists”) and term (e.g., “black-hibiscus”) ones.
Forum: Developing with WordPress
In reply to: Include posts under a custom taxonomy in author.phpThank you for your insightful response, @bcworkz. Someone suggested I use the following code, but this didn’t work. To clarify, I don’t set any co_writer term when there is no co-author for a post. My objective is to make posts tagged with an author’s “namesake co_writer term” on that author’s archive page. Here is the existing code, which I think has the logic but can’t quite tell why it still retrieves only posts mainly written by the current author.
function wp_posts_on_author_archive($query) { // Check if this is the main query and an author archive if ($query->is_main_query() && $query->is_author()) { // Get the current author's ID $author_id = get_query_var('author'); // Get the current author's name $author_name = get_the_author_meta('user_nicename', $author_id); // Modify the tax query to include posts with the current author's name as a term in "co_writer" $tax_query = array( 'relation' => 'OR', array( 'taxonomy' => 'co_writer', 'field' => 'slug', 'terms' => $author_name, ), array( 'taxonomy' => 'co_writer', 'field' => 'name', 'terms' => $author_name, ), ); $query->set('tax_query', $tax_query); } } // Hook into the pre_get_posts action add_action('pre_get_posts', 'wp_posts_on_author_archive');
- This reply was modified 9 months, 3 weeks ago by sam.
Appreciate your inputs, Joy. That seems to be a good idea indeed. Do you know how that “taxonomy toggle” can be created and made operational?
I only intended the /ph page to act as a starting/landing page to users who want their session with localized content or those directly referred to it. It’s not actually intended to rank. And correct, the user is able to see both homepages, but should not be during the same session (they need to switch from either).
With your suggestion, though, I am thinking you mean there’s no longer a need for the /ph custom front page and just the toggle to make visible specific content based on taxonomy. Correct? In that case, can the user browse the site while persistently being fed the same content until the toggle is switched again? If so, I’m interested in trying that out. Btw, is there a way I can also customize some sidebar widgets to only show while the toggle is activated? Sorry for asking so many questions.
Hi Joy, thanks for your response. I would like to know more about what you’re trying to recommend using a cookie. How do you think I can implement that?
Basically this is what I’ve created:
https://www.website.com (the main site; all articles appear except for some articles that have a specific taxonomy that is only viewable in the custom front page)
https://www.website.com/ph (the custom front-page copy; only those articles with the above taxonomy + several others that also appear on the main front page appear here)I did this with the understanding that when the user arrives at that custom front page, it should mean that they’ve opted to view the local version of the site, thus, the homepage should also always redirect them to /ph even after they visited a /page-name (which of course belongs to the same original site) until they click on the default / again, which shall remove the rule.
So when I go to https://www.website.com and click (or when i go directly to) https://www.website.com/ph, the homepage now will be https://www.website.com/ph, regardless where i go. when i click the default region, the homepage reverts to the original site.
@rwcommm You can add this perimeter in your code:
date_query_after=”-90 days”
That should only display posts from the last 90 days, hence all post falling outside of that time frame will not be displayed.
Let me know if it works.
Hi there, Stanimir. Thanks for your response.
I was forced to disable WooCommerce to enable SG Optimizer. But once I enable both plugins the same issue really arises. When SG Optimizer and WooCommerce are enabled, “edit page” and “edit post” don’t load and leave us with a blank page.
What could have been the reason for that? Is there a fix? We want to enable Woo again without disabling SG Optimizer.
I’ve deleted WooCommerce and reinstalled it, the same thing happens. I deleted it until a fix for the conflict is available.
Thanks.