<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>取得 &#8211; ケケンタの独学ITブログ</title>
	<atom:link href="https://kekenta-it-blog.com/tag/%E5%8F%96%E5%BE%97/feed/" rel="self" type="application/rss+xml" />
	<link>https://kekenta-it-blog.com</link>
	<description>プログラミングやWeb制作の情報を発信</description>
	<lastBuildDate>Tue, 18 Mar 2025 02:07:50 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://kekenta-it-blog.com/wp-content/uploads/2023/07/cropped-KEKENTA-BLOG-32x32.png</url>
	<title>取得 &#8211; ケケンタの独学ITブログ</title>
	<link>https://kekenta-it-blog.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【WordPress】ページのURLや画像・CSSなどのパスを取得する方法【まとめ】</title>
		<link>https://kekenta-it-blog.com/wp-get-various-url/</link>
					<comments>https://kekenta-it-blog.com/wp-get-various-url/#respond</comments>
		
		<dc:creator><![CDATA[ケケンタ]]></dc:creator>
		<pubDate>Tue, 02 Jul 2024 05:36:19 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[取得]]></category>
		<guid isPermaLink="false">https://kekenta-it-blog.com/?p=8951</guid>

					<description><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/07/eye-catch__wp-get-various-url__8951-1024x576.jpg" class="webfeedsFeaturedVisual" /></p>この記事では WordPressで各種類のページのURLや画像・CSS・jsファイルのパスを取得する方法 をまとめてご紹介します。 各種ページのURLを取得 トップページ 投稿一覧ページ 「投稿一覧ページ」がサイトトップ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://kekenta-it-blog.com/wp-content/uploads/2024/07/eye-catch__wp-get-various-url__8951-1024x576.jpg" class="webfeedsFeaturedVisual" /></p><div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>こんにちは！　ケケンタです。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>この記事では</p>



<p class="has-text-align-center is-style-big_kakko_box"><strong>WordPressで各種類のページのURLや</strong><br><strong>画像・CSS・jsファイルのパスを取得する方法</strong></p>



<p>をまとめてご紹介します。</p>


<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-subloop-wq/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】WP_Query（サブループ）の使い方とパラメータ一覧を紹介</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-edit-functions/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】functions.phpを編集する「３つ」の方法と編集時の注意点</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-how-to-load-js/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】JavaScriptはどこに書けばいい？「３つの方法」を解説</span>
			</a>
		</div>

<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/change-to-swell/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">無料テーマCocoonからSWELLに乗り換えた７つの理由【WordPress】</span>
			</a>
		</div>

<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type2" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2025/03/eye-catch__school-php-and-wp__14099-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://kekenta-it-blog.com/school-php-and-wp/">PHPやWordPressを学ぶのにおすすめのプログラミングスクール【７選】</a>
						<span class="p-blogCard__excerpt">僕はこれまで独学でPHPを学習してきました。結論から言えば、それでもPHPを習得することはできました。 しかし、それに費やした累計学習期間は1年ほど。モチベーション&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">各種ページのURLを取得</h2>



<h3 class="wp-block-heading" id="top-page-anc">トップページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>home_url()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php echo esc_url( home_url() ); ?&gt;&quot;&gt;トップページ&lt;/a&gt;</code></pre></div>



<h3 class="wp-block-heading">投稿一覧ページ</h3>



<p class="is-style-icon_pen"><strong>「投稿一覧ページ」が<span class="swl-marker mark_yellow">サイトトップページ</span>に設定されている場合</strong>は<a href="#top-page-anc">トップページ</a>の項目をご覧ください。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>home_url()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php echo esc_url( home_url(&#39;/投稿一覧ページのスラッグ&#39;) ); ?&gt;&quot;&gt;投稿一覧ページ&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php echo esc_url( home_url(&#39;/sample&#39;) ); ?&gt;&quot;&gt;投稿一覧ページ&lt;/a&gt;</code></pre></div>


<div class="swell-block-postLink">			<a href="https://kekenta-it-blog.com/wp-create-post-page/" class="c-blogLink -internal" data-style="text">
				<!-- <i class="c-blogLink__icon icon-link" role="presentation"></i> -->
				<span class="c-blogLink__icon">
					<svg xmlns="http://www.w3.org/2000/svg" class="swl-svg-link __svg" width="1em" height="1em" viewBox="0 0 48 48" role="img" aria-hidden="true" focusable="false"><path d="M21.2 30.2c-.5 0-1-.2-1.4-.6l-.7-.7c-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l7.1-7.1c2.3-2.3 5.3-3.5 8.5-3.5s6.2 1.2 8.5 3.5c4.7 4.7 4.7 12.3 0 17l-3.5 3.5c-.8.8-2 .8-2.8 0-.8-.8-.8-2 0-2.8l3.5-3.5c3.1-3.1 3.1-8.2 0-11.3-1.5-1.5-3.5-2.3-5.7-2.3-2.1 0-4.2.8-5.7 2.3l-7.1 7.1c-1.5 1.5-2.3 3.5-2.3 5.7s.8 4.2 2.3 5.7l.7.7c.8.8.8 2 0 2.8-.4.3-.9.5-1.4.5z" /><path d="M13.4 46.6c-3.1 0-6.1-1.2-8.5-3.5-2.3-2.3-3.5-5.3-3.5-8.5s1.2-6.2 3.5-8.5l3.5-3.5c.8-.8 2-.8 2.8 0 .8.8.8 2 0 2.8l-3.5 3.5c-1.5 1.5-2.3 3.5-2.3 5.7 0 2.1.8 4.2 2.3 5.7 3.1 3.1 8.2 3.1 11.3 0l7.1-7.1c1.5-1.5 2.3-3.5 2.3-5.7 0-2.1-.8-4.2-2.3-5.7l-.7-.7c-.8-.8-.8-2 0-2.8.8-.8 2-.8 2.8 0l.7.7c2.3 2.3 3.5 5.3 3.5 8.5s-1.2 6.2-3.5 8.5l-7.1 7.1c-2.3 2.3-5.3 3.5-8.4 3.5z" /></svg>				</span>
				<span class="c-blogLink__text">【WordPress】投稿一覧ページを作成する「２つ」の方法【オリジナルテーマ】</span>
			</a>
		</div>


<h3 class="wp-block-heading">固定ページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>the_permalink()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php the_permalink( 固定ページID ); ?&gt;&quot;&gt;固定ページへのリンク&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php the_permalink( 30 ); ?&gt;&quot;&gt;固定ページへのリンク&lt;/a&gt;</code></pre></div>



<h3 class="wp-block-heading">投稿個別ページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>the_permalink()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php the_permalink( 投稿ページID ); ?&gt;&quot;&gt;投稿個別ページへのリンク&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php the_permalink( 30 ); ?&gt;&quot;&gt;投稿個別ページへのリンク&lt;/a&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">ループ内で使用する場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP" data-line="5"><code>&lt;?php if ( have_posts() ) : ?&gt;
    &lt;?php while ( have_posts() ) : the_post(); ?&gt;
        &lt;!-- 投稿個別ページへのリンク --&gt;
        &lt;p&gt;
          &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
        &lt;/p&gt;
    &lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;</code></pre></div>



<h3 class="wp-block-heading">カテゴリーアーカイブページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>get_category_link()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php echo get_category_link( カテゴリーID ); ?&gt;&quot;&gt;カテゴリーアーカイブへのリンク&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php echo get_category_link( 7 ); ?&gt;&quot;&gt;カテゴリーアーカイブへのリンク&lt;/a&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">「現在のページのカテゴリー」の<br>アーカイブページリンクを出力したい場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- アーカイブページへのリンク --&gt;
&lt;?php 
 	$cat = get_the_category()[0];
    $cat_id = $cat-&gt;cat_ID;
?&gt;
&lt;a href=&quot;&lt;?php echo get_category_link( $cat_id ); ?&gt;&quot;&gt;カテゴリーアーカイブへのリンク&lt;/a&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">「すべてのカテゴリー」の<br>アーカイブページリンクをまとめて出力したい場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- カテゴリーアーカイブページへのリンク --&gt;
&lt;?php 
	$categories = get_categories();  
    if ( $categorie ) {
        echo &#39;&lt;ul&gt;&#39;;
  	    foreach( $categories as $category ) {
	        echo &#39;&lt;li&gt;&lt;a href=&quot;&#39;. get_category_link( $category-&gt;term_id ) . &#39;&quot;&gt;&#39;. $category-&gt;name . &#39;&lt;/a&gt;&lt;/li&gt;&#39;;
        }
        echo &#39;&lt;ul&gt;&#39;;
    }
?&gt;</code></pre></div>



<p class="is-style-icon_pen">もっとシンプルに出力する形で良ければ<strong>以下のコード</strong>が手っ取り早いです。<br>※オプションが色々あるため、使いこなせばカスタマイズ性は上記のコードよりも高いです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- すべてのカテゴリーのアーカイブページリンクを出力する --&gt;
&lt;?php wp_list_categories(); ?&gt;</code></pre></div>



<h3 class="wp-block-heading">タグアーカイブページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>get_tag_link()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php echo get_tag_link( タグID ); ?&gt;&quot;&gt;タグアーカイブへのリンク&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php echo get_tag_link( 10 ); ?&gt;&quot;&gt;タグアーカイブへのリンク&lt;/a&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">「すべてのタグ」の<br>アーカイブページリンクをまとめて出力したい場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- タグアーカイブページへのリンク --&gt;
&lt;?php
    $posttags = get_the_tags();
    if ( $posttags ) {
        echo &#39;&lt;ul&gt;&#39;;
        foreach ( $posttags as $tag ) {
            echo &#39;&lt;li&gt;&lt;a href=&quot;&#39; . get_tag_link($tag-&gt;term_id) . &#39;&quot;&gt;&#39; . $tag-&gt;name . &#39;&lt;/a&gt;&lt;/li&gt;&#39;;
        }
        echo &#39;&lt;/ul&gt;&#39;;
    }
?&gt;</code></pre></div>



<h3 class="wp-block-heading">カスタム投稿一覧ページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>get_post_type_archive_link()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php echo get_post_type_archive_link( &#39;カスタム投稿のスラッグ&#39; ); ?&gt;&quot;&gt;カスタム投稿一覧ページへのリンク&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php echo get_post_type_archive_link( &#39;custom_sample&#39; ); ?&gt;&quot;&gt;カスタム投稿一覧ページへのリンク&lt;/a&gt;</code></pre></div>



<h3 class="wp-block-heading">カスタム投稿個別ページ</h3>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<p>the_permalink()</p>
</div></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;a href=&quot;&lt;?php the_permalink( カスタム投稿ページID ); ?&gt;&quot;&gt;カスタム投稿個別ページへのリンク&lt;/a&gt;</code></pre></div>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;a href=&quot;&lt;?php the_permalink( 20 ); ?&gt;&quot;&gt;カスタム投稿個別ページへのリンク&lt;/a&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">ループ内で使用する場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP" data-line="5"><code>&lt;?php if ( have_posts() ) : ?&gt;
    &lt;?php while ( have_posts() ) : the_post(); ?&gt;
        &lt;!-- カスタム投稿個別ページへのリンク --&gt;
        &lt;p&gt;
          &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
        &lt;/p&gt;
    &lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;</code></pre></div>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">画像・CSS・jsファイルまでのURLを取得</h2>



<p class="is-style-icon_pen">画像・CSS・jsファイルまでのパスを取得する際に使用するテンプレートタグは<strong>共通</strong>しています。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl2"><div class="cap_box_ttl"><span>使用するテンプレートタグ</span></div><div class="cap_box_content">
<ul class="wp-block-list -list-under-dashed is-style-check_list">
<li><strong>親テーマ</strong>内のファイルを使用する場合……<strong>get_template_directory_uri()</strong></li>



<li><strong>子テーマ</strong>内のファイルを使用する場合……<strong>get_stylesheet_directory_uri()</strong></li>
</ul>
</div></div>



<h3 class="wp-block-heading">画像ファイル</h3>



<p class="is-style-bg_stripe">画像ファイルが<br><strong><span class="swl-marker mark_blue">「親テーマ」→「assets」→「img」ディレクトリ</span></strong><br>に配置されているという想定です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;img src=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/assets/img/sample.jpg&quot;&gt;</code></pre></div>



<h3 class="wp-block-heading">CSSファイル</h3>



<p class="is-style-bg_stripe">CSSファイルが<br><strong><span class="swl-marker mark_blue">「親テーマ」→「css」ディレクトリ</span></strong><br>に配置されているという想定です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;link href=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/css/sample.css&quot; rel=&quot;stylesheet&quot; /&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">functions.phpでCSSファイルを読み込む場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>function my_add_css_files() {  // 関数名は任意

  // CSSの読み込み
  wp_enqueue_style( &#39;sample&#39;,　get_stylesheet_directory_uri() . &#39;/css/sample.css&#39; );

}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_add_css_files&#39; );</code></pre></div>



<div class="wp-block-group is-style-big_icon_memo"><div class="wp-block-group__inner-container">
<ul class="wp-block-list is-style-check_list">
<li><strong>第１引数</strong>は別の処理でsample.cssを扱う際に用いる「ハンドル名」（任意の名前）</li>
</ul>
</div></div>



<h3 class="wp-block-heading">jsファイル</h3>



<p class="is-style-bg_stripe"><br><strong><span class="swl-marker mark_blue">「親テーマ」→「js」ディレクトリ</span></strong><br>に配置されているという想定です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>&lt;!-- 使用例 --&gt;
&lt;script src=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/js/sample.js&quot; /&gt;</code></pre></div>



<p class="has-text-align-center is-style-balloon_box">functions.phpでjsファイルを読み込む場合</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>function my_add_js_files() { // 関数名は任意

  // jsファイルの読み込み
  wp_enqueue_script( &#39;my-script&#39;, get_template_directory_uri() . &#39;/js/sample.js&#39;, array(&#39;jquery&#39;), false, true );

}
add_action( &#39;wp_enqueue_scripts&#39;, &#39;my_add_js_files&#39; );</code></pre></div>



<div class="wp-block-group is-style-big_icon_memo"><div class="wp-block-group__inner-container">
<ul class="wp-block-list is-style-check_list -list-under-dashed">
<li><strong>第１引数</strong>は別の処理でsample.jsを扱う際に用いる「ハンドル名」（任意の名前）</li>



<li><strong>第３引数</strong>は「jQueryの読み込み後にこのjsファイルを読み込む」という指定</li>



<li><strong>最後の引数</strong>をtrueにすることで&lt;/body&gt;直前に読み込む</li>
</ul>
</div></div>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4374558503914683"
     crossorigin="anonymous"></script>
<!-- ディスプレイ【横長】 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-4374558503914683"
     data-ad-slot="9744298852"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">まとめ</h2>



<p>以上が<strong><span class="swl-marker mark_yellow">WordPressで各種類のページや画像・CSS・jsファイルを取得する方法のまとめ</span></strong>でした。</p>



<p>どれも使用頻度が高いものばかりなので、ぜひこのページをブックマークに保存していただき、いつでも呼び出せるようにしていただければと思います。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="gray"><div class="c-balloon__icon -circle"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/キリッ-150x150.jpg" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">ケケンタ</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>この記事が少しでもお役に立ったなら何よりです！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<p>当ブログではWordPressやWeb制作、PHPに関する情報を発信しています。</p>



<p>ご興味のある方は他の記事もご覧いただけると嬉しいです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://kekenta-it-blog.com/wp-get-various-url/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
